Cs Xii Notes PDF
Cs Xii Notes PDF
Notes
Assignments
Exercises
Model Test
Papers
MCQs
Solution for
Practicals
PREFACE
This book contains a comprehensive guide line to C and MS-Access students. This book has
been designed by considering the course outline of XII Computer Science. Nothing is
perfect, but we do believe in striving for perfection.
TABLE OF CONTENTS
S# Contents Page #
0 Course Introduction 3
1 List of Assignments 4
10 Chapter 8: Functions 79
List of Chapters
Ch 1 Concepts of Computer Programming
Ch 2 Algorithms and Flow Charts
Ch 3 C Language Fundamentals
Ch 4 Operators and Expressions
Ch 5 Conditional Statements
Ch 6 Input and Output Function
Ch 7 Iterations and its Types
Ch 8 Functions
Ch 9 Database Concepts
Ch 10 MS Access
No Description Due
Date
1 Write an algorithm of preparing tea and draw flow chart.
Write an algorithm of starting and running a car.
8 Write a Program and draw flow chart, take input for basic
4|Page Muhammad Umair Ayub
salary, calculate house rent allowance as 5% of the basic
salary and travel allowance as 8% of the basic pay,
calculate gross pay, deduct 2% tax of the basic pay and
finally calculate the net pay.
* * * * * * * *
* * * * * *
* * * *
* *
18 Differentiate
a. Operators and Operands
b. Predefined and Programmer defined functions
c. Increment and decrement operators
d. Break and Continue
e. Table and Query
f. Primary Key and Foreign Key
g. Table and Query
h. Form and Report
i. Wizard Mode and Design View
N Description Due
o Date
1 Describe in detail the system development life cycle and its
phases
CONCEPTS OF COMPUTER
1
PROGRAMMING
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Computer Language
A computer language is defined as the source of communication to the
computer system which provides all the materials to develop programs and
consequently complete software.
Explanation
A language provides all the material to develop software. Software is a
collection of programs which works integratedly and a program is a
collection of instructions which are written in a specific computer language.
There are a number of languages being used for application and system
software.
Examples
C language
CPP
Java
Visual Basic
Procedure Oriented
A procedure language uses the traditional approach for
programming using pre-defined and programmer defined
function and procedures. The control structure plays an
important role.
Examples
C, COBOL, PASCAL etc.
Object Oriented
An object oriented language uses classes and objects having
specific properties and methods for a comprehensive
programming. It is a better approach than a procedure
oriented language.
Examples
C++, JAVA etc.
Visual Programming
A visual programming language provides a graphical or
windows like environment for programming. It contains visual
Program
A program is defined as collection of instructions in a computer language to
perform a specific task.
Explanation
The programs are the components of software which are integrated with
each other. A program contains a number of instructions which are definitely
written in a computer language.
Example
The following is a C language program which prints three lines of text.
void main()
{
clrscr();
printf(“\t\t\t------*****WeLc0mE***** ----- \n”);
printf(“How are you???\n”);
printf(“It is my first program!!!”);
getch();
}
Software
Software is a collection of integrated programs having a definite purpose.
Explanation
The software is a computer program which is built using some computer
language. It is a collection of programs which works integratedly. The
software that controls and manages the hardware is called system software
and the software which facilitates the user is called application software.
Example
MS- Word
MS-Excel
Typing Master
Operating System
etc.
Introduction to C Language
C is a powerful programming language developed by Dennis Ritchie at AT &
T Bell laboratories of USA in 1972.
Historical Background
In the early ages of computer programming, there used to be special
purpose programming languages. For example COBOL (common business
oriented language) was being used to develop business application.
Fortran(formula translation language) was being used to solve mathematical
and technical problems. Pascal language was being used to solve scientific
problems. There was a need of such kind of language which can be used in
any kind of programming as general purpose language.
Development of C language
C was evolved from the earlier language BCPL (Basic Combined
Programming Language) which was developed in 1967 by Martian Richards
at the Cambridge University. BCPL was developed as a language for writing
system software specially operating system and compilers.
In 1970 Ken Thompson at Bell laboratories developed a language based on
BCPL and called it B language means the first letter of BCPL. Dennis Ritchie
was the programmer who developed B language further as a new language
and gave it the name of “C” the second letter of BCPL.
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Problems
Example algorithms and flow chart
Algorithm
Step by step process to solve any problem is called an algorithm
Characteristics of an algorithm
The following are some important characteristics of an algorithm.
The number of steps in an algorithm is finite.
The steps mentioned in an algorithm strictly follow a sequence to
get the desired result.
The algorithm must get the final result of the problem in the form
of a comprehensive solution.
The algorithm can be written to solve any business, scientific,
technical and even general life problem.
Example Problem
Write an algorithm to add two numbers and for printing the result.
Algorithm
Step 1: Start
Step 2: Read X
Step 3: Read Y
Step 4: Set Z=X+Y
Step 5: Write Z
Step 6: Exit
Process Assignment or
Equation
On Page To Connect
Connector Different Parts
on the same
page
Off Page To Connect
Connector Different Parts
from one page
to another
Algorithm
Step1. Start
Step2. Read a, b, r, T, S
Step3. Set T = (1.0/2.0)*(a*b)
Step4. Set S = (4.0/3.0)*(3.142)*(r*r*r)
Step5. Write T, S
Step6. Exit
Flow Chart
*******************
*******************
Algorithm
Step1. Start
Step2. Read name
Step3. Read age
Step4. Read height
Step5. Read gender
Step6. Write name
Step7. Write age
Step8. Write height
Step9. Write gender
Step10. Exit
*******************
Flow Chart
*******************
Algorithm
Step1. Start
Step2. Read num
Step3. IF num>=2 and num<=10 then
Step4. Repeat FOR i = 1 to 10
a. Set t = num * i
b. Write t
[End of FOR Loop]
Step5. ELSE
Write Error!!!
[End of IF-ELSE structure]
Step6. Exit
Flow Chart
C LANGUAGE
3
FUNDAMENTALS
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Short Answer Questions
Q1. What is a variable? Describe rules to define a variable.
Q2. What is a constant? Why it is used in programming?
Q3. What is a header file? Describe its purpose.
Q4. What is a C statement? Mention example.
Q5. For what purpose the key words are used in C language?
Q6. Define preprocessor directive with example.
Q7. What are identifiers? Describe with example.
Q8. What is an input statement? Give example.
Q9. What is an output statement? Give example.
Q10. What is a format specifier? Describe format specifiers used in C.
Q11. Define address operator with example code.
Q12. What are the methods to write comments in C?
Q13. Define and explain escape sequences.
Q14. Define data type. How many data types are used in C language?
Long Answer Questions
Q1. Describe the IDE of C language in detail.
Q2. What is structured programming? Describe program development life
cycle.
Q3. Convert the mathematical equations in C equivalent.
Problems
Example problems and source codes
Variable
A variable is a programming ingredient in the form of an identifier defined by
the programmer. It is a location in a memory on which the character or
numeric data can be stored.
Explanation
A variable is declared using some data type which defines the type of the
data. It is necessary to follow the rules while defining the variable name.
A variable has got the following characteristics:
It‟s name.
The data type which defines its size.
The address on which it is located in the memory.
The value which is stored in it.
Rules for Variable Names
The following rules must be followed while declaring a variable
The first letter must be non numeric
No space, commas or special characters can be used in a variable
name.
The underscore (_) can be used in a variable name.
The reserved words like int, void, for, if etc cannot be used as
variable names.
While writing a C program which has an extension of “.C” the
variable must be stored in the beginning of the main function.
It is better to use a variable name up to eight characters.
Example
int marks;
float percentage;
Q2. What is a constant? Why it is used in programming?
Constant
The constants are the fixed value memory locations identified by an
identifier given by the programmer.
Explanation
The constant values cannot be change throughout the program. The
constant may be of any data types.
Integer constant.
Floating point constant.
Character constant.
Header File
Header files are the library files of the C language, which hold the particular
codes of the library functions.
Explanation
There are a number of library files in C language holding different functions
for different purposes like I/O functions and mathematical function.
Example
stdio.h, math.h, conio.h etc.
Q5. For what purpose the key words are used in C language?
Keywords
The C language provides some reserved words having standard and pre-
defined meanings in C, which are called keywords.
Explanation
The keywords appear in white color in the IDE of C; they have their special
purposes and cannot be used as a variable or function name. There are a
number of keywords present in C relevant to different types of programming
tasks.
Example
void if auto for while
int float continue break do
Q14. Define data type. How many data types are used in C language?
Data Type
A data type defines that what type of data is to be used in a program.
Explanation
The C language supports several different types of data, each of which may
be represented differently within the computer‟s memory. The basic data
types, their descriptions and the memory requirement for each data type are
listed in the following table.
Example
Typical Range
Date
Description Memory
Type
Requirement
int Integer quantity 2 bytes
char Single character 1 byte
float Floating point number 4 bytes
double Double-precision floating 8 bytes
point number.
An IDE contains the menus having commands which help the programmer
for easy to use programming from editing of the source code up to the on
screen output. The IDE contains the commands having short cut keys to
facilitate the programmer. It displays the error, warning and alerts to inform
the programmer about a specific problem.
Example
IDE of C language
IDE of Visual Basic 6
IDE of C Language
The IDE of C language has got a blue color editor for the editing of source
code. It displays different programming text in different colors. The
important menus of C language IDE are as follows:
File
Edit
Search
Run
Compile
Debug
Project
Options
Window
Help
A number of commands are there which
are required for the different
programming options.
Page 33 V: 03
Statement 1; // Function
Statement 2; // Body
…….
} // End of function
Program Demonstration
Our first example prints the text “This is my first C program” on the screen.
The program 3.1 shows the structure of complete C program.
Program
# include <stdio.h>
void main (void)
{
print f (“This is my first C program”);
}
The Development Cycle
The phase through which the C program passes is called a development
cycle These steps are as follows.
Editing source code
Compiling the program
Linking the program
Running the program
1. Editing Source Code
In the very first step an algorithm in going to be coded completely and
file is saved with the extension of .C or .CPP
2. Compiling the Program
Once a program has been edited, it needs to be compiled so that errors
can be shown. If no errors are there and object file having the same file
name but with extension of .OBJ is created.
3. Linking the Program
This step covers the inclusion of library files or other user defined header
files which function are used in the program.
4. Running the Program
If no syntax and linking error are there, the program can be run
successfully but any run time error can also produce problem in the
program output. When the program is going to run, a file is created
having same file name but it will have extension of .EXE
1. C = x2 + 2xy + y2
Solution:
C = pow(x,2) + 2 * x * y + pow (y,2);
34 | P a g e
2. K= a3 + 3ab(a+b) + b3
Solution:
K= pow(a,3) + 3* a*b*(a+b) + pow(b,3);
3. M = ( x + y) ( x – y)
( x + 3) ( x – 3)
Solution:
M= (( x + y) * ( x – y )) / ( ( x + 3 ) * ( x – 3 ));
4. N = x2 y 2
Solution:
N = Sqrt ( pow ( x,2 ) + pow ( y,2 ));
1
5. D =
x y
Solution:
D = 1 / sqrt ( x – y ) ;
6. O = 1 1
(x y) (x y)
Solution:
O = ( 1 / ( x – y )) * ( 1 / ( x + y) ) ;
7. S = xm - xn
Solution:
S = pow ( x , m) – pow ( x , n ) ;
ab
8. P =
a b
Solution:
P = Sqrt ( a + b ) / sqrt ( a - b) ;
(a x)(a 3)
9. T = |a| +
ax
ax
Solution:
T = abs ( a ) + sqrt (( a + x) * ( a – 3 )) / sqrt (( a + x ) / ( a – x ));
*******************
35 | P a g e
Example Program 3.1
Write a program using escape sequence and print the following lines of text
using single printf() statement.
Love Pakistan
&
Build Pakistan
Work Hard
To
Develop Your
Home Land
Source Code
void main()
{
clrscr();
printf("\n\t\t\t\tLove Pakistan\n\t\t\t\t\t\t&\n\t\t\t\tBuild
Pakistan\n\t\t\t\t\tWork
Hard\n\t\t\t\t\t\tTo\n\t\t\t\tDevelop Your\n\t\t\t\tHome Land");
getch();
}
-*******************
Example Program 3.2
Write a program that reads and prints the data using Escape sequence,
(asking the name, age, height and gender of a student).
Source Code
void main()
{
char gender,name[40];
int age;
float height;
clrscr();
printf("Enter your name: ");
scanf("%s",name);
printf("\nEnter your age: ");
scanf("%d",&age);
printf("\nEnter your height: ");
scanf("%f",&height);
printf("\nEnter your gender(m/f): ");
scanf("%s",&gender);
printf("\n\n\t\t\t==================\n");
printf("\t\t\t YOUR INFORMATION\n");
printf("\t\t\t==================\n");
36 | P a g e
printf("\t\t\tName : %s\n",name);
printf("\t\t\tAge : %d\n",age);
printf("\t\t\tHeight : %.2f\n",height);
printf("\t\t\tGender : %c\n",gender);
getch();
}
*******************
Source Code
void main()
{
char c,s[25];
int i;
float f;
clrscr();
printf("Enter any character: ");
scanf("%c",&c);
printf("\nEnter any string(max length 25): ");
scanf("%s",s);
printf("\nEnter any integer value : ");
scanf("%d",&i);
printf("\nEnter any floating point value: ");
scanf("%f",&f);
printf("\n\nCharacters : %c\n",c);
printf("String : %s\n",s);
printf("Integer : %d\n",i);
printf("Floating Point : %.2f\n",f);
getch();
}
*******************
Example Program 3.4
Write a program that reads and prints the data using Escape sequence,
(asking the name, age, height and gender of a student).
Source Code
void main()
{
char gender,name[40];
int age;
float height;
37 | P a g e
clrscr();
printf("Enter your name: ");
scanf("%s",name);
printf("\nEnter your age: ");
scanf("%d",&age);
printf("\nEnter your height: ");
scanf("%f",&height);
printf("\nEnter your gender(m/f): ");
scanf("%s",&gender);
printf("\n\n\t\t\t==================\n");
printf("\t\t\t YOUR INFORMATION\n");
printf("\t\t\t==================\n");
printf("\t\t\tName : %s\n",name);
printf("\t\t\tAge : %d\n",age);
printf("\t\t\tHeight : %.2f\n",height);
printf("\t\t\tGender : %c\n",gender);
getch();
}
*******************
38 | P a g e
Source Code
void main()
{
float eng, urdu, phy, comp, maths, tot, per; //Declaring Variables
clrscr();
//Taking Input for Marks
printf("\n Enter the marks of English.\t: ");
scanf("%f",&eng);
printf("\n Enter the marks of Urdu.\t: ");
scanf("%f",&urdu);
printf("\n Enter the marks of Physics.\t: ");
scanf("%f",&phy);
printf("\n Enter the marks of Computer.\t: ");
scanf("%f",&comp);
printf("\n Enter the marks of Mathematics.\t: ");
scanf("%f",&maths);
tot=eng+urdu+phy+comp+maths; //Calculating Total Marks And
Percentage
per=tot/500*100;
printf("\n The Total Marks Are = %0.2f\t”, tot);
printf("\n The Percentage is = %0.2f \t”, per);
getch();
}
*******************
Example Program 3.7
Write a program, take input for basic salary, house rent allowance, travel
allowance and medical allowance calculate 5% tax on gross pay and
calculate the net salary and print results.
Source Code
void main()
{
float BS, TA, HRA, MA, TAX,GP, NS; //Declaring Variables
clrscr();
printf("\n Enter Value for Basic Salary of Employee :\t ");
scanf("%f",&BS);
printf("\n Enter Value for House Rent Allowance :\t ");
scanf("%f",&HRA);
printf("\n Enter Value for Travel Allowance :\t ");
scanf("%f",&TA);
printf("\n Enter Value for Medical Allowance :\t ");
scanf("%f",&MA);
GP=BS+TA+HRA+MA;
TAX=5*GP/100;
NS=GP-TAX;
39 | P a g e
printf("\n ======Printing Salary Details======= \t”);
printf("\n The Basic Salary of Employee Is =%0.2f \t”, BS);
printf("\n The Tax Due on Employee Is =%0.2f \t”, TAX);
printf("\n The Net Salary of Employee Is =%0.2f \t”, NS);
getch();
}
*******************
Example Program 3.8
Write a program to solve the following mathematical equation.
K=a2+2ab+b2
Source Code
void main()
{
int a, b, K;
clrscr();
printf("\n Enter Value a:\t ");
scanf("%d",&a);
printf("\n Enter Value for b:\t ");
scanf("%d",&b);
K=a*a+2*a*b+b*b;
printf("\n ======Printing Result======= \t”);
printf("\n The Result of the Equation Is =%d \t”, K);
getch();
}
*******************
40 | P a g e
CHAPTER FOUR
OPERATORS
4
AND EXPERSSIONS
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Problems
Example problems with source codes
41 | P a g e
Chapter # 4
OPERATORS AND EXPRESSIONS
Classification of Operators
Operators fall into two basic classes:
Unary Operators
Binary Operators
Unary Operators
The operator which requires only one operand is called unary operator
Example
++ Increment Operator
-- Decrement Operator
Binary Operators
The operator which requires at least two operands for evaluation is called
binary operator.
Example
+, -, /, *
42 | P a g e
Explanation
Operators are always supposed to be performed on some value which may
be in form of a variable or constants. There may be multiple operands in a C
statement to evaluate.
Example
43 | P a g e
Explanation
The modulus operator which is denoted by % is also called remainder
operator. The values on which the operator is being applied may be constant
values or in the form of variables.
Example
C=7%2;
The variable C contains the remainder 1 which is leftover after dividing 7 by
2.
2. Assignment Operators
Assignment operator is denoted by (=) is it use to assign / to store the value
of an expression to an identifier.
Expression Meanings
a = 5; 5 is assigned in „a‟
Total = 74.75; 74.75 has been stored in total
Area = Length x breath; The product of length and breath
will be started in area.
44 | P a g e
Operator Operation Example Explanation
+= Add-assign a + =b same as a = a + b
-= Subtract-assign a – =b same as a = a – b
*= Multiply-assign a * =b same as a = a * b
/= Divide-assign a / =b same as a = a / b
% = Remainder-assign a %=b same as a = a % b
3. Relational Operators
The relational operators are used for the comparison of two operands. The
operands may be variables or constant or expressions that ultimately results
in a numeric value. Character values can also be compared as these can be
45 | P a g e
x = 5;
x = x + 1; //x is incremented
x++; // x is incremented by 1 using incremented operators.
x-- ; // x is decremented by 1 using decremented operators.
smaxgor PmlpmaxE
Example Program 4.1
Write a program to solve the following mathematical equation.
M= 1 1
(x y) (x y)
Source Code
void main()
{
int x, y, M;
clrscr();
printf("\n Enter Value x:\t ");
scanf("%f",&x);
printf("\n Enter Value for y:\t ");
scanf("%f",&y);
M = ( 1 / ( x – y )) * ( 1 / ( x + y) ) ;
printf("\n ======Printing Result======= \t”);
printf("\n The Result of the Equation Is =%0.0f \t”, M);
getch();
}
*******************
46 | P a g e
Example Program 4.2
Write a program to solve the following mathematical equation.
ab
P=
a b
Source Code
#include <math.h>
void main()
{
int a, b, P;
clrscr();
printf("\n Enter Value a:\t ");
scanf("%d",&a);
printf("\n Enter Value for b:\t ");
scanf("%d",&b);
P = sqrt ( a + b ) / sqrt ( a - b) ;
printf("\n ======Printing Result======= \t”);
printf("\n The Result of the Equation Is =%d \t”,P );
getch();
}
*******************
47 | P a g e
int a, b, Z;
clrscr();
printf("\n Enter Value a:\t ");
scanf("%d",&a);
printf("\n Enter Value for b:\t ");
scanf("%d",&b);
Z=(a+b)*(a-b);
printf("\n ======Printing Result======= \t”);
printf("\n The Result of the Equation Is =%d \t”, Z);
getch();
}
*******************
Problem 4.5
Write a program which uses arithmetical operators to calculate the area of a
triangle, volume of a sphere.
Source Code
void main()
{
float a,b,r,T,S;
clrscr();
printf("Enter the value for altitude of a triangle: ");
scanf("%f",&a);
printf("\nEnter the value for base of a triangle: ");
scanf("%f",&b);
printf("\nEnter the value for radius of a sphere: ");
scanf("%f",&r);
T=(1.0/2.0)*(a*b);
S=(4.0/3.0)*(3.142)*(r*r*r);
printf("\n\nArea of triangle = %.2f",T);
printf("\nArea of sphere = %.2f",S);
getch();
}
*******************
48 | P a g e
CHAPTER FIVE
CONDITIONAL
5
STATEMENTS
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Problems
Example problems with source codes
49 | P a g e
Chapter # 5
CONDITIONAL STATEMENTS
50 | P a g e
Q4. Explain the control structure iteration or repetitive flow.
Definition
The “if” statement is a conditional control structure. In programming "if"
statement is used when an action is supposed to be taken on the basis of
some condition.
Explanation
In programming, sometimes it happens when the programmer has to take
some action by checking some condition. The action can be taken not only
when the condition is true but also when the condition is false. The if
statement has mainly two parts
1) Condition
2) Action
The following are some general example
1. If tomorrow it is holiday, we will go for the picnic.
2. If I pass intermediate exam, I will apply in NED University.
3. If tomorrow it is raining. I will go for the picnic otherwise I will go to
the college.
Syntax
if (condition)
{
Action 1
Action 2
51 | P a g e
else
{
Action 1
Action 2
Flowchart
Example Program
#include <stdio.h>
#include <conio.h>
void main()
{
float bs, hra, ns; // declared variables
clrscr(); //cleared the screen.
printf(“\n Enter Basic Salary of Employee\t”)
scanf(“%f”, &bs);
/* Take input in the basic salary of employee. Now we will calculate the
house rent allowance on the basis of a condition */
Program Demonstration
In the above program we have taken input basic salary of an employee and
then mentioned a condition if the basic salary is greater then equal to 5000
we have calculated house rent allowance 10% of the basic salary and if the
condition is false then we have calculated the house rent allowance 5% of
the basic salary then the result has been printed.
*******************
52 | P a g e
Q2. Define and explain switch statement with syntax and example
program.
Definition
The switch statement is selection control which is used to select an option
from different alternatives.
Explanation
As compared to the if, the switch statement is used to check only for
equality. Normally the condition is checked by a variable called controlling
variable. The value of this may be type of integer or character but not any
other.
Syntax
switch (variable)
{
case 1:
Statement (s);
Break;
case 2:
statement (s);
break;
}
Flow Chart
Example Program
#include <stdio.h>
#include <conio.h>
void main()
{
int I;
53 | P a g e
clrscr();
print f (“ In Enter a number from 1 to 4\t”);
scan f(“%d”,& i);
switch (i)
{
case 1:
print f(“You are in case 1 \n”);
break;
case 2:
print f(“You are in case 2 \n”);
break;
case 3
print f(“You are in case 3\n”);
break;
default:
print f(“\n invalid input”);
}
getch();
}
Program Demonstration
In this example program we have taken input in a integer variable we have
mentioned that the value must be from 1 to 4. The reserved word case
checks the condition for equality for the alternate operations. The action is
performed under the concerned case. There may be one or more statement
under any case.
Purpose of Break
When the option is found in any of the case the statement(s) under the case
is performed and the break statement specifies that no more case should be
checked now.
Purpose of Default
The statements under the default are performed if the user input is not from
the given alternatives.
54 | P a g e
Syntax
if (condition)
{
if (condition)
{
Action 1
Action 2
}
}
Example Program
An organization provides 10% house rent allowance if the employee is male.
Not only this but also if his basic salary is greater than Rs. 5000
void main()
{
float bs,hra,ns;
char gender;
clrscr();
printf(“\n Enter basic salary of employee\t”);
scanf(“%f”,&gender);
if(gender=='M')
{
if (bs>5000)
{
hra=bs*10/100;
ns=bs+hra;
}
}
else
{
printf("\n No house rent allowance can be granted");
ns=bs;
}
printf(“\n The net salary of employee is %f\t”,ns);
getch();
}
Demonstration of the program
In the above program we have taken input for basic salary (bs) and gender
of an employee then we have checked the condition if the employee is male
then we have checked another condition that the basic salary is greater then
equal to 5000. We have calculated the house rent allowance as 10% of the
basic salary. Then we have printed the results.
55 | P a g e
Q4. Differentiate Switch Statement & if statement
56 | P a g e
Problem 5.2
Take Input for three numbers and find the greatest among them
Source Code
void main()
{
int a, b, c; //Declaring Variables
clrscr();
printf("\n Enter First Number:\t ");
scanf("%d",&a);
printf("\n Enter Second Number:\t ");
scanf("%d",&b);
printf("\n Enter Third Number:\t ");
scanf("%d",&c);
if(a>b && a>c)
printf("\n The First Number is Greatest that is\t%d”a);
else if (b>a && b>c)
printf("\n The First Number is Greatest that is\t%d”b);
else if (c>a && c>b)
printf("\n The First Number is Greatest that is\t%d”c);
getch();
}
*******************
Problem 5.3
Take input for two numbers x and y, Compare the numbers by if() and print
the message whether these are equal or not.
Source Code
void main()
{
int x,y;
clrscr();
printf("\n Enter the value for x:\t");
scanf("%d",&x);
printf("\n Enter the value for y:\t ");
scanf("%d, &y);
if (num1 == num2)
{
printf("\n you are in true action block.");
printf("\n No.1 and No.2 are equal." );
}
else
{
printf("\n You are in false action block");
printf("\n No.1 and No.2 are not equal.");
57 | P a g e
}
getch();
}
*******************
Problem 5.4
Take input for an employee's basic salary. If basic salary is greater then
5000 then give 10% house rent and calculate net salary otherwise 5% house
rent allowance and calculate net salary. Print net salary.
Source Code
void main()
{
float BS, HRA, NS; // declared variables
clrscr();
printf("\n Enter the employee's Basic Salary \t");
sanf("%f",&BS);
if (BS>5000)
{
HRA = BS*10/100;
NS = BS+HRA;
}
else
{
HRA = BS*5/100;
NS = BS + HRA;
}
pinttf("\n The net salary of the employee is\t %0.2f",NS);
getch();
}
*******************
Problem 5.5
Take input for gender and final percentage marks, if the gender is female
and marks are greater then 70% then student can apply for admission other
wise cannot apply for the admission.
Source Code
void main()
{
float per;
char gender;
clrscr();
printf("\n Enter value for gender 'm/f'\t");
scanf("%c",&gender);
printf("\n Enter value for percentage\t");
scanf("%f",&per);
if (gender=='f' && per >= 70)
58 | P a g e
{
printf("\n\n You can apply for the admission.");
}
else
{
printf("\n You can not apply for the admission.");
}
getch();
}
*******************
Problem 5.6
A company insures a person if he is male and having age less than 35 years.
Write a program to check whether a person is insured or not.
Source Code
void main()
{
//Declaring Variables
float BS, TA, HRA, GP, TAX, NS;
char GEN;
clrscr();
printf("\n Enter Gender of the Person :\t ");
scanf("%c",&gender);
printf("\n Enter Age of the Person :\t ");
scanf("%f",&AGE);
if(gender==‟m‟&&AGE<=35)
printf("\n The Person Is Insured\t”);
else
printf("\n The Person Is Not Insured\t”);
getch();
}
*******************
Problem 5.7
A company pays 10% house rent allowance and 8% travel allowance if the
basic pay of the employee is greater than 10000 otherwise the company
pays 7% house rent allowance and 5% travel allowance. Calculate the gross
pay.
Source Code
void main()
{
//Declaring Variables
float BS, TA, HRA, GP;
59 | P a g e
clrscr();
printf("\n Enter Value for Basic Salary of Employee :\t ");
scanf("%f",&BS);
if(BS>=10000)
{
HRA=7*BS/100;
TA=5*BS/100;
}
else
{
HRA=10*BS/100;
TA=8*BS/100;
}
GP=BS+TA+HRA;
printf("\n ======Printing Salary Details======= \t”);
printf("\n The Basic Salary of Employee Is =%0.2f \t”, BS);
printf("\n The House Rent Allowance For Employee Is =%0.2f \t”, HRA);
printf("\n The Travel Allowance For Employee Is =%0.2f \t”, TA);
printf("\n The Gross Pay of Employee Is =%0.2f \t”, GP);
getch();
}
*******************
Problem 5.8
A company pays 15% house rent allowance and 7% travel allowance if the
basic pay of the employee is greater than 12000 otherwise the company
pays 12% house rent allowance and 6% travel allowance. The employee has
to pay 5% tax on basic pay. Calculate the gross pay and net pay.
Source Code
void main()
{
//Declaring Variables
float BS, TA, HRA, GP, TAX, NS;
clrscr();
printf("\n Enter Value for Basic Salary of Employee :\t ");
scanf("%f",&BS);
if(BS>=12000)
{
HRA=15*BS/100;
TA=7*BS/100;
}
else
{
60 | P a g e
HRA=12*BS/100;
TA=6*BS/100;
}
TAX=5*BS/100;
GP=BS+TA+HRA;
NS=GP-TAX;
printf("\n ======Printing Salary Details======= \t”);
printf("\n The Basic Salary of Employee Is =%0.2f \t”, BS);
printf("\n The House Rent Allowance For Employee Is =%0.2f \t”, HRA);
printf("\n The Travel Allowance For Employee Is =%0.2f \t”, TA);
printf("\n The Gross Pay of Employee Is =%0.2f \t”, GP);
printf("\n The Tax Due on of Employee Is =%0.2f \t”, TAX);
printf("\n The Net Pay of Employee Is =%0.2f \t”, NS);
getch();
}
*******************
Problem 5.9
Write a program to make a simple calculator in C using switch statement.
Source Code
void main()
{
int a, b, ans=0;
char op;
clrscr();
printf("\n Enter Number1=\t");
scanf("%d",&a); //taking input for the two numbers
printf("\n Enter Number2=\t");
scanf("%d",&b);
printf("\n Enter Operator=\t");
scanf("%c",&op);
switch(op) // checking operator using switch
{
case „+‟:
ans=a+b;
break;
case „-‟:
ans=a-b;
break;
case „/‟:
ans=a/b;
break;
case „*‟:
ans=a*b;
break;
61 | P a g e
default:
printf("\n\n Invalid Operator Try Again");
}
printf("\n The answer is =%f\t",ans); // printing answer.
getch();
}
*******************
Problem 5.10
Develop a simple program of call center in C.
Source Code
void main()
{
int sc, a, ans=0;
char op;
clrscr();
printf("\n =======Welcome To Call Center=======\n",;
printf("\n Dial Service Code=\t");
scanf("%d",&sc); //taking input for the two numbers
printf("\n Press 1 To Check Balance\n Press 1 To Check
Balance\n Press 2 To Recharge\n Press 3 For Net Services\n
Press 4 To Call Operator\n \t");
scanf("%d",&a);
printf("\n Enter Operator=\t");
scanf("%c",&op);
switch() // checking operator using switch
{
case 1:
printf("\n Your Current Balance Is ---------- \t");
case 2:
printf("\n You Balance Can Be Loaded Using Card\t");
case 4:
printf("\n Your Current Balance Is ---------- \t");
case 5:
printf("\n Your Current Balance Is ---------- \t");
default:
printf("\n\n Invalid Operator Try Again");
}
printf("\n The answer is =\t",ans); // printing answer.
getch();
}
*******************
62 | P a g e
CHAPTER SIX
INPUT
6
OUTPUT FUNCTIONS
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
63 | P a g e
INPUT OUTPUT FUNCTIONS
IO function
Formatted Unformatted
Input Output
scanf(); printf();
Multiple Character Input Multiple Character Output
gets(); puts();
Formatted IO functions
Formatted IO function are the C language predefined functions which have a
particular syntax for writing its code. It is necessary to follow the proper
syntax while using them in a program.
Example
printf(); is an example of formatted output function.
And scanf(); is an example of formatted input function.
Syntax
Here is the syntax of scanf(); function.
Function Name Format Specifier Double quotes Address Operator
scanf(“%d”, &a);
64 | P a g e
Here is the syntax of printf(); function.
65 | P a g e
Function Name Format Specifier Double quotes
Unformatted IO functions
The formatted IO functions are the C language function which do not have a
specified syntax in parentheses.
Example
The following are the C lanuage formatted IO functions.
getch();
getche();
getchar();
gets();
puts();
putch();
putchar();
66 | P a g e
putchar();
It is a single character unformatted output function, which can display on
character.
Here is an example.
putchar();
gets();
This function is used to take input for multiple character values.
Here is an example.
x=gets(“Enter Your County Name”);
puts();
This function is used to give output for multiple characters
Here is an example.
puts(x);
*******************
67 | P a g e
CHAPTER SEVEN
ITERATION
7
AND ITS TYPES
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Problems
Example problems with source codes
68 | P a g e
CHAPTER # 7
ITERATION AND ITS TYPES
69 | P a g e
Q3. Explain For loop with syntax and example program.
For Loop
In C- language the most commonly used iterative control structure is „for
Loop‟ which is used to repeat a statement or block of statements for a
specific number of times.
Syntax
for (Initialize Exp; Test Exp; Increment/Decrement Exp)
{
statement(s);
}
Explanation
The „for loop‟ includes three expressions in the parenthesis. The initialize
expression tells the compiler the starting value from where the Loop is going
to be started. The test expression specifies the Last limit until the iteration
has to be performed. The increment or decrement brings the started value
across the test expression. After the parenthesis the bracks {} include a
statement or a block of statements to be repeated.
Example Program
void main()
{
int a ;
clrscr(); //Counter Variable
for (a=1;a<=10;a++)
{ // Block of Loop
printf(“ \n Welcome”);
} // Repetation
getch();
}
Program Demonstration
The program uses a counter variable „a‟ of type integer. The loop starts from
1 and is repeated up to 10 times by increment of 1. So the message
„Welcome‟ will be printed 10 times.
*******************
70 | P a g e
Q4. Explain while loop with syntax and example program.
While Loop
While loop is a iterative control structure of C. It is a conditional loop which
is used to repeat a statement or block of statements for a number of times
depending on a condition.
Syntax
while(condition)
{
statement(s);
}
Explanation
While loop is used in a particular programming situation when a statement
or multiple statement are to be repeated on the bases of some mentioned
condition.
Example Program
void main()
{
int a=0;
clrscr();
while(a<10)
{
getch();
}
71 | P a g e
Demonstration of the Program
In the above program the programmer has asked to enter a value less than
10. The loop continues until the user does not enter any value which is
greater than or equal to 10. Hence in this situation the numbers of iterations
are not specified, it is dependent on the entered value.
Explanation
The do while loop is used in a programming situation when the action block
is supposed to be performed at least once even if the condition is false.
Hence in the do while loop the condition comes after the action block.
Flow Chart
72 | P a g e
Example Program
void main()
{
char ans=‟N‟;
clrscr();
do
{
printf(“\nCollege of Emerging Technologies”);
printf(“ \nDo you want to print the college name again\tY\N”);
scanf(“%c”,&ans);
}
while(ans==‟Y‟);
getch();
}
Demonstration of the Program
In the above program we have printed the college name on screen and then
it has been asked if the user want to print more. Although the condition is
false in the very first step but the message is printed one time.
Nested Looping
Nested looping is defined as the loop inside the loop. It is a cyclic execution
of a statement or block of statement for specified number of times.
Syntax
for (initialize Exp; text Exp; Increment/Decrement Exp)
{
for (initialize Exp; text Exp; Increment/Decrement Exp)
{
statement(s);
}
}
73 | P a g e
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015- 2016
Flow Chart
Explanation
Loop is an iterative control structure which is used to repeat statement(s) for
a number of times on the bases of some condition. Nested looping refers to
the loop inside a loop for the repetition of some program instructions.
Nested looping can be applied on any of the loop type like for, while and do
while loops. The inner loop repeats the statement(s) for a specific number of
times and the outer loop repeats the inner loop for a specified number of
times.
Example Program
Example Program
void main()
{
int a,b;
clrscr();
for(a=1;a<=5;a++)
{
for(b=1;b<=10;b++)
printf(“\t%d”,b);
}
getch();
}
Page 74 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
Example Programs
Example Program 7.1
Write a program using for loop to print usual printing characters
corresponding to 32 to 127 ASCII code.
Source Code
void main()
{
int a;
clrscr();
for(a=32;a<=127;a++)
{
printf("%3d=%c\t",a,a);
}
getch();
}
Output
32= 33=! 34=" 35=# 36=$ 37=% 38=& 39=' 40=(
41=)
42=* 43=+ 44=, 45=- 46=. 47=/ 48=0 49=1 50=2
51=3
52=4 53=5 54=6 55=7 56=8 57=9 58=: 59=; 60=<
61==
62=> 63=? 64=@ 65=A 66=B 67=C 68=D 69=E 70=F
71=G
72=H 73=I 74=J 75=K 76=L 77=M 78=N 79=O 80=P
81=Q
82=R 83=S 84=T 85=U 86=V 87=W 88=X 89=Y 90=Z
91=[
92=\ 93=] 94=^ 95=_ 96=` 97=a 98=b 99=c 100=d
101=e
Page 75 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
*******************
Source Code
void main()
{
double pow=1;
int i,num,p;
clrscr();
printf("Enter number : ");
scanf("%d",&num);
printf("\nEnter power : ");
scanf("%d",&p);
for(i=1;i<=p;i++)
{
pow*=num;
}
printf("\nAnswer is %.2f",pow);
getch();
}
Output
Enter number : 6
Enter base : 3
Answer is 216.00
*******************
Example Program 7.3
Write a program using nested for loop to print to print the following.
*
***
*****
*******
*********
Page 76 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Source Code
void main()
{
int a,x,y,m=4,n=1;
clrscr();
for(y=0;y<=4;y++)
{
for(x=1;x<=m;x++)
{
printf(" ");
}
for(a=1;a<=n;a++)
printf("*");
n=n+2;
m--;
printf("\n");
}
getch();
}
Output
*
***
*****
*******
*********
*******************
Page 77 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output
Enter value to print its table 7
7x1=7
7x2=14
7x3=21
7x4=28
7x5=35
7x6=42
7x7=49
7x8=56
7x9=63
7x10=70
*******************
Page 78 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
*******************
Page 79 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER EIGHT
FUNCTIONS
8
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Problems
Example problems with source codes
Page 80 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER # 8
FUNCTIONS
Page 81 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 82 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 83 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
The returning data type defines the data type of returning value from the
function definition. If the function does not return any value, the returning
data type is void. The function name is an identifier with the sign of
parentheses. The arguments are separated by commas and mentioned in the
parentheses. If no argument are their then the term “void” is written.
Syntax
The syntax of function prototype is as follows
Returning_data_type function_name (type of arg1, type of arg2 ….);
Example
A function for addition of three numbers
int sum ( int ,int,int);
2. Function Definition
The function definition defines the task of the function which is to be done
when the function is called. The function definition has two parts.
Function Header.
Body of the Function
The function header looks like a function declaration but it also includes the
variable names with the data types in the arguments. The function definition
is not terminated by semi-colon rather it has a block having the instructions
about the task of the function. It is called the body of the function. The body
of the function is enclosed by curly brackets.
Syntax
Returning_data_type function_name (type arg1, types arg2 ............. )
{
Statement(s);
}
Example
int sum(int x, int y, int z);
{
z=x+y+z;
return z;
}
3. Function call
The definition function can be called from the main function or from any
other function. If any value is being returned from the function definition, so
it necessary to hold the value in a variable.
Syntax
Variable_Name= Function_Name(arg1,arg2................);
Example
Ans = sum(21,22,34);
Example Program
float pi (void); // Function Déclaration
void main ()
{
Page 84 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
float ans;
clrscr ();
ans = pi (); // Function Call
printf(“\n the value of pi is \t %f”, ans);
getch ();
}
float pi (void) // Function Definition
{
float x;
x = 3.142;
return x;
}
Example Problems
Example Program 8.1
Write a program, define a function print a message of "Pakistan
Zindabad. Now call this function from main() five times.
Source Code
void msg(void);
void main()
{
clrscr();
msg();
msg();
msg();
msg();
msg();
getch();
}
void msg()
{
printf("\n Pakistan Zindabad");
}
*******************
Example Program 8.2
Write a program, define a function which can add two integers. Then call
the function at least two times from main() function.
Source Code
int sum(int, int);
void main()
{
int ans;
clrscr();
ans=sum(21,42);
Page 85 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 86 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Source Code
void sal(float, float, float);
void main ()
{
clrscr ();
sal (10000, 3500, 300);
sal (10000, 3500, 300);
sal (5000, 2200, 150);
getch ();
}
void sal(float BS, float HRA, float TA);
{
float NS;
NS = BS + HRA – TAX;
printf(“\n the net salary of employee is \t % 0.2f”, NS);
}
*******************
Page 87 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER NINE
DATABASE
9
MANAGEMENT SYSTEM
CONCEPTS
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Page 88 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER # 9
DATA BASE MANAGEMENT SYSTEM CONCEPTS
Page 89 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Entities
An entity is defined as any physical or logical thing which has some
characteristics of some value.
Example
Person: - Employee, student, patient, customer
Place: - State, Country, Region
Physical Object: - Machine, building
Logical Thing: - Account, company
Event: - Deposit amount, purchase.
*******************
Entity Set / Table
An entity set / table is a collection of different instances of the same entity
with there attributes.
Explanation
Collection of rows and columns relating to the same type of entity is called
the table. In relational database management system a table is termed as
the relational variable.
Example
Student
SID Name Address CellNo DOB
Page 90 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
In the table of student: SID, Name, Address, CellNo, DOB are the attributes
and values under these properties make a complete record.
Page 91 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Explanation
The theory behind the relational database model is called relational
algebra, which contain rules and regulations and mathematical methods
for relational database. The relational algebra was forwarded by Dr. Edgar
F, cod, a famous mathematician.
Example
A number of RDBMS are available however the most popular are Oracle,
Sybase, Ingress, Informix, Microsoft SQL Server, Microsoft Access, MySql
and so on.
============Long Questions and Answers==============
Page 92 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 93 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 94 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 95 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 96 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
The DBMS must allow each field to remain null (or empty). Specifically, it
must support a representation of "missing information and inapplicable
information" that is systematic, distinct from all regular values (for
example, "distinct from zero or any other number", in the case of numeric
values), and independent of data type. It is also implied that such
representations must be manipulated by the DBMS in a systematic way.
Page 97 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Changes to the logical level (tables, columns, rows, and so on) must
not require a change to an application based on the structure. Logical
data independence is more difficult to achieve than physical data
independence.
Page 98 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Example
Oracle, SQL Server etc
Page 99 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
3. Utilities
The utilities are the sub-programs which facilities the user for the maintains
of the database.
Data dictionary maintenance
Monitoring Performance
Data Prevention
Page 100 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
4. Report Generator
The report generator is a DBMS component which can produce on-screen
and print out report according to the requirement. The user is able to specify
the format of the report.
Example
Oracle Report Builder
Seagate crystal Reports
5. Security Manager
The security manager is the important component of the DBMS which
enables the DBA (Database administrator) to specify different access
privileges for different user of DBMS. The purpose of the security feature is
of course to protect data from unauthorized user.
Example
Oracle Rights Manager
Q7. Describe key fields and their types used in a database table.
Key Field
There may be a number of fields present in a table, but a field which
uniquely identifies all the records is called key field.
Explanation
The key field is unique in nature. There cannot be any duplication in a key
field. Similarly it cannot have a null value. The key field may be of the
following types.
Candidate Key
Primary Key
Secondary Key
Foreign
Example
Employee: NIC, NTN, Password #, EID etc
1. Candidate Key
All unique keys present in a table behave as candidate keys. It means that
these are candidate to be selected as a primary key.
Example
Employee: NIC, NTN, Passport #, EID etc.
Here the entire given field are candidate keys
Page 101 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
2. Primary Key
From the candidate keys, a key
which is selected as to uniquely
identify all the record is called a
primary key.
Normally in ERDs the primary key is
Employee
underline in a table. Here EID is a
primary key EID
NTC
3. Secondary Key Name
Once a primary key has been Address
selected the remaining candidate NTN
keys are called secondary keys Phone #
Here NIC and NTN are secondary
keys.
4. Foreign Key
In the database when a table is suppose to be linked with another table a
key field is required in both the tables which is called foreign key.
Two tables cannot be linked without a foreign key. A primary key can also be
used as foreign key.
Here SID is primary key in the table of “student” and it is foreign key in the
table of “Marks”.
Page 102 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
DBMS RDBMS
1 The database management A relational database is a
system is special purpose particular DBMS based on
software to manage data base relational algebra.
2 It is based on the rules of It is based on relational algebra
DBMS
3 The database management The theory behind the relation
system makes it possible to database model is called relational
develop a database for an algebra, which contain rules and
organization and provides regulations and mathematical
techniques to perform all methods for relation database.
types of database operation The relational algebra was
like creation, insertion, forwarded by Dr. Edgar F, cod, a
deletion, updating. famous mathematician.
4 The DBMS foundations were The relational algebra was
developed by different forwarded by Dr. Edgar F, cod, a
computer science and famous mathematician.
mathematics scientists.
5 Example: Fox Pro Example : Oracle, SQL Server MS-
Access etc
Page 103 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER TEN
10
MICROSOFT
ACCESS
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Page 104 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER # 10
MICROSOFT ACCESS
Text
Character data can be stored using this data type. Maximum 255 characters
can be stored while using this data type.
Explanation
(Default) Text or combinations of text and numbers, as well as numbers that
don't require calculations, such as phone numbers can be stored using this
data type. The field size may be up to 255 characters or the length set by
the Field Size property. Microsoft Access does not reserve space for unused
portions of a text field
Example
Page 105 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Name, Address, Qualification etc are some examples of the fields for which
text data type can be stored.
Page 106 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Table
Form
Query
Reports
Pages
Macros etc
Now we will discuss these objects in detail
1. Table/Relational Variable
In a relational database a Table is also called relational variable. A table is a
collection of rows and columns, where row represents a complete record and
a column represents related fields.
Example
Student
SID Name Class Address Phone
Code
0300 Mahrukh G2M1 Tipu Sultan R. 4371298
0301 Javeria G2M2 Tariq Road. 4572370
0302 Zeeshan P2M2 Khadda Mrk. 4209211
2. Form
A form is defined as a GUI or windows like object which facilitates a user to
perform database operations (insertion, deletion, updating, searching) in an
easy to se way.
Example
Page 107 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
3. Query
A query is a view of selected columns taken from a single or multiple tables.
A query is not an actual table it shows the data of existing tables.
Sometimes user needs to have the data of different columns from different
tables, in this situation a query is defined as a view level table.
Example: - Table: Student
4. Report
A report is an important MS-ACCESS
object it facilitates the database
designer to generate on screen as well
as print out reports for the Users
according to the requirement. The data
is taken from the concerned tables.
Report can be formatted according to
the requirement having logos, Company
Page 108 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
5. Pages
MS-ACCESS object which enables a database designer to create web pages
linked with the database. The data will be accessed from the concerned
tables while using the website.
Page 109 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 110 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER ELEVEN
PRACTICAL PROGRAMMING
11
PROBLEMS IN C
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Problems With Algorithm and Source Code
1. Write a program that generate 1 to 10 numbers, calculate and print
average of these numbers.
2. Write a program that reads marks of five subjects, calculate the total
marks, percentage, and state whether the student is passed or fail.
3. Write a program to generate the table of N.
4. Find the factorial of N, use scanf() to read the value of N.
5. Write a program that finds out the largest number among three input
numbers.
6. Write a program which uses arithmetical operators to calculate the area of
a triangle, volume of a sphere, etc.
7. Write a program to print square and cube of first ten prime numbers.
8. Write a program, to calculate the roots of a quadratic equation
ax2+bx+c=0.
9. Write a program using for loop to print usual printing characters
corresponding to 32 to 127 ASCII code.
10. Write a program, which uses a switch and break statements.
11. Write a program that calculate power of base without using power
function by taking input both.
12. Write a program to calculate pay roll of an employee. Read the basic pay
from keyboard; calculate medical allowance as 15% of basic pay,
conveyance allowance as 20%, and house rent allowance as 45% of basic
pay. Calculate gross pay and net pay and print all.
13. Write a program using nested for loop to print pyramid of stars.
14. Write a program using function that accepts two numbers as its
arguments and returns summation of these two numbers.
Page 111 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Experiment No 1
Write a program that generate 1 to 10 numbers, calculate and print average
of these numbers.
Algorithm
Step 1 START
SET sum= 0
Step 2 REPEAT a=1 TO 10
i.WRITE a
ii.SET sum=sum+a
Step 3 END REPEAT
Step 4 SET avg=sum/10
Step 5 END
Source Code
void main()
{
int a,sum=0;
float avg;
clrscr();
for(a=1;a<=10;a++)
{
printf("\t%d",a);
sum+=a;
}
avg=sum/10;
printf(“\n The sum of first ten numbers is=\t%d”,sum);
printf(“\n And the average of first ten numbers is=\t%0.2f”,avg);
getch();
}
Output
1 2 3 4 5 6 7 8 9 10
The sum of first ten numbers is= 55
And the average of first ten numbers is= 5.5
*******************
Experiment No 2
Write a program that reads marks of five subjects, calculate the total marks,
percentage, and state whether the student is passed or fail.
Algorithm
Step 1 START
Step 2 READ eng
Step 3 READ urdu
Page 112 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 113 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Source Code
void main()
{
int a,N;
clrscr();
printf("\nEnter value to print its table\t");
scanf("%d"&a);
for(a=1;a<=10;a++)
{
printf("\n%dx%d=%d",N,a,N*a);
}
getch();
}
Output
Enter value to print its table 7
7x1=7
7x2=14
7x3=21
7x4=28
7x5=35
7x6=42
7x7=49
7x8=56
7x9=63
7x10=70
*******************
Page 114 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Experiment No 4
Find the factorial of N, use scanf() to read the value of N.
Algorithm
Step1. Start.
Step2. Set f = 1, i = 0
Step3. Read num
Step4. Repeat WHILE num <= 0.
c. “Write Error! You have enter no. less than 0”
d. Read num
[End of outer WHILE loop]
Step5. Repeat FOR n = 1 to num
a. Set f = f * 1
[End of FOR Loop]
Step6. Write f
Step7. Exit
Source Code
void main()
{
double f=1;
int num,n;
clrscr();
printf("Enter the no. greater than 0 to find its factorial: ");
scanf("%d",&num);
while(num<0)
{
printf("\nError! number is less than 0.\n");
printf("Please enter number greater than 0: ");
scanf("%d",&num);
}
for(n=1;n<=num;n++)
{
f*=n;
}
printf("\nThe factorial of %d is %f",num,f);
getch();
}
Output
Enter the no. greater than 0 to find its factorial: -3
Page 115 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
*******************
Experiment No 5
Write a program that finds out the largest number among three input
numbers.
Algorithm
Step 1 START
Step 2 READ a
Step 3 READ b
Step 4 READ c
Step 5 IF a>b AND a>c THEN
WRITE “a is largest”
ELSE IF b>c AND b>a THEN
WRITE “ b is largest”
ELSE
WRITE “ c is largest”
END IF
Step 6 END
Source Code
void main()
{
int a,b,c;
clrscr();
printf("\nEnter First Number\t");
scanf("%d",&a);
printf("\nEnter Second Number\t");
scanf("%d",&b);
printf("\nEnter Third Number\t");
scanf("%d",&c);
if(a>b&&a>c)
printf("\n First number is largest that is %d",a);
else if(b>a&&b>c)
printf("\n Second number is largest that is %d",b);
else
printf("\n Second number is largest that is %d",c);
getch();
}
Output
Enter First Number 45
Enter Second Number 72
Page 116 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 117 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Experiment No
Write
118 a program to print square and cube of first ten prime numbers.
Algorithm
Step1. Start.
Step2. Repeat FOR p = 1 to 30
a. Set isPrime = 1
b. Repeat FOR d = 2 to p
a. IF p % d is equal to 0 then
b. Set isPrime = 0
c. IF isPrime is not equal to 0 then
d. Write p,pxp,pxpxp
[End of FOR Loop]
[End of FOR Loop]
Step3. Exit
Source Code
void main ()
{
int p, d, isPrime;
clrscr();
for(p=1;p<=30;++p)
{
isPrime=1;
for(d=2;d<p;++d)
if(p%d==0)
isPrime=0;
if (isPrime!=0)
printf ("\n%d\t%d\t%d ", p,p*p,p*p*p);
}
getch();
}
Output
2 3 5 7 11 13 17 19 23 29
2 4 8
3 9 27
5 25 125
7 49 343
11 121 1331
13 169 2179
17 289 4913
19 361 6859
23 529 12167
29 841 24389
*******************
Page 118 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Experiment No 8
Write a program, to calculate the roots of a quadratic equation ax2+bx+c=0.
Algorithm
Step1. Start.
Step2. Read a, b, c
Step3. Set xp = (-b)+(sqrt(pow(b,2.0)-(4.0*a*c)))/(2.0*a)
xn = (-b)-(sqrt(pow(b,2.0)-(4.0*a*c)))/(2.0*a)
Step4. Write xp, xn
Step5. Exit
Source Code
#include<math.h>
void main()
{
int a,b,c;
float xp,xn;
clrscr();
printf("\nEnter the value for a : \t");
scanf("%d",&a);
printf("\nEnter the value for b : \t");
scanf("%d",&b);
printf("\nEnter the value for c : \t");
scanf("%d",&c);
xp = (-b)+(sqrt(pow(b,2.0)-(4.0*a*c)))/(2.0*a);
xn = (-b)-(sqrt(pow(b,2.0)-(4.0*a*c)))/(2.0*a);
printf("\nThe roots of given equation are (%.2f,%.2f)",xp,xn);
getch();
}
Out Put
Enter the value for a : 5
Enter the value for b : 10
Enter the value for c : 25
*******************
Experiment No 9
Write a program using for loop to print usual printing characters
corresponding to 32 to 127 ASCII code.
Algorithm
Step1. Start.
Step2. Repeat FOR a = 32 to 127
Write a, a
[End of FOR Loop]
Step3. Exit
Page 119 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Source Code
void main()
{
int a;
clrscr();
for(a=32;a<=127;a++)
{
printf("%3d=%c\t",a,a);
}
getch();
}
Output
32= 33=! 34=" 35=# 36=$ 37=% 38=& 39=' 40=(
41=)
42=* 43=+ 44=, 45=- 46=. 47=/ 48=0 49=1 50=2
51=3
52=4 53=5 54=6 55=7 56=8 57=9 58=: 59=; 60=<
61==
62=> 63=? 64=@ 65=A 66=B 67=C 68=D 69=E 70=F
71=G
72=H 73=I 74=J 75=K 76=L 77=M 78=N 79=O 80=P
81=Q
82=R 83=S 84=T 85=U 86=V 87=W 88=X 89=Y 90=Z
91=[
92=\ 93=] 94=^ 95=_ 96=` 97=a 98=b 99=c 100=d
101=e
102=f 103=g 104=h 105=i 106=j 107=k 108=l 109=m 110=n
111=o
112=p 113=q 114=r 115=s 116=t 117=u 118=v 119=w 120=x
121=y
122=z 123={ 124=| 125=} 126=~ 127=⌂
******************
Experiment No 10
Write a program, which uses a switch and break statements.
Algorithm
Step1. Start.
Step2. Read num1, num2
Step3. Read switch op
Step4. IF switch op = „+‟
Write num1 + num2
IF switch op = „-‟
Write num1-num2
Page 120 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
IF switch op = „*‟
Write num1 * num2
IF switch op = „/‟
Write num1 / num2
Step5. ELSE
Write Unknown operator
Step6. Exit
Source Code
void main()
{
float num1=1.0,num2=1.0;
char op, c;
clrscr();
A:
printf("Type number, operator, number : ");
scanf("%f %c %f", &num1, &op, &num2);
switch(op)
{
case'+':
printf(" = %.2f",num1+num2);
break;
case'-':
printf(" = %.2f",num1-num2);
break;
case'*':
printf(" = %.2f",num1*num2);
break;
case'/':
printf(" = %.2f",num1/num2);
break;
default:
printf("\nUnknown operator");
}
Page 121 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output
Type number, operator, number : 12 + 7
= 19.00
Do you want to perform again y/n y
Type number, operator, number : 2 * 4
= 8.00
Do you want to perform again y/n y
Type number, operator, number : 8 - 7
= 1.00
Do you want to perform again y/n y
Type number, operator, number : 16 / 3
= 5.33
Do you want to perform again y/n n
*******************
Experiment No 11
Write a program that calculate power of base without using power function
by taking input both.
Algorithm
Step1. Start.
Step2. Read num, p
Step3. Repeat FOR i = 1 to p
a. Set pow = pow * num
[End of FOR Loop]
Step4. Write pow
Step5. Exit
Source Code
void main()
{
double pow=1;
int i,num,p;
clrscr();
printf("Enter number : ");
scanf("%d",&num);
printf("\nEnter power : ");
scanf("%d",&p);
for(i=1;i<=p;i++)
{
pow*=num;
}
printf("\nAnswer is %.2f",pow);
getch();
}
Page 122 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output
Enter number : 6
Enter base : 3
Answer is 216.00
*******************
Experiment No 12
Write a program to calculate pay roll of an employee. Read the basic pay
from keyboard; calculate medical allowance as 15% of basic pay,
conveyance allowance as 20%, and house rent allowance as 45% of basic
pay. Calculate gross pay and net pay and print all.
Source Code
void main()
{
float BS,MA,CA,HRA,GPAY,NPAY,TAX=0;
clrscr();
printf("\nEnter the basic pay of employee\t");
scanf("%f",&BS);
MA=15*BS/100;
CA=20*BS/100;
HRA=45*BS/100;
GPAY=BS+MA+CA+HRA;
NPAY=GPAY-TAX;
printf("\nEmployee\'s basic salary is \t%0.2f",BS);
printf("\nEmployee\'s medical allowance is\t %0.2f",MA);
printf("\nEmployee\'s conveyance allowance is\t %0.2f",CA);
printf("\nEmployee\'s house rent allowance is\t %0.2f",HRA);
printf("\nEmployee\'s gross pay is \t%0.2f",GPAY);
printf("\nEmployee\'s net pay is \t %0.2f",NPAY);
getch();
}
Algorithm
Step 1 START
Step 2 READ BS
Step 3 SET TAX=0
Step 4 SET MA=15*BS/100
Step 5 SET CA=20*BS/100
Step 6 SET HRA=45*BS/100
Step 7 SET GPAY=BS+MA+CA+HRA
Step 8 SET NPAY=GPAY-TAX;
Step 9 WRITE BS
Step 10 WRITE MA
Step 11 WRITE HRA
Step 12 WRITE GPAY
Step 13 WRITE NPAY
Page 123 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Step14 END
Output
Enter the basic pay of employee 5000
Employee‟s basic salary is 5000
Employee‟s medical allowance is 750
Employee‟s conveyance allowance 1000
Employee‟s house rent allowance is 2250
Employee‟s gross pay is 9000
Employee‟s net pay is 9000
*******************
Experiment No 13
Write a program using nested for loop to print to print the following.
*
***
*****
*******
*********
Algorithm
Step1. START
Step2. SET m=4
Step3. SET n=1
Step4. Repeat FOR y =1 to 4
a. REPEAT FOR x = 1 to m
b. WRITE space
END REPEAT
c. REPEAT FOR a = 1 to n
d. WRITE *
END REPEAT
e. SET n=n-2
f. WRITE new line
END REPEAT
Step5. END
Source Code
void main()
{
int a,x,y,m=4,n=1;
clrscr();
for(y=0;y<=4;y++)
{
for(x=1;x<=m;x++)
{
printf(" ");
Page 124 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
}
for(a=1;a<=n;a++)
printf("*");
n=n+2;
m--;
printf("\n");
}
getch();
}
Output
*
***
*****
*******
*********
*******************
Experiment No 14
Write a program using function that accepts two numbers as its arguments
and returns summation of these two numbers.
Algorithm
Step 1 START
Step 2 READ a
Step 3 READ b
Step 4 SET ans=sum(a,b)
Step 5 RETURN x+y
Step 6 WRITE ans
Step 7 END
Source Code
int sum(int,int);
void main()
{
int a,b,ans;
clrscr();
printf("\nEnter first number\t");
scanf("%d",&a);
printf("\nEnter second number\t");
scanf("%d",&b);
ans=sum(a,b);
Page 125 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output
*******************
Page 126 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER TWELVE
12
MIRCROSOFT ACESS
PRACTICALS
OBJECTIVE:
When you have completed this chapter, you will be able
to perform the following practicals
Page 127 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
PRACTICAL NO.1
Objectives:
Procedure:
1- First we click on the start then move to the programs and then open
Microsoft Access Click on the blank database option to create a New
Database (Bank Account)
2- Click create Table in Design View t Create a New Table Account Info and
enter fields name which are Acct_ID, Acct_Name, Acct_Address,
Acct_Phone, Acct_Email.
3- Create 2nd Table in Design View (Account Status)
4- Create relationship b/w Account Info. Acct_ID and Account Status,
Acct_ID
5- Create a Query that will retrieve desired Acct_ID
SELECT*
FROM Account Info
WHERE Account Info. Acct_ID= [Account Identification No. is];
6- Create 2nd Query which will give desired result
DELET*
FROM Account Info
WHERE Account Info, Acct_ID =[ Account Identification No. is];
7- Create 2nd Query which will give desired result
UPDATE Account Info
SET Acct_Name= [Account Holder Name],
Acct_Address= [Account Holder Address],
Acct_Phone= [Account Holder Phone],
Acct_Email= [Account Holder Email]
WHERE Acct_ID= [Account Holder Identification];
Page 128 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output:
1st Table:
2nd Table:
Page 129 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 130 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
PRACTICAL NO. 2
Objective:
Procedure:
1. First we click on start then move to programs and then open
Microsoft Access .click on blank data baseoption to create a New
Database (Student attendance).
2. Click Create Table in Design View to Create a New table Student
Info and enter fields name which are
Stud_ID,Stud_Name,Stud_Address,Stud_Phone,
Stud_Email.
3. Create 2nd Table in design View Student Attendence and enter
fields names are (Stud_ID,Stud_Attendance)
4. Create relationship b/w Student info.Stud_ID & Student
Attendence.Acct_ID
5. Create a Query that will retreive desired Stud_ID.
SELECT*
FROM [student info].
WHERE Stud_ID=[Student identification number
Is];
6. Create 2nd Query which will give desired result
DELETE*
FROM [Student info]
WHERE Stud_ID= [Student identification number is];
7. Create 2nd Query which will give desired result
UPDATE [Student info]
SET Stud_Name = [Student Name],
Stud_Adress = [Student Address],
Stud_Phone = [Student Phone],
WHERE Stud_ID[Student Identification No].
Page 131 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output:
1st Table:
2nd Table:
Table Relationship:
Page 132 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 133 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
PRACTICAL NO.3
Objective:
Procedure:
Output:
Page 134 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 135 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
PRACTICAL NO.4
OBJECTIVE:
PROCEDURE:
Page 136 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output:
Book Table:
Page 137 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Issued Books
Page 138 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
RACTICAL No. 5
Objective:
Employee
Salary
Procedure
1. Open Microsoft Access and select bland Access database, click Ok
button to display File New Database dialog window. Type the
database name. Click on the option to finish process.
2. Create a table by using Design. Enter the required fields into the
cell with their suitable data type. Then select the (Emp_id) as a
Primary key. Then save the table and give the suitable name
3. Create an Employee table which is given in objective.
4. Create a salary table which is given in objective.
5. Then calculate gross_pay as Gross_pay = Medical Allownce +
Convience allowance + House Rent Allownce + Basic Pay.
6. Then Calculate Tax as 5 % of Gross Pay.
7. Then Calculate Net Pay = Gross Pay- Tax.
All the above criteria can be met by coding the following SQL
query.
Page 139 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output:
Table Employee:
Table Salary:
Page 140 V: 03
Muhammad Uwais BIT-MCS (KU)
Relationships: Computer Science XII 2015-2016
Page 141 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 142 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
PRACTICAL NO.6
Objective:
Item
Item_Id Item _Name Item _rate
Customer
Customer_Id Name Phone Address
Order
Customer_Id Date Item_Id Quantity Amount
Search the items which are sold within a given range of Dates.
Delete the record where Name like”Ahmed”.
Update the record; set Item_rate to 400 where Item_code like
K101.
Procedure:
Page 143 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output:
Page 144 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Table Item:
Relationship:
Page 145 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
PRACTICAL No. 7
Objective:
Patient
Status
Procedure:
Open Microsoft Access and select bland Access database, click Ok
button to display File New Database dialog window. Type the database
name. Click on the option to finish process.
Create a table by using Design. Enter the required fields into the cell
with their suitable data type. Then select the (Patient_ Id) as a
Primary key. Then save the table and give the suitable name.
Create a Patient table which is given in the objective.
Create a Status table which is given in the objective.
Create a query in which show the patients under treatment of a
particular doctor “Dr. Ahmer”.
Create a query to delete the record of the patient who has been
discharged.
Create a query using design method to update the prescription of a
particular patient.
Page 146 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 147 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 148 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 149 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
PRACTICAL No. 8
Objective:
Bio Data
Marks
Procedure:
1. Open Microsoft Access and select bland Access database, click Ok
button to display File New Database dialog window. Type the database
name. Click on the option to finish process.
2. Create a table by using Design. Enter the required fields into the cell
with their suitable data type. Then select the (Roll_No) as a Primary
key. Then save the table and give the suitable name.
3. Create a Bio Data table which is given in the objective.
4. Create a Marks table which is given in the objective.
5. Input five records in tables.
6. Create a query in which calculate the percentage up to 2 decimal
places.
7. Create a query in which we have to calculate the highest marks.
Page 150 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Output:
Table: Bio data:
Table: Result:
Page 151 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 152 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER THIRTEEN
QUESTIONS
13
AND ANSWERS FOR SELF
PRACTICE
OBJECTIVE:
When you have completed this chapter, you will be able
to know about the
Question from C Language
Exercises 1
Getting Started with C
Exercises 2
The Components of a C Program
Exercises 3
Storing Data: Variables and Constants
Exercises 4
Statements, Expressions, and Operators
Exercises 5
Functions: The Basics
Exercises 6
Basic Program Control
Exercises 7
Fundamentals of Input and Output
Exercises 8
Using Numeric Arrays
Exercises 9
Understanding Variable Scope
The exercises are available on the blog
Biekcomputercience.blogspot.com
Page 153 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER FORTEEN
TEST PAPERS
14
FOR PREPARATION
OBJECTIVE:
When you have solved these papers you will be able
appear in the final examination with a remarkable
preparation
Question Papers
Grand Test Paper
Silver Test for MS-Access
Golden Test of C Language
Page 154 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 155 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
a. %d
b. %c
c. %s
d. %cc
Section ‘B’
Q2.
What are MS-Access objects? Explain any five in detail.
05
OR
Write down the steps involved in programming
Q3.
Define any five of the following
05
1. Algorithm
2. Format Specifier
3. Header File
4. Flow Chart
5. Modulus Operator
6. Variable
7. Preprocessor Directive
8. Address Operator
9. Comment
10. Library Function
Page 156 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Q4.
Convert the following equations into C equivalent.
04
i. Z=p2+q2+t2+pq+qt+pt
ii. X=2(a2+b2)
iii. F=pq/p+q
Q5
Explain any three of the following with examples.
06
1. Data types of C
2. Escape Sequence
3. Keywords of C
4. Unformatted I/O functions
5. Control Structures
6. IDE
Section ‘C’
Q6.
(a) Explain diagrammatically the structure of a C program 05
OR
What are MS-Access database? Explain any five in detail.
(b) Write the program take input for a number and calculate the factorial of
that number. 05
OR
Write a program, take input in three numbers and find the greatest among
them
Q7.
(a) How many types of loops are there in C language? Explain each of them
with example codes. 06
OR
Write down the procedure of creating a user defined function in detail.
Page 157 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Q8.
(a)How many types of operators are there in C? Describe relational and
logical operators with example codes. 05
OR
Differentiate
j. Switch and if statement
k. DBMS and RDBMS
l. Break and Continue
(b). Write a program using nested for loop that prints the following series.
05
1 1 1 4 3 9 -----------------10 100
OR
Write a program using for loop to print the following output. Also write
comments.
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
Q9
(a) What is a database model explain relational database model in detail.
05
OR
How many types of relationships can be defined in a data base explain each
with example.
(b) Write a program that takes input for a number in variable M and find the
square, cube and square root of that number and print results. 05
OR
Write a program to solve the quadratic equation using quadratic formula.
Page 158 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
vi. A key which can uniquely identify each record in a table is called
*Super key *Foreign Key *Candidate Key *None of them
vii. A table is a collection of
*Fields and Records *File and Records
*Fields and Relations *Records and Relation
viii. The collection of rows and columns is called
*File *Table *Record *Database
ix. Which one is an access data type
*char *float *number *long
x. Which one is an MS- Access object?
*Macro *Report *Pages *All
xi. A property or characteristic of an entity having some value is
called
*Column *Attribute *Field *All
xii. Which one is a component of a database management system.
*Data dictionary *Utilities *Query language *All
xiii. ERD stands for
*entity relationship diagram *example relationship diagram
*entity ray diagram *example ray diagram
xiv. Which one is not an example of a database management
system?
*Excel *dbase *SQL server *Access
xv. Rules and regulations which are applied on a table are called
*logics *query language *constraints *none
xvi. Normally how many characters can be stored using text data
type?
*512 *1024 *255 *100
xvii. Which data type is used to for the fields which carry numeric
data?
*Date/Time *Number *Text *OLE
Page 159 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Note: Attempt any six questions from this section. The answer must
not exceed 8 to 10 lines. All questions carry equal marks. (36)
Q11.
(a) What are MS-Access objects explain any five in detail. 08
(b) Define and explain the relational database management system. 08
Q12. 08
(a) Explain MS-Access data types in detail.
(b) Describe hierarchical database management system with diagram. 08
Q13. 08
(a) What are the components of a database management system? Describe
in detail.
(b) Write Procedure to create a database in MS-Access of Bank Accounts.
08
1) Create two tables and create relationship b/w tables
Acct_ID ,Acct_Name, Acct_Address, Acct_Phone, Acct_Email
2) Required fields of 2nd table are
Acct_ID, Acct_Status.
3) Search the Desired Acct_ID, Delete the Desired Acct_ID
Also update desired Acct-ID.
Page 160 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Page 161 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
18. A variable which is defined out of main function but not in any
other function is called
*Local Variable *Counter Variable *Global Variable *Operating
Variable
19. The process of writing program instructions is called
*Designing *Coding *Compiling *Running
20. loop uses post testing.
*for() *while() *do while() * None
21. Which of the following is an example of initializing a character
variable?
* int i=‟a‟; *char ch=‟a‟; *ch=‟a‟; char ch=a;
22. Which Header file is used for string functions?
*string.h iostream.h *stdio.h *conio.h
23. In C language the library files are also called
*header files *object files *source files
*Exe files
24. Which one is not a valid variable name?
*const *2ND *my age *All
25. Which escape sequence is used for back space?
*\x *\a *\n *\b
26. The C language was developed by
*Peter Norton * Dennis Ritchie *Robert Lafore *Yashwanth
Kenethkar
27. The step by step process to solve a problem is called
*Flow Chart *Program *Algorithm *Software
28. A C language Source Code File cannot be run without
Function
*main() *clrscr() *getch() *printf()
29. Which one is not a C language data type?
*char *int *float *string
30. A single line C statement is terminated by
*Colon *Semicolon *Comma *Full Stop
Note: Attempt any eight questions from this section. The answer
must not exceed 8 to 10 lines. All questions carry equal marks. (32)
Page 162 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
Q6. Describe any three C language data types with their ranges, format
specifier and example program. 04
Q7. Define the following terms of C language. 04
1. User Defined Function 2. Format Specifier 3. Control
Structures Logical Operators
Q8. What do you know about C language? Describe the IDE of C. 04
Q9.Describe the control structures of C language. 04
Q10. Define algorithm. Write its characteristics. 04
Q11. How many types of C language file are there? Describe briefly. 04
Q.12 Convert the following equations in C. (Only Write Equations)
04
H=(abc+a3b2c+2ab)/3xy P=a3+b3+3ab+√xy
D=(a2+b2)/2ab Z= Ax2+Bxy+Sinx
Q11.
(a) Write a program to calculate pay roll of an employee. Read the basic pay
from keyboard, calculate medical allowance as 15% of basic pay,
conveyance allowance as 20%, and house rent allowance as 45% of basic
pay. Calculate gross pay and net pay and print all. 05
(b) Write a program that calculates power of base without using power
function by taking input both. 05
(c) Write output for the following program. 04
void main()
{
int a,x,y,m=4,n=1;
clrscr();
for(y=0;y<=4;y++)
{
for(x=1;x<=m;x++)
{
printf(" ");
}
for(a=1;a<=n;a++)
printf("*");
n=n+2;
m--;
printf("\n");
}
Page 163 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
getch();
}
Q12.
(a) Explain iterative control structures of C in detail. 08
(b) Write a program using nested loop which prints the following output.
06
1 2 3 4 5
1 2 2 4
1 2 3
1 2
1
Q13.
(a) Write a program using for loop to print usual printing characters
corresponding to 32 to 127 ASCII code. 05
(b) Find errors and write the correct program. 05
(c) Write output for the following program. 04
void main ()
{
int p, d, isPrime;
clrscr();
for(p=1;p<=30;++p)
{
isPrime=1;
for(d=2;d<p;++d)
if(p%d==0)
isPrime=0;
if (isPrime!=0)
printf ("\n%d\t%d\t%d ", p,p*p,p*p*p);
}
getch();
}
Page 164 V: 03
Muhammad Uwais BIT-MCS (KU)
Computer Science XII 2015-2016
CHAPTER FIFTEEN
15
MULTIPLE CHOICE
QUESTIONS
OBJECTIVE:
When you have completed this chapter, you will
command to answer the multiple
choice questions
Page 165 V: 03