Xii CS Practice File
Xii CS Practice File
PRACTICAL FILE
NAME: _________________________________
CLASS: ____________________________________
SUBJECT: ____________________________________
CERTIFICATE
Certified that Mr./Ms.__________________________________
S/O D/O_____________________________________________
Of class _____________________ subject Computer Science
___________________ ________
Head of the department In charge
INDEX
S-NO PRACTICAL DATE SIGN
C-PROGRAMMING
01 Write a program to read the 001marks of 5 subjects calculate the total
marks, percentage and state whether he is pass or fail and then print it
02 Write a program to generate the multiplication table of N
03 Find the factorial of a number n, read value of n using scanf and print the
factorial of n
04 Write a program to input three numbers and print the greater one
05 Write a program that input a number and then check it whether it is
prime or not
06 Write a program that input a year and then check whether it is a leap
year or not
07 Write a program using for loop to print usual printing characters
corresponding to 32 to 127 ASCII Code
08 Write a program which uses a switch and break statement
09 Write a program using nested for loop to print the following output
*
**
***
****
*****
10 Write a program that reads and prints the data using escape sequence (
asking the name, age, height and gender of student using scanf and
printf statement)
11 Write a program which uses airthematic operators to calculate the area
of triangle and volume of sphere
12 Write a program that input any two number and then pass these
numbers as arguments a function sum1 and then print their sum
13 Write a program which print a text of four line consisting of character,
integer value and floating-point value using printf() statement and
escape sequence.
14 Write a program to compute roots of quadratic equation ax2+b+c=0
using quadratic formula
15 Write a program that calculates power of base without using power
function by taking input both
DATA BASE
01 Create a database in MS-Access of Bank Account
02 Create a database in MS-Access of library
03 Create a database in MS-Access of student information
04 Create a database in MS-Access of student result
05 Create a database in MS-Access of student attendance
06 Create a database in MS-Access of hospital
PRACTICAL 01:
Object:01 Write a program to read the marks of five subjects calculate
the total marks, percentage and state whether he/she is pass or fail then
print it.
Algorithm:01
Source Code:
#include<stdio.h>
int main(void)
{
int n=5, count=1;
float total, percentage, grand_total=0, max_marks, marks, sum=0;
while(count<=n)
{
printf("marks obtained in subject %d\t=",count);
scanf("%f",&marks);
while(marks<0 || marks>100)
{
printf("invalid marks, try again:");
scanf("%f",&marks);
}
printf("total marks in subject %d\t=",count);
scanf("%f",&max_marks); if(max_marks<0 ||
max_marks>100)
{
printf("invalid total marks, try again:");
scanf("%f",&max_marks);
}
sum+=marks;
grand_total+=max_marks;
++count;
}
total=sum;
percentage = total/grand_total*100;
printf("\nYour total marks are = \t% of out of = \t%of", total, grand_total);
printf("\nyour percentage is = \t%2f%",percentage); if(percentage<33)
{
printf("\n\t you have failed");
}
else
{
printf("\n\t congratulations you are passed");
}
getch();
}
OUTPUT:
marks obtained in subject 1 =30 total
marks in subject 1 =100 marks
obtained in subject 2 =40 total
marks in subject 2 =100 marks
obtained in subject 3 =30 total
marks in subject 3 =100 marks
obtained in subject 4 =70 total
marks in subject 4 =100 marks
obtained in subject 5 =90
total marks in subject 5 =100
Object:
Write a program to generate the multiplication table of N.
Algorithm no: 02 FLOW CHART
1. set the variables
2. read num
3. write message
{ Read n
{ power=num*i;
Write num,i,power
printf("\n %d\tx\t%d\t=\t%d",num,i,power);
getch(); i=i+1
}
Stop
OUTPUT:
Enter The Number of Table: 6
PRACTICAL NO : 03
Object:03 Find the factorial of a number n, read value of n using scanf, and print the factorial of n
Algorithm:03
1. Set factorial = 1 FLOW CHART
2. Read num
3. IF n>= 0 then goto Step 4
4. ELSE S Start
5. Write Factorial cannot be done
6. Repeat FOR i <= num
a. factorial = factorial x i Factorial = 1
7. End of FOR loop i = 1, j = 0,
8. Write factorial k = 0, num = 0
9. Exit
Source Code:
#include <stdio.h>
Read num
if (num >= 0) {
Yes
for (int i = 1; i <= num; i++) {
factorial = factorial * i;
} If i<=num?
printf("\nThe Factorial of %.0f is %.0f", num, factorial);
} else {
Yes
printf("\nThe Factorial Cannot be done for This no: %.0f", num);
}
Factorial = factorial * i
return 0;
}
i=i+1
Write
factorial
Write
error
Stop
Output:
Enter The Number To Get The Factorial: 9
no
Return 1st no
If 1st no is greater
than 1st and 3rd no?
yes
no Return 2nd no
If 3rd no is greater
than1st and 2nd no?
yes
no Return 3rd no
Output: stop
Enter the First No:
30
Enter the Second No:
60
Enter the Third No:
1
2 Read number
3. IF num <= 1 then Write message
Yes
4. Else check if num > 5 then 5. Set i= num%2 j=
num%3 k = num%5 If num <= 1?
6. if I,j and k are not equal to 0 then
7. Write Message
No
8. Else check if num is not equal to 4 then Write Message
9. Else write Error Message
10. Exit
No
Source Code: If num > 5
#include <stdio.h> #include<stdlib.h>
int main(void)
yes
{
int num,i,j,k;
printf("Enter A Natural Number\n");
i = num %2 No
scanf("%d",&num); If i is not equals
j = num %3 to 4
if(num<=1) k = num % 5
{
printf("\n This Number %d is not a Prime Number", num);
Yes
exit(0); }else{ if(num>5)
{ No
If i , j, and k are
i=num%2; j=num%3; k=num%5;
not equal to 0
if(i!=0 && j!=0 && k!=0)
{
printf("\nThis Number %d is a Prime Number", num);
yes
}
else printf("\n This Number %d is not a Prime Number", Write it’s a
num); prime number
}
else if(num!=4) Write its not
{ A prime no
Output:
Enter A Natural Number
88
This Number 88 is not a Prime Number
PRACTICAL NO : 06
Object:06
Write a program that input a year an then check whether it is a leap
year or not.
Start
Algorithm:06
1. Set i , year , and leap year
FLOW CHART
2. Read year i=0
3. Take the remainder of year from 4 and assign to year = 0
leap leap = 0
4. If leap is equal to 0
5. Write it’s a leap year
6. Else write is not a leap year
7. exit Source Code: #include <stdio.h> Read year
int main(void)
{
int i,year,leap; printf("\nEnter the year: "); scanf("%d",&year);
leap=year%4; Leap = year % 4
if(leap==0)
{
printf("\n The year %d you entered is a leap year", year);
}
else If leap == 0 Write its not
{ a leap year
printf("\n The year %d you entered is not a leap year", year);
}
}
Output:
Write it’s a leap
Enter A Natural Number
year
88
Stop
Output:
Enter A Natural Number
88
Stop
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=⌂
PRACTICAL NO : 08
Object:08
Write a program which uses a witch statement and break statement
Algorithm:08
1. Read the ticket no
FLOW CHART
2. Read the switch variable Start
3. IF switch variable = 122
Write you have won the first prize
IF switch variable = 456 Read ticket
Write you have won the second prize no
IF switch variable = 122
Write you have won the third prize
4. ELSE Write Sorry! Better try next time
5. Exit Write you have
Case 122 won 1st prize
Source Code: #include <stdio.h>
int main(void)
{
int ticket_no;
printf("\n Enter The Ticket Number: ");
Write you have
scanf("%d", &ticket_no);
Case 456 won 2nd prize
switch(ticket_no)
{
case 122: printf("\n You Have Won The First
Prize."); break; case 456: printf("\n You
Have Won The Second Prize."); break; case
16: printf("\n You Have Won The Third Write you have
Prize."); break; default: Case 16 won 3rd prize
printf("\n Sorry!! Better Try Next Time.");
}
}
stop
Output:
Enter The Ticket Number: 456
j += 1
i += 1
Stop
Output:
*
**
***
****
***** PRACTICAL NO : 10
Object10:
Write a program that reads and prints the data using escape sequence (asking the name, age, height and gender of student
using scanf and print statement) Algorithm:10
1. Read gender FLOW CHART
2. Read name
Name: AHMED
Age: 27
Height: 5.60
Gender: M
PRACTICAL NO
: 11
Object:11
Write a program which uses airthematic operators to calculate the area of the triangle and volume of sphere.
Algorithm:11
FLOW CHART
1. Start
2. Set global variable pi
3. Set local variables Start
4. Read height and base of a triangle
5. Read radius of a Sphere
6. Calculate area by means of formula ½ bh Set pi = 3.1415927
7. Calculate volume by using formula = 4/3 πr³
8. Write Area of Triangle and Volume of Sphere
9. Exit Read height and base of a
Source Code: triangle and radius of sphere
#include <stdio.h>
#include <math.h>
int main(void) {
float area, volume, height, base, radius;
return 0;
}
int sum1(int x, int y) { int sum = 0; sum = x + y; return sum; Read two
} numbers
Stop
Sum = x + y
Sum = x + y
Return Sum
Enter a character: a
Enter an integer: 12
Character: a
String: GUARD PUBLIC COLLEGE
Integer: 12
Floating No: 12.22
PRACTICAL NO : 14
Object:14
Write a program to compute roots of quadratic equations a x 2 + b + c = 0 using quadratic formula.
Algorithm:14
1. Set root1 = 0 root2 = 0
2. Read a FLOW CHART
3. Read b
Start
4. Read c
5. Call Built-in function square root
a. d = sqrt (b xb-4xaxc)
Root 1 = 0
b. root1 = (-b-d) / (2 x a)
c. root2 = (-b + d) / (2 x a) Root 2 = 0
6. Write two roots
7. Exit
Source Code:
#include <stdio.h> Read a, b, c
#include <math.h>
int main(void) {
float a, b, c, d, root1 = 0, root2 = 0;
if (d >= 0) {
Write first root and second
root1 = (-b - sqrt(d)) / (2 * a); root
root2 = (-b + sqrt(d)) / (2 * a);
int main(void) {
float num, pow, power, i; Read pow
power = 1;
Stop
Steps:
1. firstly, go to the search bar and write Access , click on it and it will be open for you.
2. Then click on blank database, write your file name namely BANK ACCOUNTS, save it on your desktop and click on
create.
3. You can see that there is a column on the left side namely, “ All Access objects” there is a drop-down button click on it,
select table object.
4. Now, there is a header above the page, on that header you can see a option namely “View” with a drop down button,
click on that drop down button and select design view.
5. Now in design view there are two columns one is “ fields” and second one is “ data type” 6. Write the fields and data
types which are given below:
1. firstly, go to the search bar and write Access , click on it and it will be open for you.
2. Then click on blank database, write your file name namely LIBRARY , save it on your desktop and click on create.
3. You can see that there is a column on the left side namely, “ All Access objects” there is a drop-down button click on it,
select table object.
4. Now, there is a header above the page, on that header you can see a option namely “View” with a drop down button, click
on that drop down button and select design view.
5. Now in design view there are two columns one is “ fields” and second one is “ data type” 6. Write the fields and data types
which are given below: Table: library
Field Name Data type
book_ID Number
book_Name Text
book_status Text
7. Save that table by clicking right button on the table header and name that table “ library ” Set book_ID field as a primary
key ( if its not already done)
8. After making the table, go to the create option, you’ll see a option namely “Query design” click on it, and your query will
be made.
9. Now, you can see a column on the right side namely “add tables” add your table by clicking on the “add selected table”
button.
10. After selecting table, click on every field in the table which is required. Save it and name it “ Qry_Books_available_list”
11. Create the second query in the same fashion as the first one but set true as a criteria on status field close it and named it
“Qry_Issued_List”.
12. Now select the option “RUN” on every query and see the results.
Output:
1. firstly, go to the search bar and write Access , click on it and it will be open for you.
2. Then click on blank database, write your file name namely STUDENT INFORMATION , save it on your desktop and click on
create.
3. You can see that there is a column on the left side namely, “ All Access objects” there is a drop-down button click on it,
select table object.
4. Now, there is a header above the page, on that header you can see a option namely “View” with a drop down button,
click on that drop down button and select design view.
5. Now in design view there are two columns one is “ fields” and second one is “ data type” 6. Write the fields and data
types which are given below: Table: Student_Information
Field Name Data type
Stud_ID Number
Stud_Name Text
Stud_Class Text
Stud_Group Text
Stud_gender Text
7. Save that table by clicking right button on the table header and name that table “ Student_Information ” Set book_ID field
as a primary key ( if its not already done)
8. After making the table, go to the create option, you’ll see a option namely “Query design” click on it, and your query will
be made.
9. Now, you can see a column on the right side namely “add tables” add your table by clicking on the “add selected table”
button.
10. After selecting table, click on every field in the table which is required and set “pre_medical” as a criteria on group field
and female on gender field, Save it and name it “ Qry_PE_Female_list”
11. Create the second query in the same fashion as the first one but set “pre_Engineering” as a criteria on group field and
male on gender field, close it and named it “Qry_PE_Male_List”.
12. Now select the option “RUN” on every query and see the results.
OUTPUT:
1. firstly, go to the search bar and write Access , click on it and it will be open for you.
2. Then click on blank database, write your file name namely STUDENT RESULT , save it on your desktop and click on create.
3. You can see that there is a column on the left side namely, “ All Access objects” there is a drop-down button click on it,
select table object.
4. Now, there is a header above the page, on that header you can see a option namely “View” with a drop down button,
click on that drop down button and select design view.
5. Now in design view there are two columns one is “ fields” and second one is “ data type” 6. Write the fields and data
types which are given below: Table: Result
Field Name Data type
Stud_ID Number
Stud_Name Text
Stud_Marks Number
7. Save that table by clicking right button on the table header and name that table “ Result ” Set book_ID field as a primary
key ( if its not already done)
8. After making the table, go to the create option, you’ll see a option namely “Query design” click on it, and your query will
be made.
9. Now, you can see a column on the right side namely “add tables” add your table by clicking on the “add selected table”
button.
10. After selecting table, click on every field in the table which is required ,Save it and name it “ Qry_All”
11. Create the second query in the same fashion as the first one but set “Stud_Marks ” field as a Descending Order Close it
and named it “Qry_Marks_Des”.
12. Now select the option “RUN” on every query and see the results.
OUTPUT:
Database Practical no: 05
Object: procedure for creating database of student attendance.
Steps:
1. firstly, go to the search bar and write Access , click on it and it will be open for you.
2. Then click on blank database, write your file name namely STUDENT ATTENDANCE, save it on your desktop and click on
create.
3. You can see that there is a column on the left side namely, “ All Access objects” there is a drop-down button click on it,
select table object.
4. Now, there is a header above the page, on that header you can see a option namely “View” with a drop down button, click
on that drop down button and select design view.
5. Now in design view there are two columns one is “ fields” and second one is “ data type” 6. Write the fields and data types
which are given below: Table: student_info
Field Name Data type
Stud_ID Number
Stud_Name Text
Stud_Address Text
Stud_phone Number
Stud_Email Text
7. Save that table by clicking right button on the table header and name that table “ Student_Info”
8. Now make another table by clicking “create” in the header file, you’ll see an option namely table, click on it and table will be
created.
9. Now go to the “view” option in the header, click on its drop-down button and go to the design view.
10. Write the fields and data types which are given below. Table: Student_Attendance
Field Name Data type
Stud_ID Number
Stud_Attendance Text
11. Save that table by name “ Student_Attendance”
12. Set Acct_id field as a primary key ( if its not already done)
13. Go to the database tools option, you’ll see an option namely “Relationship” clicks on it and it will create.
14. Now in relationship tab, you can see a column in the right side namely “ Add tables”, and below you can see your both table
which are “Student_info” and “Student_Attendance” select both by clicking on the “Add selected table” button.
15. Now go to the relationship design option which is in the header, in that option you’ll see the option namely “Edit
Relationships” click on it.
16. When you click on it, a prompt will be appeared, click on create new, choose “Table1” in left table name and “Table2” in
right table name. choose “ID” in left and right column name, and then click on create button in the prompt and your
relationship will be established.
17. After making the tables and the relationships, go to the create option, you’ll see a option namely “Query design” click on it,
and your query will be made.
18. Now, you can see a column on the right side namely “add tables” add your both tables by clicking on the “add selected
table” button.
19. After selecting tables, button click on every field in both tables which are required. Save it and name it “ Qry_Std_Search”
20. Than created the second query just like the first one, but in that query select only one table namely “Student_info”, select
every field and than select update from query type and update “Stud_ID” of an Acct_Id. Close it and name it
“Qry_Update_StdId”.
21. Create the third query just like the 1st and 2nd one but selected delete query from Query type. Set the criteria and named it
“Qry_delete_Std”
22. Now select the option “RUN” on every query and see the results.
OUTPUT:
Qry_Std_Search
Qry_Update_StdId After
delete:
Qry_Delete_Std
After delete and update:
Database Practical no: 06
Steps:
1. firstly, go to the search bar and write Access , click on it and it will be open for you.
2. Then click on blank database, write your file name namely HOSPITAL , save it on your desktop and click on create.
3. You can see that there is a column on the left side namely, “ All Access objects” there is a drop-down button click on it,
select table object.
4. Now, there is a header above the page, on that header you can see a option namely “View” with a drop down button, click
on that drop down button and select design view.
5. Now in design view there are two columns one is “ fields” and second one is “ data type” 6. Write the fields and data types
which are given below:
Table: patient
Field Name Data type___
patient_ID Number
patient _Name Text patient _Address
Text
patient _doctor Number
admit_card Text
Discharge_status Yes/No
Discharge_Date Text
Charges Number
7. Save that table by clicking right button on the table header and name that table “ patient”
8. Now make another table by clicking “create” in the header file, you’ll see an option namely table, click on it and table will be
created.
9. Now go to the “view” option in the header, click on its drop-down button and go to the design view.
10. Write the fields and data types which are given below.
Table: Status
Field Name Data type___
patient _ID Number
Date Text
Doctor Text
Test_Report Text
Prescription Text
Disease Text
11. Save that table by name “ Status”
12. Set patient_ID field as a primary key ( if its not already done)
13. Go to the database tools option, you’ll see an option namely “Relationship” clicks on it and it will create.
14. Now in relationship tab, you can see a column in the right side namely “ Add tables”, and below you can see your both table
which are “Student_info” and “Student_Attendance” select both by clicking on the “Add selected table” button.
15. Now go to the relationship design option which is in the header, in that option you’ll see the option namely “Edit
Relationships” click on it.
16. When you click on it, a prompt will be appeared, click on create new, choose “patient” in left table name and “status” in
right table name. choose “ID” in left and right column name, and then click on create button in the prompt and your
relationship will be established.
17. After making the tables and the relationships, go to the create option, you’ll see a option namely “Query design” click on it,
and your query will be made.
18. Now, you can see a column on the right side namely “add tables” add your patient table by clicking on the “add selected
table” button.
19. After selecting tables, button click on every field in the table which are required and set Muhammad Faizan as a doctor.
Save it and name it “ Qry_DrMF”
20. Than created the second query just like the first one, but in that query select only one table namely “Status”, select every
field and than select update from query type and update prescription and set “patient_ID” to K100. Close it and name it
“Qry_Update_Prescription”.
21. Create the third query just like the 1st and 2nd one but selected delete query from Query type. Set the criteria and named it
“Qry_delete_Std”
22. Now select the option “RUN” on every query and see the results. OUTPUT:
Simple view: