Xii Comp Practical Journal
Xii Comp Practical Journal
PRACTICAL JOURNAL
FOR CLASS XII
PROGRAMMING IN C & MS ACCESS
Name: ____________________
Group: ____________________
Roll No.___________________
Roll No. _______________________ has carried out all practical work as prescribed
2 Writing a Program that Reads & Prints the Data Using Escape Sequence
(Asking the Name, Age, Height and Gender of Student Using scanf and
printf Functions).
3 Writing a Program that Uses Operators (Calculate the Area of Triangle,
Volume of Sphere and Arrange The Resultant Values in Ascending Order).
4 Writing a Program that Uses ‘For’ Loop Statement. (Generate the
Multiplication Tables from 2 To 20).
5-A Writing a Program that Uses While Loop and Nested While Loop
• First While Loop Takes the Marks of each Individual Subject One
by One
• Second While Loop Validates the Marks Entered by the User and
Prompts the User to Input Correct Marks i.e. between 0 and 100
Unless User has Entered Correct Value of Marks
• Finally the Program Calculates the Average Marks of All Subjects
5-B Writing a Program that Uses For Loop and While Loop Inside For Loop to
Calculate Average Marks of Student:
Writing a Program that Uses While Loop and Nested While Loop
• The For Loop Takes the Marks of each Individual Subject One by
One
• Second While Loop Validates the Marks Entered by User and
Prompts User to Input Correct Marks i.e. Between 0 and 100
Unless User has Entered Correct Value of Marks
• Finally the Program Calculates the Average Marks of All Subjects
6 Writing a Program to Find the Factorial of Integer n Using ‘While’ Loop.
The Program Should Read the Value of n Using scanf and Print the
Factorial Using printf.
7-A Writing a Program to Draw Check-Board, the Program Should Use Nested
For Loops and If-Else Statement in Inner For Loop to Print the Result.
7-B Writing A Program to Calculate Fibonacci Series of Integer n Entered By
the User.
Note: Fibonacci Series is Defined as A Sequence of Numbers in Which the
First Two Numbers are 1 and 1, Or 0 and 1, Depending on the Selected
Beginning Point of the Sequence, and Each Subsequent Number is the
Sum of the Previous Two.
8 Writing a Program Which Uses a Switch Statement and Breaks the
Program if Certain Condition is Observed i.e. Writing a Program Which
Uses a Switch, Case And Break Statements and Interconvert the
Temperature Scales Using Menu Options.
9 Writing a Function that Generates Factorial of an Integer n and Calls this
Function in the ‘Main’ Program.
10 Writing a Program Which Uses Multiple Arguments in a Function.
(Develop a User-Defined Function to Generate a Rectangle. Use The
Function for Passing Arguments to Draw Different Sizes of Rectangles and
Squares).
MS ACCESS
01 Create database of student information
(ST_ID,NAME,CLASS, GROUP,SEX)
1. Create St_Id as primary key.
2. Input ten records.
Queries:
• Find the list of female students.
• Find the list of student.
02 Create database of library (Book_Id, name, reference or lending book
issued).
1. Create a suitable PK
2. input 10 records with difference names
Queries:
• Display list of books which are not for lending.
• Find list of books issued.
03 Create A Database In MS-Access Of Bank Accounts. Create 2 Tables,
Relationship B/W Tables.
PROGRAMMING - C
PRACTICALS
Page 2 of 41
Practical Journal Computer Science - XII
Practical 1
Algorithm
Flowchart
Start
Write
character, string, integer,
floating point number
Stop
Source Code
#include<conio.h>
#include<stdio.h>
int main(void)
{
char ch = 'A', str[] = "My College";
int num = 2;
float fnum = 12.47;
return 0;
}
Output
Page 3 of 41
Practical Journal Computer Science - XII
Practical 2
Writing a Program that Reads & Prints the Data Using Escape Sequence
(Asking the Name, Age, Height and Gender of Student Using scanf and printf
Functions).
Algorithm
Step 6. Read gender.
Step 7. Read name.
Step 8. Read age.
Step 9. Read height.
Flowchart Start
Read
gender, name, age,
height
Write
name, age, height,
gender
Stop
Source Code
#include<conio.h>
#include<stdio.h>
int main(void)
{
char gender, name[25];
int age;
float height;
return 0;
}
Output
Page 5 of 41
Practical Journal Computer Science - XII
Practical 3
Algorithm
1. Read a, b, r, t, s.
1
2. Set Area of Triangle t = a b.
2
4
Area of Sphere s = r 3 .
3
3. IF t < s, then
Write t, s.
ELSE
Write s, t.
[End of IF-ELSE structure.]
4. Exit.
Flowchart
Start
Read
a, b, r, t, s
1
Area of Triangle t = a b
2
4 3
Area of Sphere s = r
3
No
If t < s?
Yes
Write t, s Write s, t
Stop
Page 6 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define pi 3.1415927
int main(void)
{
float a, b, r, t, s;
printf("\n\n\t\tEnter the value for Altitude of a Triangle. ");
scanf("%f", &a);
printf("\n\n\t\tEnter the value for Base of a Triangle. ");
scanf("%f", &b);
printf("\n\n\t\tEnter the value for Radius of a Sphere. ");
scanf("%f", &r);
t=(1.0/2.0)*(a*b);
s=(4.0/3.0)*pi*pow(r,3);
if (t<s)
{
printf("\n\n\t\tArea of Triangle = %.2f",t);
printf("\n\n\t\tArea of Sphere = %.2f",s);
}
else
{
printf("\n\n\t\tArea of Sphere = %.2f",s);
printf("\n\n\t\tArea of Triangle = %.2f",t);
}
return 0;
}
Output
Page 7 of 41
Practical Journal Computer Science - XII
Practical 4
Writing a Program that Uses ‘For’ Loop Statement to Generate the
Multiplication Tables from 2 To 20.
Algorithm
Flowchart
No
If i<=10?
Start
Yes
j=ni
j=0
Write j
Read n
i=i+1
If n>=2 and No
A
n<=20?
A
Yes
Stop
Page 8 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
int main (void)
{
int i,n,j=0;
printf("\n\t\tEnter Table No. ");
scanf("%d",&n);
return 0;
}
Output
Page 9 of 41
Practical Journal Computer Science - XII
Practical 5(a)
Writing a Program that Uses While Loop and Nested While Loop
• First While Loop Takes the Marks of each Individual Subject One by
One
• Second While Loop Validates the Marks Entered by User and
Prompts User to Input Correct Marks i.e. Between 0 and 100 Unless
User has Entered Correct Value of Marks
• Finally the Program Calculates the Average Marks of All Subjects
Algorithm
Step 21. Set count = 1 and sum = 0.
Step 22. Read n. [number of subjects.]
Step 23. Repeat WHILE count n
a. Read marks of n subjects.
b. Repeat WHILE marks are < 0 or > 100
i. Write Invalid marks, try again.
ii. Read marks.
[End of inner WHILE loop.]
c. sum = sum + marks.
d. count = count + 1.
[End of outer WHILE loop.]
Step 24. average = sum/n.
Step 25. Write average.
Step 26. Exit.
Page 10 of 41
Practical Journal Computer Science - XII
Flowchart Start
count=1, sum=0
Read n
If countn? No
Yes
Read
marks of n subjects
If
marks<0 or marks>100? No
Yes
Write
Invalid marks, try again
Read marks
sum=sum+marks
count=count+1
average=sum/n
Write average
Stop
Page 11 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n, count = 1;
float marks, average, sum = 0;
// initialise and read in a value for n
printf("How many Subjects? ");
scanf("%d", &n);
printf("\n");
// read marks
while(count <= n)
{
printf("Marks in Subject %d = ", count);
scanf("%f", &marks);
while(marks < 0 ¦¦ marks > 100)
{
printf("Invalid marks, try again: ");
scanf("%f", &marks);
}
sum += marks;
++count;
}
// calculate the average and print the answer
average = sum/n;
printf("\nThe average marks are = %f", average);
return 0;
}
Output
Page 12 of 41
Practical Journal Computer Science - XII
Practical 5(b)
Writing a Program that Uses For Loop and While Loop Inside For Loop to
Calculate Average Marks of Student:
Writing a Program that Uses While Loop and Nested While Loop
• The For Loop Takes the Marks of each Individual Subject One by One
• Second While Loop Validates the Marks Entered by User and
Prompts User to Input Correct Marks i.e. Between 0 and 100 Unless
User has Entered Correct Value of Marks
• Finally the Program Calculates the Average Marks of All Subjects
Algorithm
Flowchart
Start
sum=0
Read n
count=1
average=sum/n
If countn? No
1
Yes
If
marks<0 or marks>100? No
Stop
Yes
Write
Invalid marks, try again
Read marks
sum=sum+marks
count=count+1
Page 14 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n, count;
float marks, average, sum = 0;
// initialise and read in a value for n
printf("How many Subjects? ");
scanf("%d", &n);
printf("\n");
// read marks
for(count =1; count <= n; count++)
{
printf("Marks in Subject %d = ", count);
scanf("%f", &marks);
while(marks < 0 ¦¦ marks > 100)
{
printf("Invalid marks, try again: ");
scanf("%f", &marks);
}
sum += marks;
}
// calculate the average and print the answer
average = sum/n;
printf("\nThe average marks are = %f", average);
return 0;
}
Output
Page 15 of 41
Practical Journal Computer Science - XII
Practical 6
Writing a Program to Find the Factorial of Integer n Using ‘While’ Loop. The
Program Should Read the Value of n Using scanf and Print the Factorial
Using printf.
Algorithm
Step 33. Set f = 1 and i = 1.
Step 34. Read num.
Step 35. IF num 0 then goto Step 4.
ELSE goto Step 6.
Step 36. Repeat WHILE i num
h. f = f * i.
i. i = i + 1.
Step 37. Write f.
Step 38. ELSE
Write Sorry!!
Step 39. Exit.
Start
Flowchart
f = 1, i = 1
Read num
No
If num0?
Yes
Write
If inum? Sorry!!
Yes
f=f*i
i=i+1
Write f
Stop
Page 16 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
int main(void)
{
double f=1;
int num, i;
if (num>=0)
{
i = 1;
while (i<=num)
{
f=f*i;
i++;
}
printf("\n\n\n\t\tThe factorial of %d is %lf", num, f);
}
else
printf("\n\n\n\t\t Sorry!!");
return 0;
}
Output
Page 17 of 41
Practical Journal Computer Science - XII
Practical 7(a)
Writing a Program to Draw Check-Board, the Program Should Use Nested
For Loops and If-Else Statement in Inner For Loop to Print the Result.
Algorithm
Flowchart
Start
Read a, b
b=1
No
If b<12? Stop
Yes
a=1
No
If a<12?
Yes
If (a+b)(mod2)=0?
No
Yes
a=a+1
Write new
line
b=b+1
Page 19 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
int main (void)
{
int a, b;
return 0;
}
Output
Page 20 of 41
Practical Journal Computer Science - XII
Practical 7(b)
Writing A Program to Calculate Fibonacci Series of Integer n Entered By the
User.
Note: Fibonacci Series is Defined as A Sequence of Numbers in Which the
First Two Numbers are 1 and 1, Or 0 and 1, Depending on the Selected
Beginning Point of the Sequence, and Each Subsequent Number is the Sum
of the Previous Two.
Algorithm
Step 1. Start
Step 2. Declare variables i, a,b , show
Step 3. Initialize the variables, a=0, b=1, and show =0
Step 4. Enter the number of terms of Fibonacci series to be printed
Step 5. Print First two terms of series
Step 6. Use loop for the following steps
show=a+b
a=b
b=show
increase value of i each time by 1
print the value of show
Step 7. End
Page 21 of 41
Practical Journal Computer Science - XII
if n==0:
return 0
elif n==1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
Flowchart
Page 22 of 41
Practical Journal Computer Science - XII
Source Code
#include <stdio.h>
int main() {
int i, n;
// initialize first and second terms
int t1 = 0, t2 = 1;
// initialize the next term (3rd term)
int nextTerm = t1 + t2;
// get no. of terms from user
printf("Enter the number of terms: ");
scanf("%d", &n);
// print the first two terms t1 and t2
printf("Fibonacci Series: %d, %d, ", t1, t2);
// print 3rd to nth terms
for (i = 3; i <= n; ++i) {
printf("%d, ", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
Output
Page 23 of 41
Practical Journal Computer Science - XII
Practical 8
Writing a Program Which Uses a Switch Statement and Breaks the Program
if Certain Condition is Observed i.e. Writing a Program Which Uses a
Switch, Case And Break Statements and Interconvert the Temperature
Scales Using Menu Options.
Algorithm
Flowchart
Start
Read
switch variable
case 1
from Celsius to Fahrenheit Yes Read 9
Yes c f = 32 + c
5
No
case 2
from Fahrenheit to Celsius Yes Read 5
Yes f c = (f − 32)
9
No
case 3
from Celsius to Kelvin Yes Read
Yes c k = c + 273.15
No
case 4
from Fahrenheit to Kelvin Yes Read 5
Yes f k = (f − 32) + 273.15
9
No
Write
Invalid switch variable
Stop
Page 25 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int i;
float c, f, k;
printf("\n\n\n");
printf("\t\t\tMENU FOR TEMPERATURE SCALE CONVERSION");
printf("\n\t\t\t_____________________________________\n\n");
switch(i)
{
case 1:
printf("Enter temperature in Celsius: ");
scanf("%f", &c);
f = 32.0+(9.0/5.0)*c;
printf("The temperature in Fahrenheit is = %.2f", f);
break;
case 2:
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &f);
c = 5.0/9.0*(f-32.0);
printf("The temperature in Celsius is = %.2f", c);
break;
case 3:
printf("Enter temperature in Celsius: ");
scanf("%f", &c);
k = c + 273.15;
printf("The temperature in Kelvin is = %.2f", k);
break;
case 4:
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &f);
k = (5.0/9.0*(f-32.0)) + 273.15;
printf("The temperature in Kelvin is = %.2f", k);
break;
default:
printf("Invalid MENU option\n\n");
}
getch();
}
Output
Page 26 of 41
Practical Journal Computer Science - XII
Practical 9
Writing a Function that Generates Factorial of an Integer n and Calls this
Function in the ‘Main’ Program.
Algorithm
Step 1. Declare a function double factorial(int x), which accepts an integer as an argument
and returns a double value.
The Function main
Step 2. Read num.
Step 3. IF num 0, then
Call the function factorial(num) and store the value it returns in fact.
(where num is the actual argument)
Write fact.
ELSE
Write Sorry!!
[End of IF-ELSE structure.]
Step 4. Exit.
Defining the Function double factorial(int x)
(where x is the formal argument)
Step 5. Set f = 1 and i = 1.
Step 6. Repeat FOR i =1 to i x
f = f * i.
[End of FOR loop.]
Step 7. Return f.
Flowchart
Start factorial(int x)
f = 1, i = 1
Read num
No
If ix?
No
If num0?
Yes
Yes
f=f*i
fact = Write
call factorial(num) Sorry!!
i=i+1
Write fact
return(f)
Stop
Stop
Page 27 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
double factorial(int x); /* function prototype */
void main(void)
{
clrscr();
int num;
double fact;
printf("\n\n\n\t\tEnter the number to find its Factorial: ");
scanf("%d", &num);
if (num>=0)
{
fact = factorial(num);
printf("\n\n\n\t\tThe factorial of %d is %lf", num, fact);
}
else
printf("\n\n\n\t\t Sorry!!");
getch();
}
double factorial(int x) /* factorial function */
{
int i;
double f=1;
for(i=1; i<=x; i++)
f=f*i;
return(f); /* return function */
}
Output
Page 28 of 41
Practical Journal Computer Science - XII
Practical 10
Writing a Program Which Uses Multiple Arguments in a Function. (Develop
a User-Defined Function to Generate a Rectangle. Use The Function for
Passing Arguments to Draw Different Sizes of Rectangles and Squares).
Algorithm
Step 1. Declare a function void rectangle(int, int), which accepts two integer arguments
but returns no value.
The Function main
Step 2. Write Drawing room.
Step 3. Call function rectangle(6,3).
(6 and 3 are length and width of the room)
Step 4. Write Bedroom.
Step 5. Call function rectangle(8,2).
Step 6. Write Bathroom.
Step 7. Call function rectangle(2,1).
Step 8. Write Kitchen.
Step 9. Call function rectangle(4,3).
Step 10. Exit.
Defining the Function void rectangle(int length, int width)
Step 11. Repeat FOR j = 1 to j <= width
Step 12. Repeat FOR k = 1 to k <= length
Write \xDB.
(where \xDB is the code for one rectangle)
[End of inner FOR loop.]
Write new line.
[End of outer FOR loop.]
Step 13. Exit.
Page 29 of 41
Practical Journal Computer Science - XII
Flowchart
call function
rectangle(6,3) No
Stop If j<=width?
k=1
No
If k<=length?
Write Bathroom
Yes
call function
rectangle(2,1) Write
\xDB
Write Kitchen
k=k+1
call function
rectangle(4,3)
Stop
Page 30 of 41
Practical Journal Computer Science - XII
Source Code
#include<stdio.h>
#include<conio.h>
int main(void)
{
printf("\nDrawing room\n"); /* print room name */
rectangle(6,3); /* draw room */
printf("\nBedroom\n"); /* etc. */
rectangle(8,2);
printf("\nBathroom\n");
rectangle(2,1);
printf("\nKitchen\n");
rectangle(4,3);
return 0;
}
Output
Page 31 of 41
Practical Journal Computer Science - XII
MS-Access
PracticalS
Page 32 of 41
Practical Journal Computer Science - XII
Practical # 01
Creating Database
1. Click File from menu bar and click New. Click the blank Database
2. Write the file name for Database in file name Box e.g. Students.
Crating Table
Entering Fields:
1. Type St_id in first field name & press Tab key to switch to next column
with heading Data Type . A list triangle appears.
2. Click list triangle and select a data type for St_id from the list i-e text.
3. Press Tab key to go Description column of and gives comments about
the field (optional).
4. Repeat step (a) to (c) for giving other fields e.g. St- Name, St-Class, St-
Group, St-Sex.
5. Right click the field “St-id”. A context menu appears click the Primary
Key from this menu. It will set the Primary Key for St-id Field.
6. Click save button or press CTRL+S. Save as dialog box appears.
7. Type table name Table1, and click ok. Click close button.
Page 33 of 41
Practical Journal Computer Science - XII
Entering Records:
Repeat step 4 and add St_Class St_ Group, St _ Sex from Table1.
Practical # 02
Procedure
Creating database
1. Click File from menu bar and click New. Click the blank Database.
2. Write the file name for Database in file name Box e.g. Library
Creating Table
Entering Fields
a) Type book _ id in first field name & press Tab key to switch to next
column witth heading Data type. A list triangle appears
b) Click list triangle and select a data type for book _ id from the list.
c) Press tab key to go to Description column of the particular field.
(Just comments).
Repeat step (a) to (c) for given other fields e.g. Book _name, Book
reference or lending book.
5. Right click the field “Book_ id’. A context menu appears click the
primary Key from this menu. It will set the Primary Key for Book-
id field.
6. Click save button. Or press CtrI + S, save as dialog box appear.
7. Type table name Table! And click OK. Click Close button.
Page 35 of 41
Practical Journal Computer Science - XII
Enter Record
8. Click save table1 in data base window. Click view menu then Click
datasheet View. A window appears. Enter record here
9. Press CTRL+ S to save record. Click Close button.
Queries
3. Click in next column. Double click the field Book-Id from Table1 Box.
4. Click in next column. Double click the field Book-Name from Table1
box.
5. Repeat step4 and add Book- Reference/ Lending. Book-issued from
Table1.
6. In column containing Book-Reference/Lending. Book-field, click in
criteria cell. Type Female to see record no of Book-Reference/Lending.
Book-issued.
Practical # 3
Procedure
Creating Database
1. Click File from menu bar and click New. Click the Blank database.
2. Write the file name for database in file name box.e.g. Bank-account.
Creating Tables
A window appears with three columns Filed Name, Data type, Description.
Entering Fields:
a) Type Acct_Id in first field name & Press Tab Key to switch to next column
with heading Data Type. A list triangle appears
b) Click list triangles and select a Data Type for Acct_ id from the list.
c) Press Tab Key to go to Description column of the particular field.(just
Comments)
5. Right click the field “Account_Id”. A context menu appears click the Primary
Key from this menu. It will set the Primary Key for Acct_Id Field.
Page 37 of 41
Practical Journal Computer Science - XII
Entering Records:-
1. Click Table1 in data base window. Click view menu then datasheet view.
A window appears. Enter record here.
2. Press CTRL+S to save records .Click Close button.
3. Click Relationship from menu bar then click Show Table. All tables
created in opened database appear in show table Box.
4. Select Table1 & click Add button. Click Table2 & click Add. Then click
Close button.
5. The two boxes of Table1 and Table2 appear with their fields.
6. Click Acct-ld field of Table1, drag the mouse till Acct-id field of Table2.
7. Click Enforce Referential integrity then click Create button.
A relationship line between two tables appears showing that a
relationship is created.
Queries:
Practical # 4
Queries
• Search the desired Stud_Id
• Delete the desired Stud_Id
• update Desired Stud_Id.
Procedure
Creating Database
1. Click File from menu bar and click New. Click the Blank database.
2. Write the file name for database in file name student .e.g. student_att.
Creating Table
A window appears with three columns Filed Name, Data type, Description.
Entering Fields:
a) Type Stud_Id in first field name & Press Tab Key to switch to next
column with heading Data Type. A list triangle appears
b) Click list triangles and select a Data Type for Stud_ id from the list.
c) Press Tab Key to go to Description column of the particular
field.(just Comments)
5. Right click on the field “Student_Id”. A context menu appears click the
Primary Key from this menu. It will set the Primary Key for Stud-Id Field.
6. Click save button or press CTRL+S. Save as dialog box appears.
7. Type table name Table1, and Click ok. Click Close button.
Repeat step 4 to step 7 and create second table with Stud Id, Stud Id Field
Page 40 of 41
Practical Journal Computer Science - XII
Entering Records:-
1. Click Table1 in data base window. Click view menu then datasheet view.
A window appears. Enter record here.
2. Press CTRL+S to save records .Click Close button.
Repeat step 1 to 2 of C option for entering data in Table2.
3. Click Relationship from menu bar then click Show Table. All tables
created in opened database appear in show table Box.
4. Select Table1 & click Add button. Click Table2 & click Add. Then click
Close button.
5. The two boxes of Table1 and Table2 appear with their fields.
6. Click Stud-ld field of Table1, drag the mouse till Stud-id field of Table2.
7. Click Enforce Referential integrity then click Create button.
A relationship line between two tables appears showing that a
relationship is created.
Queries