Sunday, December 18, 2016

Chapter-2

Database Management Systems

Unit 2 Database
2.1 Concept of Database
2.1.1 Introduction: Data, Information, Database and DBMS
2.1.2 Objectives of DBMS
2.1.3 Database Model: Relational Model ,Network Model, Hierarchical Model, Entity Relational Data Model
2.1.4 Concept of Normalization
2.1.5 Types of Normalization 1NF, 2NF
2.1.6 Structured Query Language
2.1.7 Centralized Vs. Distributed Database
2.1.8 Data Security.
2.2 Design Database using DBMS Software
2.2.1             Create a Database
2.2.2 Create Tables and Fields and its properties
2.2.3 Create a Relational Databases
2.2.4 Create and Run Queries
2.2.5 Working with Forms
2.2.6 Generate Reports
2.3 Project Work on DBMS Software


Definition of Data
Data is the collection of raw (unprocessed) facts and figures without any added interpretation or analysis about persons, places and things which can be recorded in the form of words or texts, images, graphics, numbers, audios, videos, sounds etc.
Data have been collected, stored, processed and/or manipulated but have not been organized or placed into context.
For example:-Name, Roll, Marks obtained by student etc.

Examples of Data

  1. Student Data on Admission Forms
    When students get admission in a college. They fill admission form. This form     contains raw facts (data of student) like name, father’s name, address of student etc. 
  2. Data of Citizens
    During census, data of all citizens is collected.
  3. Survey Data
    Different companies collect data by survey to know the opinion of people about their product.
  4. Students Examination data
    in examination data about obtained marks of different subjects for all students is collected.    

Types of Data
There are following main types of Data.
1)  NUMERIC DATA
Numeric data consists of 0 to 9 digits, + and – sign and decimal point etc.
For example: 5, 44, 34.55, -45 etc
2)  ALPHABETIC DATA
It consists of all alphabetic letters A to Z, a to z and blank space etc.
For example: Nepal, KIC, SEMI etc.
3)  ALPHANUMERIC DATA
It consists of alphabet letters, digits and special characters like #, $, % etc.
For example: House Number 10-A, 14-August-1947, F-16 etc.
4)  GRAPHIC DATA   
Graphic data or image data consists of charts, graphs and images etc.
For example: a collection of maps of countries, a collection of family pictures etc.
5)  AUDIO DATA
Audio data consists of sounds and voices.
For example: audio songs, radio program, radio news, audio songs etc.
6)   VIDEO DATA
Video data consists of moving pictures.
For example: movie, TV dram, TV news etc.
7)  MIXED DATA
Mixed data consists of combined data of two or more types.
 For example:  TV drama consists of audio as well as video data. 
  
Definition of Information
Information is processed data after data processing which gives a complete sense or proper meaning. Information is useful in decision-making. 

Information of three students:

Id
names
address
roll
1.
Ram
Dharan
5
2.
Rajesh
Biratnagar
6
3.
Riya
Kathmandu
10





Field: - A field is the property or attributes of a table. Simply, a field is a piece of information about a person or place or thing. In above table Id, Name, Address, Roll is known as fields.

Record: - A collection of interrelated fields is called a record.  It is also known as tuple. A tuple is one record (one row). For example above table contains 3 records and each record has 4 related fields namely id, name address, roll.

Tables: -A database table is composed of records and fields that hold data. It organizes the data in the rows and columns form. 
                                                 Where, a row defines a record and a column defines a field.

File:- File is the collection of all related records.

Examples of Information
  1. Student Address Labels
    stored data of students can be used to print address labels of students. 
  2. Census Report (Total population, Literacy Rate, Male / Female ratio etc.)
    Census data is used to get report/information about total population of a country and literacy rate etc.
  3. Survey Reports and Results
    Survey data is summarized into reports/information to present to management of the company.
  4.  Result Cards of Individual Students, Result sheets of  a particular Class
    In examination system collected data (obtained marks in each subject) is processed to get total obtained marks of a student. Total obtained marks are Information. It is also used to prepare result card of a student.
  5. Merit List
    after collecting admission forms from candidates, merit is calculated on the basis of obtained marks of each candidate. Normally, percentage of marks obtained is calculated for each candidate. Now all the candidates’ names are arranged in descending order by percentage. This makes a merit list. Merit list is used to decide whether a candidate will get admission in the college or not.
Compare between Data and Information

            DATA
       INFORMATION
Data is collection of raw facts and figures.
Information is processed data.

Data is unarranged and unorganized.

Information is arranged and organized.

Data is meaningless.
Information is meaningful.
Data is input.
Information is output.
Data is used less frequently.
Information is used frequently.
Data represents facts before processing.
Information represents results (obtained after processing).

Data is not helpful in decision-making.

Information is helpful in decision-making.

Data is raw material for information.

Information is the final product of data.

Data are unprocessed records

Information contains processed records

Data is in large amounts

Information is in small amounts

If data is lost, it is very difficult (or even impossible in some situations) to re collect.
If information is lost, it is easily derived from stored data, again.

Data is the asset of an organization and is not available for sale to public.

Normally, information is available for sale to general public.

Data depends upon the sources for collecting data, the collection methods adopted and the people who will collect data.
Information depends upon data.

Definition of Database
A database is an organized collection of interrelated information that can be used for multiple purposes as desired. Database is actually a place where related piece of information is stored and various operations can be performed on it.
An example of a database is a dictionary, where words are arranged alphabetically, and a telephone directory where subscriber names are listed in an alphabetic order, result sheet, salary sheet, attendance etc.

Objectives of database
v  Organized data storage.
v  Convenient retrieve of selected data.
v  Presented selected data in a convenient format.
v  Safety and security of data.
v  Integrity sharing and availability of data.


Labels:

Friday, December 2, 2016

Chapter-4

C Programming
4.1  Introduction:
4.1.1        Overview, History, Features, Advantages and Disadvantages of C Language.
4.1.2    Structure of C program.
4.1.3    Compiling Process.
4.1.4    C Preprocessor and Header Files
4.2  Fundamentals of C
4.2.1   Character Set used in C
4.2.2   Use of Comments
4.2.3   Identifiers, Keywords and Tokens.
4.2.4   Data Types in C
4.2.5   Constants and Variables
4.2.6   Type of Specifier
4.2.7   Statements – Simple and Compound Statements
4.3  Operators and Expressions
4.3.1    Operators: Precedence & Associativity 
4.3.2    Expressions
4.3.3    Type Casting and Conversions
4.3.4    Introduction to Library Functions
4.4  Input/ Output (I/O) Functions
4.5  Control Structures
4.5.1    Decisions (if, if-else, else if, switch, ?: operator)
4.5.2    Looping (while, do while, for)

4.6  Array and String
4.6.1    Definition of array and string
4.6.2    Types of Array – One-Dimensional and Two-Dimensional (definition, declaration, and initialization.)
4.6.3    String Function :  strlen(), strcat(), strcmp(), strrev(), strcpy(), strlwr() , strupr()
4.7  Functions
4.7.1    Concept of Function, function definition, function prototype.
4.7.2    Return and Void statements of a function
4.7.3    Accessing a Function – Function Call(by value, by reference)
4.7.4    Concept of Recursion
4.8  Structures and Unions
4.8.1  Definition and Difference between Structure and Union.
4.8.2  Structure: Declaration, Initialization and Size of Structure.
4.9  Pointers
4.9.1   Definition of Pointer
4.9.2   Address (&) and indirection (*) operator
4.9.3  Pointer Expression and Assignment
4.10       Working with Files
4.11    Concept of Data File
4.12    Sequential and Random File
4.13 Opening, Reading, Writing and Appending on/from Data File


Overview of C language
         C is a general-purpose, structured, procedural, compiled, high-level programming language that was originally developed by Dennis M. Ritchie at AT&T’s Bell Lab for use with the UNIX operating system by inheriting the features of B and BPCL with his own features. C was originally first implemented on the DEC PDP-11 computer in 1972. It is suitable for preparing system software as well as application software. The file extension of c program is .c.
         C is also called middle (intermediate language) level language because it combines the best features of high level language and low level language.

A Brief History of C Language
The C programming language was developed by Dennis Ritchie at Bell Labs during the early 1970's. Quite unpredictably it derived from a computer language named B and from an earlier language BCPL. Initially designed as a system programming language under UNIX it, expanded to have wide usage on many different systems. The earlier versions of C became known as K&R C after the authors of an earlier book, "The C Programming Language" by Kernighan and Ritchie. C was standardized by ANSI (American National Standard Institute) in 1980. It is still used for some system and network programming as well as for embedded systems.

Features and Importance of C:
a)   It is highly portable language: - it means C programs written for one computer can be run on another computer without little or no modifications.
b)  It is structured language: - because it has a fixed structure.
c)   It is efficient and fast: - it is efficient and fast due to its verities of data types and powerful operators.
d)  It can handle low-level activities
e)   It can be compiled on a variety of computer platforms
f)   It contains a powerful instructions set of data operators that tell computer how to manipulate the data within a program.
g)  It has both the features of high level language as well as low level language.
h)  It has rich system library: - because it has large numbers of predefined keyword and library functions.

Advantages of C
a)   It is one of the efficient and fast executing programming languages.
b)  It is easy for debugging, testing and maintaining.
c)   There is no limitation while programming using C. We can develop any kinds of program.
d)  C is powerful language and the use of pointer has made it unique.
e)   Its compiler is easily available.
f)   Length of programs can be reduced by using function.
g)  Reusability of function increases.

Disadvantages of C
a)   There is no runtime checking.
b)  There is no strict type checking.
c)   It is very difficult to fix the bugs.
d)  It is not powerful like as object oriented programming.
e)   Pointer is one of the unique features which have made C powerful but if it is mishandled the system may crash so it is risky too.

Basic structure of C program
     Here, we can easily illustrated each component of a basic structure of C program as below
·         Documentation section: - it contains a set of comments lines about the name of program, the author, algorithm, methods used and other detail. E.g. // WAP to find sum of two number.
·         Link Section: -it provides instruction to the compiler to link functions with program from the system library. E.g. #include<stdio.h>, #include<conio.h> etc.
·         Definition section: - in this section, all symbolic constants are defined. E.g. #define pi 3.147
·         Global declaration section: - In this section, declared variable as global which are used in more than one functions.
·         Main () function section: - Every C program starts and ends with a main () function. It contains declaration and executables parts where declaration part declares all the variables used in the execution part. E.g. int a=2, b=5;
a=a+2;
b=b+8;
·         Subprogram section: -This section contains all the user-defined functions that are called in the main function.

Documentation Section
Link Section
Definition Section
Global Declaration Section
Declaration part
Executable part
Main() function section
{





}

Subprogram Section
Function 1 {}
Function 2 {}
-
-
Function n {}




User-defined functions

                                                                                                                                                                                                                                          

Fig. Basic structure of a C program

Example
// WAP to calculate the area of circle using function.          : Documentation section

#include<stdio.h>                     : link section
#include<conio.h>
#define pi 3.147                        : definition section
float r;                                                                             :global declaration section

float area(float x);

void main()                                : starting from here to main function
{  float value;                                       :declaration part
clrscr();
printf("Enter a radius of circle\t");
scanf("%f",&r);
value=area(r);                  :executable part and also calling user defined function

printf("\nArea of cirlce is: %f",value);
getch();
}

float area(float x)                       :user defined function
{
return(pi*x*x);
}


Compiling process
Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object' file. This step doesn't create anything the user can actually run. Instead, the compiler merely produces the machine language instructions that correspond to the source code file that was compiled. In c programming compiling process consists of following steps:


v  Preprocessing: - They instruct compiler to do required pre-processing before actual compilation. You can call this phase text substitution or interpreting special preprocessor directives denoted by #.
v   Compiler – the compiler translates the high-level instructions in the .i file into low-level Assembly language instructions. The generated file containing the translation is in text format and typically has a .s file extension.
v  Assembling – the assembler converts the Assembly language text instructions in the .s file into machine code. The generated object file containing the conversion is in binary format and typically has a .o file extension.
v  Linking –Linking refers to the creation of a single executable file from multiple object files. If these piece of code need some other source file to be linked then linker link them to make it a executable file.
v  Loader: - It loads the executable code into memory. Program and data stack are created, register get initialized.

Header files and C preprocessor
Header Files:
Header files are a collection of macros, types, functions and constants. Any program that needs those functions can include the corresponding header files.
List of some commonly used Header file and their purposes:
Header Files
Purpose
Functions Declared
stdio.h
Used for standard input and output (I/O) operations.
printf(), scanf(), getchar(), putchar(), gets(), puts(), getc(), putc(), fopen, fclose(), feof()
conio.h
Contains declaration for console I/O functions.
clrscr(), exit(), getch()
ctype.h
Used for character-handling or testing characters.
isupper(), is lower, isalpha()
math.h
Declares mathematical functions and macros.
pow(), squr(), cos(), tan(), sin(), log()
stdlib.h
Used for number conversions, storage allocations.
rand(), srand()
string.h
Used for manipulating strings.
strlen(), strcpy(), strcmp(), strcat(), strlwr(), strupr(), strrev()

C Preprocessor:
The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. C Preprocessor is just a text substitution tool and it instructs the compiler to do require pre-processing before the actual compilation. All preprocessor commands begin with a hash symbol (#). 
Preprocessor directive is a collection of special statement that is executed at the beginning of a compilation process. It is placed in the source program before the main function. They all begin with the symbol # (hash) and do not require a semicolon at the end.

#define directive: it defines a text substitution, macro substitution and symbolic constant.
Syntax:
#define identifier substitution_token
For Example:
#define TRUE 1
#define FALSE
#define MAX 100
#define PI 3.14

#include directive:  -This directive searches for a header or source file, which can be processed by the implementation, to be include in the program.
Syntax:
#include <filename>

For example:  #include<stdio.h>

Labels: