I PUC COMPUTER SCIENCE
PRACTICAL MANUAL
SECTION - B
Pgm Program Name
No
SECTION - A (C++ PROGRAMMING)
1 Write a program to interchange the values of two variables using a third variable.
2 Write a program to interchange the values of two variables without using a third
variable.
3 Write a program to find the area and circumference of a circle.
4 Write a C++ program to convert days into years, months and days.
(Hint: Assume all months have 30 days)
5 Write a C++ program to input the total amount in a bill, if the amount is greater than
1000, a discount of 8% is given. Otherwise, no discount is given. Output the total
amount, discount and the final amount. Use simple if statement.
6 Write a C++ program to check whether a given year is a leap year not, Using if – else
statement.
7 Write a C++ program to accept a character. Determine whether the character is a
lower-case or upper-case letter.
8 Write a C++ program to find sum of all the digits of a number using while statement.
9 Write a C++ program to find the factorial of a number using for statement.
(Hint: 5! = 5 * 4 * 3 * 2 * 1 = 120)
10 Write a C++ program to determine whether the string is a palindrome.
11 Write a C++ program to check whether the given number is an Armstrong Number
using do-while statement. (Hint: 153 = 13 + 53 + 33)
12 Wri Write a C++ program to find the area of triangle given three sides.
13 Write a program to input the marks of four subjects, calculate the total percentage and
output the result as either “First class”, or “Second class”, or “Pass class” or “Fails”
using switch statement.
Class Range %
First Class Between 60 and 100%
Second Class Between 50 and 59%
Pass Class Between 40 and 49%
Fails Less than 40%
Write a program to check whether a given number is an Armstrong number using do-
while statement (Hint: 153 = 13 + 53+ 33).
14 Write a C++ program to generate the Fibonacci sequence up to a limit using for
statement. (Hint: 5 = 0 1 1 2 3)
15 Write a C++ program to find the second largest of n number in the array.
16 Write a C++ program to arrange a list of numbers in ascending order.
17 Write a C++ program to find position of a given number in the array.
18 Write a C++ program to find the sum of two matrices:
19 Write a program to find GCD and LCM of two numbers using functions.
20 Write a program to input the register number, name and class of all the
students in a class into a structure and output the data in a tabular manner with proper
heading.
SECTION – C : WEB DESIGNING
28 1. Create a web page to display your details using different tags.
29 2. Create a model web site for your college making use of different tags.
PROGRAM 01:
Write a C++ program to interchange the values of two variables using a
third variable.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int a, b, temp;
clrscr( );
cout<<"Enter the two numbers";
cin>>a>>b;
cout<<"Before Interchanging : a = " <<a<<" and b = "<<b<<endl;
temp = a;
a = b;
b = temp;
cout<<"After Interchanging : a = " <<a<<" and b = "<<b<<endl;
getch();
}
OUTPUT:
Enter the two numbers:
10 20
Before Interchanging : a = 10 and b = 20
After Interchanging : a = 20 and b = 10
PROGRAM 02:
Write a C++ program to interchange the values of two variables without
using third variable.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int a, b;
clrscr( );
cout<<"Enter the two numbers:"<<endl;
cin>>a>>b;
cout<<"Before Interchanging : a = " <<a<<" and b = "<<b<<endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"After Interchanging : a = " <<a<<" and b = "<<b<<endl;
getch();
}
OUTPUT:
Enter the two numbers:
10 20
Before Interchanging : a = 10 and b = 20
After Interchanging : a = 20 and b = 10
PROGRAM 03:
Write a C++ program to find the area and circumference of a circle.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
float rad, area, circum;
clrscr( );
cout<<"Enter the radius:";
cin>>rad;
area = 3.142 * rad * rad;
circum = 2 * 3.142 * rad;
cout<<"Area of circle = "<<area<<endl;
cout<<"Circumference of circle = "<<circum<<endl;
getch();
}
OUTPUT :
Enter the radius: 10
Area of circle = 314.200012
Circumference of circle = 62.84
PROGRAM 04:
Write a C++ program to convert days into years, months and days.
(Hint: Assume all months have 30 days)
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int totaldays, days, year, month;
clrscr( );
cout<<"Enter the total days:";
cin>>totaldays;
year = totaldays/365;
totaldays = totaldays % 365;
month = totaldays/30;
days = totaldays % 30;
cout<<"Years = "<< years<<endl;
cout<<"Months = "<<month<<endl;
cout<<"Days = "<<days<<endl;
getch();
}
OUTPUT :
Enter the total days: 1015
Years = 2
Months = 9
Days = 15
PROGRAM 05:
Write a C++ program to input the total amount in a bill, if the amount is
greater than 1000, a discount of 8% is given. Otherwise, no discount is
given. Output the total amount, discount and the final amount. Use simple
if statement.
#include<iostream.h>
#include<conio.h>
void main( )
{
float TAmount, discount, FAmount ;
clrscr( );
cout<<"Enter the Total Amount : ";
cin>>TAmount;
discount = 0;
if(TAmount>1000)
discount = 0.08 * TAmount;
FAmount = TAmount - discount;
cout<<"Total Amount = "<<TAmount<<endl;
cout<<"Discount = "<<discount<<endl;
cout<<"Final Amount = "<< FAmount<<endl;
getch( );
}
OUTPUT :
Enter the Total Amount : 3000
Total Amount = 3000
Discount = 240
Final Amount = 2760
PROGRAM 06:
Write a C++ program to check whether a given year is a leap year not,
Using if – else statement.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int year ;
clrscr( );
cout<<"Enter the Year in the form YYYY : ";
cin>>year;
if(year%4 = =0 && year%100!=0 || year%400 = =0)
cout<<year<<" is a leap year"<<endl;
else
cout<<year<<" is not a leap year"<<endl;
getch( );
}
OUTPUT 1:
Enter the Year in the form YYYY : 2012
2012 is a leap year
OUTPUT 2:
Enter the Year in the form YYYY : 1900
1900 is not a leap year
PROGRAM 07:
Write a C++ program to accept a character. Determine whether the
character is a lower-case or upper-case letter.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
char ch ;
clrscr( );
cout<<"Enter the Character"<<endl;
cin>>ch;
if(ch>= 'A' && ch <='Z')
cout<<ch<<" is an Upper-Case Character"<<endl;
else if(ch>= 'a' && ch <='z')
cout<<ch<<" is an Lower-Case Character"<<endl;
else
cout<<ch<<" is not an alphabet"<<endl;
getch( );
}
OUTPUT 1:
Enter the Character
A
A is an Upper-Case Character
OUTPUT 2:
Enter the Character
g
g is an Lower-Case Character
OUTPUT 3:
Enter the Character
5
5 is not an alphabet
PROGRAM 08:
Write a C++ program to find sum of all the digits of a number using while
statement.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int n, m, sum, rem;
clrscr( );
cout<<"Enter the Number: ";
cin>>n;
m=n;
sum = 0;
while(n!=0)
{
rem = n % 10;
sum = sum + rem;
n = n/10;
}
cout<<"Sum of digits in "<<m<<”=”<<sum<<endl;
getch( );
}
OUTPUT :
Enter the Number: 1205
Sum of digits in 1205 = 8
PROGRAM 09:
Write a C++ program to find the factorial of a number using for statement.
(Hint: 5! = 5 * 4 * 3 * 2 * 1 = 120)
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int n, fact, i;
clrscr( );
cout<<"Enter the number"<<endl;
cin>>n;
fact = 1;
for( i = 1; i<= n; i++)
fact = fact * i;
cout<<n<<"! ="<<fact<<endl;
getch( );
}
OUTPUT :
Enter the number
3
4! = 24
PROGRAM 10:
Write a C++ program to determine whether the string is a palindrome.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<string.h>
void main( )
{
char s[100], r[100];
clrscr( );
cout<<"Enter the String:";
[Link](s, 100);
strcpy (r, s);
strrev (r);
if(strcmpi(s, r) = = 0)
cout<<"It is palindrome"<<endl;
else
cout<<"It is not palindrome"<<endl;
getch( );
}
OUTPUT 1:
Enter the String: MADAM
It is palindrome
OUTPUT 2:
Enter the String: CAT
It is not palindrome
PROGRAM 11:
Write a C++ program to check whether the given number is an Armstrong
Number using do-while statement. (Hint: 153 = 13 + 53 + 33)
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int n, m, rem, sum;
clrscr( );
cout<<"Enter the three digit number"<<endl;
cin>>n;
m = n;
sum = 0;
do
{
rem = n % 10;
sum = sum + rem * rem * rem;
n = n / 10;
}while(n != 0);
if(sum == m)
cout<<m<<" is an Armstrong Number "<<endl;
else
cout<<m<<" is not an Armstrong Number "<<endl;
getch( );
}
OUTPUT 1:
Enter the three digit number
370
370 is an Armstrong Number
OUTPUT 2:
Enter the three digit number
152
152 is not an Armstrong Number
PROGRAM 12:
Write a C++ program to find the area of triangle given three sides.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<math.h>
void main( )
{
float s1, s2, s3, s, area;
clrscr( );
cout<<"Enter the length of three sides:";
cin>>s1>>s2>>s3;
s = (s1 + s2+ s3)/2;
area = sqrt( s* (s-s1) * (s-s2) * (s-s3));
cout<<"Area of triangle = "<<area<<endl;
getch();
}
OUTPUT :
Enter the length of three sides: 5 3 6.5
Area of triangle = 7.210832
PROGRAM 13:
Write a C++ program to input the marks of four subjects. Calculate the total
Percentage and output the result as either “First Class” or “Second Class” or
“Pass Class” or “Fail” using switch statement.
Class Range (%)
First Class Between 60% to 100%
Second Class Between 50% to 59%
Pass Class Between 40% to 49%
Fail Less than 40%
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int m1, m2, m3, m4, total, choice;
float per;
clrscr( );
cout<<"Enter the First subject marks:";
cin>>m1;
cout<<"Enter the Second subject marks:";
cin>>m2;
cout<<"Enter the Third subject marks:";
cin>>m3;
cout<<"Enter the Fourth subject marks:";
cin>>m4;
total = m1 + m2 + m3 + m4;
per = total / 4.0;
cout<<"Total Marks = "<<total<<endl;
cout<<"Percentage = "<<per<<endl;
choice = (int) per/10;
cout<<"The result of the student is = ";
switch(choice)
{
case 10:
case 9:
case 8:
case 7:
case 6: cout<<"First Class "<<endl;
break;
case 5: cout<<"Second Class"<<endl;
break;
case 4: cout<<"Pass Class"<<endl;
break;
default: cout<<"Fail"<<endl;
}
getch( );
}
OUTPUT :
Enter the First subject marks: 99
Enter the Second subject marks: 98
Enter the Third subject marks: 77
Enter the Fourth subject marks: 97
Total Marks = 371
Percentage = 92.0
The result of the student is = First class
PROGRAM 14:
Write a C++ program to generate the Fibonacci sequence up to a limit using for
statement. (Hint: 5 = 0 1 1 2 3)
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int n, f1, f2,f3, count;
clrscr( );
cout<<"Enter the number limit: ";
cin>>n;
f1 = 0;
f2 = 1;
cout<<f1<<setw(4)<<f2;
f3 = f1 + f2;
for(count = 2; f3<=n; count++)
{
cout<<setw(4)<<f3;
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
cout<<endl<<”Total terms = "<<count;
getch( );
}
OUTPUT :
Enter the number limit: 50
0 1 1 2 3 5 8 13 21 34
Total terms = 10
PROGRAM 15:
Write a C++ program to find the second largest of n number in the array.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main( )
{
int a[50], i, n, largest, secondlar;
clrscr( );
cout<<"How many elements?"<<endl;
cin>>n;
cout<<"Enter the elements:"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
if(a[0] > a[1])
{
largest = a[0];
secondlar = a[1];
}
else
{
largest=a[1];
secondlar=a[0];
}
for(i=2; i<n; i++)
if(a[i] > largest)
{
secondlar = largest;
largest = a[i];
}
else
if(a[i] > secondlar)
secondlar = a[i];
cout<<"Largest = "<<largest<<endl;
cout<<"Second Largest = "<<secondlar<<endl;
getch( );
}
OUTPUT:
How many elements?
5
Enter the elements:
10 20 50 40 30
Largest = 50
Second Largest = 40
PROGRAM 16:
Write a C++ program to arrange a list of numbers in ascending order.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main( )
{
int a[50], i, temp, j, n;
clrscr( );
cout<<"Enter the number of elements:"<<endl;
cin>>n;
cout<<"Enter the elements:"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
for(i=1; i<=n; i++)
{
for(j=0;j<n;j++)
{
if(a[j] >a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
cout<<"The sorted elements are:"<<endl;
for(i=0; i<n; i++)
cout<<a[i]<<setw(4);
getch( );
}
OUTPUT:
Enter the number of elements:
5
Enter the elements:
60 20 50 40 30
The sorted elements are:
20 30 40 50 60
PROGRAM 17:
Write a C++ program to find position of a given number in the array.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main( )
{
int a[50], i, pos, ele, n;
clrscr( );
cout<<"Enter the number of elements:"<<endl;
cin>>n;
cout<<"Enter the elements:"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the search element:"<<endl;
cin>>ele;
pos= -1;
for(i=0; i<n; i++)
{
if(ele == a[i])
{
pos = i;
break;
}
}
if(pos >= 0)
cout<<ele<<" is present at position "<<pos<<endl;
else
cout<<ele<<" is not present"<<endl;
getch( );
}
OUTPUT 1:
Enter the number of elements:
5
Enter the elements:
60 20 50 40 30
Enter the search element:
20
20 is present at position 1
OUTPUT 2:
Enter the number of elements:
5
Enter the elements:
60 20 50 40 30
Enter the search element:
35
35 is not present
PROGRAM 18:
Write a C++ program to find the sum of two matrices:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main( )
{
int a[5][5], b[5][5], sum[5][5], row, col, i, j;
clrscr( );
cout << "Enter the row and column of the matrix: ";
cin >>row>>col;
cout << "Enter elements of first matrix: " << endl;
for (i = 0; i < row; i++)
for (j = 0; j < col; j++)
cin >> a[i][j];
cout << "Enter elements of second matrix: " << endl;
for(i = 0; i < row; i++)
for(j = 0; j < col; j++)
cin >> b[i][j];
for(i = 0; i < row; i++)
for(j = 0; j < col; j++)
sum[i][j] = a[i][j] + b[i][j];
cout << "Sum of two matrix is: " << endl;
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
cout << sum[i][j] << setw(5);
cout << endl;
}
getch( );
}
OUTPUT1:
Enter the row and column of the matrix: 2 3
Enter elements of first matrix:
1 2 3
4 5 6
Enter elements of second matrix:
2 5 1
2 1 1
Sum of two matrix is:
3 7 4
6 6 7
PROGRAM 19:
Write a program to find GCD and LCM of two numbers using functions.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
int gcd(int x, int y)
{
int r;
while(b!=0)
{
r = x % y;
x = y;
y = r;
}
return(x);
}
void main()
{
int gcd(int x, int y);
int a, b, product, lcm, g;
clrscr();
cout<<”Enter two numbers”;
cin>>a>>b;
g = gcd(a, b);
product= a*b;
lcm = product/g;
cout<<”GCD = “<<g<<endl;
cout<<”LCM = “<<lcm;
getch();
}
OUTPUT:
Enter two numbers:2 4
GCD=2
LCM=4
PROGRAM 20:
Write a program to input the register number, name and class of all the
students in a class into a structure and output the data in a tabular manner with
proper heading.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
struct student
{
int regno;
char name[25];
char section[10];
};
void main()
{
student s[50];
int i,j,n;
clrscr();
cout<<”How many students?”;
cin>>n;
for(i=0;i<n;i++)
{
cout<<”Enter the Reg. No. of the student”<<i+1<<” : “;
cin>>s[i].regno;
cout<<”Enter the name of the student”<<i+1<<” : “;
cin>>s[i].name;
cout<<”Enter the class of the student”<<i+1<<” : “;
cin>>s[i].section;
}
cout<<”\t REG NO. \t NAME \t CLASS \t”<<endl;
for(i=0; i<n; i++)
cout<<”\t”<<s[i].regno<<”\t”<<s[i].name<<”\t”<<s[i].section<<endl;
getch();
}
OUTPUT:
How many students? 3
Enter the Reg. No. of the student1: 111
Enter the name of the student1: Ayesha
Enter the class of the student1: CEBA
Enter the Reg. No. of the student2: 222
Enter the name of the student2: Harshini
Enter the class of the student2: CEBA
Enter the Reg. No. of the student3: 333
Enter the name of the student3: Divya
Enter the class of the student3: SEBA
[Link]. NAME CLASS
111 Ayesha CEBA
222 Harshini CEBA
333 Divya SEBA
SECTION – C : WEB DESIGNING
28. Create a web page to display your details using different tags.
<html>
<head>
<title> My Details </title>
</head>
<body text = "blue" bgcolor = "yellow">
<h1><center> My Details </center></h1>
<p align = "left" > My name is geetha. I am a student of Janatha Independent P
U College, hemmady. I am studying in II PUC and i have
taken PCMC combination. </p><br>
<h2> About My College </h2>
<p>
Most prestigious Institution in Karnataka. Has been a pioneer in the field of
education for many years, excellency in imparting quality knowledge.
</p><br>
<h3> My Hobbies are </h3>
<ol>
<li> Reading </li>
<li> Singing </li>
<li> Dancing </li>
</ol>
<marquee direction = "left"> "Enjoy Life As a Student" </marquee>
</body>
</html>
29. Create a model web site for your college making use of different tags.
Web page 1:
<html>
<head>
<title>Janatha Independent P U College </title>
</head>
<body text = "blue" bgcolor = "pink">
<h1><center> My College </center></h1>
<font size = "4" face = "Times New Roman" color = "violet">
Most prestigious Institution in Karnataka. Has been a pioneer in the field
of education for many years, excellency in imparting quality knowledge.
</font><br><br>
<a href = "C:\Users\C\Desktop\[Link]"> click here for more details </a>
</body>
</html>
Web page 2 :
<html>
<head>
<title> Janatha Independent P U College </title>
</head>
<body text = "red" bgcolor = "green">
<img src = "c:\[Link]" border ="3" height = "200" width = "150"><br>
<h1> Courses Offered here includes </h1>
<h2> Science </h2>
<ul>
<li> pcmb </li>
<li> pcmc </li>
</ul>
<h2> Commerec </h2>
<ul>
<li> ebac </li>
<li> ebas </li>
</ul>
<marquee direction = "left"> "Admission Open For Eligible students" </marquee>
</body>
</html>