11th Comp - Sci EM Practical Programs - 2023-24
11th Comp - Sci EM Practical Programs - 2023-24
COMPUTER SCIENCE
PRACTICAL PROGRAMS
2023 - 24
Prepared By,
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 1
HSC 1st Year COMPUTER SCIENCE - PRACTICAL PROGRAMS
CS1 - GROSS SALARY
1. Write a C++ program to input basic salary of an employee and calculate its Gross
salary according to following:
Basic Salary <25000 HRA = 20% DA = 80%
Basic Salary >= 25000 HRA = 25% DA = 90%
Basic Salary >= 40000 HRA = 30% DA = 95%
Coding:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float basic,gross,da,hra;
cout<<"Enter Basic salary of an employee:";
cin>>basic;
if(basic<25000)
{
da=basic*80/100;
hra=basic*20/100;
}
else if (basic>=25000&&basic<40000)
{
da=basic*90/100;
hra=basic*25/100;
}
else if (basic>=40000)
{
da=basic*95/100;
hra=basic*30/100;
}
gross=basic+hra+da;
cout<<setw(25)<<"Basic pay:"<<setw(10)<<basic<<endl;
cout<<setw(25)<<"Dearness allowance:"<<setw(10)<<da<<endl;
cout<<setw(25)<<"House rent allowance:"<<setw(10)<<hra<<endl;
cout<<setw(25)<<" "<<setw(10)<<"..............."<<endl;
cout<<setw(25)<<"Gross salary:"<<setw(10)<<gross<<endl;
cout<<setw(25)<<" "<<setw(10)<<"..............."<<endl;
return 0;
}
Output :
Enter Basic salary of an employee : 25000
Basic Pay: 25000
Dearness Allowance: 22500
House Rent Allowance: 6250
…………..….………
Gross Salary: 53750
………………………
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 2
CS2 - PERCENTAGE
2. Write a C++ program to check percentage of a student and display the division
(distinction, first, second, third or fail) scored using switch case
Percentage Division
>=80 Distinction
>=60 and <80 First division
>=50 and <60 Second Division
>=40 and <50 Third Division
<40 Fail
Coding:
#include<iostream>
using namespace std;
int main()
{
float percent;
int x;
cout<<"Enter your percentage : ";
cin>>percent;
cout<<" You scored : "<<percent<<"%"<<endl;
x=percent/10;
switch(x)
{
case 10:
case 9:
case 8:
cout<<"You have passed with Distinction";
break;
case 7:
case 6:
cout<<"You have passed with First Division";
break;
case 5:
cout<<"You have passed with Second Division";
break;
case 4:
cout<<"You have passed with Third Division";
break;
default:
cout<<" Sorry : You have Failed ";
}
return 0;
}
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 3
CS3 – PALINDROME
3. Write a C++ program to enter any number and check whether the number is
palindrome or not using while loop.
Coding:
#include<iostream>
using namespace std;
int main()
{
int num,n,digit,rev=0;
cout<<"Enter the positive number:";
cin>>num;
n=num;
while(num)
{
digit=num%10;
rev=(rev*10)+digit;
num=num/10;
}
cout<<"The reverse of the number is:"<<rev<<endl;
if(n==rev)
cout<<"The number is a Palindrome";
else
cout<<"The number is not a Palindrome";
return 0;
}
Output 1 :
Enter the positive number: 1221
The reverse of the number is: 1221
The number is a Palindrome
Output 2 :
Enter the positive number: 1234
The reverse of the number is: 4321
The number is not a Palindrome
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 4
CS4 - NUMBER CONVERSION
4. Using do while loop create the following menu based C++ program
1.Convert a Decimal to binary number
2.Convert a binary number to Decimal 3. Exit
Depending on the choice accept the value and display the result .The program
should continue till the user select the third option.
Coding: #include<iostream>
using namespace std;
#include<cmath>
int main()
{
int dec,d,i,temp,ch;
long int bin;
do
{
dec=bin=d=i=0;
cout<<"\n\n\t\t MENU \n 1. DECIMAL TO BINARY NUMBER\n 2.
BINARY TO DECIMAL NUMBER\n 3. EXIT\n";
cout<<"Enter your choice(1/2/3)";
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the Decimal Number :";
cin>>dec;
temp=dec;
while(dec!=0)
{
d=dec%2;
bin+=d*pow(10,i);
dec/=2;
i++;
}
cout<<"The Binary Number is:"<<bin;
break;
case 2:
cout<<"Enter the Binary Number :";
cin>>bin;
temp=bin;
while(bin!=0)
{
d=bin%10;
dec+=d*pow(2,i);
bin/=10;
i++;
}
cout<<"The Decimal Number is:"<<dec;
break;
case 3:
break;
default:
cout<<"Invalid Choice:";
}
}
while(ch!=3);
return 0;
}
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 5
Output 1 : MENU
1. DECIMAL TO BINARY NUMBER
2.BINARY TO DECIMAL NUMBER
3.EXIT
Enter Your Choice(1/2/3) 1
Enter the Decimal Number : 23
The Binary Number is: 10111
Output 2 : MENU
1. DECIMAL TO BINARY NUMBER
2.BINARY TO DECIMAL NUMBER
3.EXIT
Enter Your Choice (1/2/3) 2
Enter the Binary Number : 11001
The Decimal Number is: 25
Output 3 : MENU
1. DECIMAL TO BINARY NUMBER
2.BINARY TO DECIMAL NUMBER
3.EXIT
Enter Your Choice (1/2/3) 3
Output 4 : MENU
1. DECIMAL TO BINARY NUMBER
2.BINARY TO DECIMAL NUMBER
3.EXIT
Enter Your Choice (1/2/3) 4
Invalid Choice
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 6
CS5 - FIBONACCI PRIME SERIES
5. Write a C++ program using a user defined function to generate the Fibonacci
series till n terms and print if each term is prime or Composite.
Coding:
#include<iostream>
#include<stdlib.h>
using namespace std;
void Primechk(int a)
{
int j;
if(a==0||a==1)
{
cout<<"\tNEITHER PRIME NOR COMPOSITE";
} else
{
for(j=2;j<a;j++)
{
if(a%j==0)
{
cout<<"\tCOMPOSITE"; break;
}
} if(a==j)
cout<<"\tPRIME";
}
}
void fibo (int n)
{
int a = -1,b=1,c=0;
for (int i=1;i<=n;i++)
{
cout<<endl;
c=a+b;
cout<<c;
Primechk(c);
a=b;
b=c;
}
}
int main()
{
int n;
cout<<"ENTER THE NUMBER OF REQUIRED FIBO TERMS…";
cin>>n;
cout<<"\n\t FIBONACCI SERIES\n";
fibo (n);
return 0;
}
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 7
Output:
FIBONACCI SERIES
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 8
CS6 - INSERT / DELETE ELEMENTS IN AN ARRAY
6. Write a menu driven C++ program to Insert and Delete elements in a single
dimension array of integers and print the array after insertion or deletion.
Coding:
#include<iostream>
using namespace std;
int a[20],b[20],c[40];
int m,n,p,val,i,j,key,pos,temp;
/*Function Prototype*/
void display();
void insert();
void del();
int main()
{
int choice;
cout<<"\nEnter the size of the array elements:\t";
cin>>n;
cout<<"\nEnter the elements for the array:\n";
for (i=0;i<n;i++)
{
cin>>a[i];
}
do {
cout<<"\n\n--------Menu-----------\n";
cout<<"1.Insert\n";
cout<<"2.Delete\n";
cout<<"3.Exit\n";
cout<<"-----------------------";
cout<<"\nEnter your choice:\t";
cin>>choice;
switch (choice)
{
case 1: insert(); break;
case 2: del(); break;
case 3:break;
default :cout<<"\nInvalid choice:\n";
}
} while (choice!=3);
return 0;
}
void display()//displaying an array elements
{
int i;
cout<<"\nThe array elements are:\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
}//end of display()
void insert()//inserting an element in to an array
{
cout<<"\nEnter the position for the new element:\t";
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 9
cin>>pos;
cout<<"\nEnter the element to be inserted :\t";
cin>>val;
for (i=n; i>=pos-1; i--)
{
a[i+1]=a[i];
}
a[pos-1]=val;
n=n+1;
display();
}//end of insert()
void del()//deleting an array element
{
cout<<"\n Enter the position of the element to be deleted:\t";
cin>> pos;
val= a [pos];
for (i= pos;i<n-1;i++)
{
a[i]=a[i+1];
}
n=n-1;
cout<<"\nThe deleted element is = "<<val;
display();
}//end of delete()
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 10
Output:
Enter the size of the array elements: 5
Enter the elements for the array:
1
2
3
4
5
--------Menu-----------
1.Insert
2.Delete
3.Exit
-----------------------
Enter your choice: 1
Enter the position for the new element: 3
Enter the element to be inserted : 26
The array elements are:
1 2 26 3 4 5
--------Menu-----------
1.Insert
2.Delete
3.Exit
-----------------------
Enter your choice: 2
Enter the position of the element to be deleted: 2
The deleted element is = 2
The array elements are:
1 3 26 4 5
--------Menu-----------
1.Insert
2.Delete
3.Exit
-----------------------
Enter your choice: 3
--------------------------------
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 11
CS 7 - Boundary Element of a Matrix
7. Write a C++ program to print boundary elements of a matrix.
Coding:
#include <iostream>
using namespace std;
void printBoundary (int a[][10], int m, int n)
{
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++)
{
if (i==0|| j==0||i==m-1||j==n-1)
cout<<a[i][j]<<" ";
else
cout<<" ";
}
cout <<endl ;
}
}
// Driver code
int main()
{
int a[10][10] ,i,j,m,n;
cout<<"Enter more than 3 number of rows and columns"<<endl;
cin>>m>>n;
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
cout<<"enter the value for array["<<i+1<<"]"<<"["<<j+1<<"] :";
cin>>a[i][j];
}
}
system("cls");
cout<<"\n\nOriginal Array\n";
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\n The Boundry element\n";
printBoundary(a, m, n);
return 0;
}
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 12
Output:
Enter more than 3 number of rows and columns
44
enter the value for array[1][1] :1
enter the value for array[1][2] :2
enter the value for array[1][3] :3
enter the value for array[1][4] :4
enter the value for array[2][1] :5
enter the value for array[2][2] :6
enter the value for array[2][3] :7
enter the value for array[2][4] :8
enter the value for array[3][1] :9
enter the value for array[3][2] :0
enter the value for array[3][3] :1
enter the value for array[3][4] :2
enter the value for array[4][1] :3
enter the value for array[4][2] :4
enter the value for array[4][3] :5
enter the value for array[4][4] :6
Original Array
1234
5678
9012
3456
The Boundary element
1234
5 8
9 2
3456
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 13
CS8 - ABC PUBLISHERS
8. Define a class named Publisher in C++ with the following descriptions
private members
Bookno integer
Title 20 characters
Author 10 characters
price float
Totamt float
Define a member function called calculate() to calculate the number of copies and
the price and return the total amount.
Public members
A default constructor function to initialize all data members.The book number must
be automatically generated staring from 1001
Readdata() function to accept values for Title,Author and price.Get the number of
copies from the user and invoke calculate().
Display data () function display all the data members in the following format
ABC PUBLISHERS
~~~~~~~~~~~~~~~~~
INVOICE
~~~~~~~~~
==================================
Book Number :
Title :
Author Name :
Price Per Book :
Total Amount :
==================================.
Coding:
#include<iostream>
#include<stdlib.h>
using namespace std;
int id=1001;
class Publisher
{
int Bookno;
char Title[20];
char Author [10];
float Price;
float Totamt;
float calculate (int);
public:
Publisher()
{Bookno=id;
Title[0]='\0';
Author[0]='\0';
Price=0;
Totamt=0;
id++;
}
void Readdata();
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 14
void Displaydata();
};
void Publisher::Readdata()
{
int nocopies;
cout<<"\nEnter the Title name ";cin>>Title;
cout<<"\nEnter the Author name ";cin>>Author;
cout<<"\nEnter the Price ";cin>>Price;
cout<<"\nEnter the Number of copies ";cin>>nocopies;
Totamt=calculate(nocopies);
}
float Publisher::calculate(int x)
{
return x*Price;
}
void Publisher::Displaydata()
{
cout<<"\n\t\tABC PUBLISHERS\n";
cout<<"\t\t~~~~~~~~~~~~~~\n";
cout<<"\t\t INVOICE\n";
cout<<"\t\t ~~~~~~~\n";
cout<<"\n==================================\n";
cout<<" Book Number : "<<Bookno<<endl;
cout<<"Title : "<<Title<<endl;
cout<<"Author Name : "<<Author<<endl;
cout<<"Price Per Book : "<<Price<<endl;
cout<<"Total Amount : "<<Totamt<<endl;
cout<<"\n==================================\n";
}
int main()
{
int n,i;
Publisher p[10];
cout<<"Enter the number of object to be created";cin>>n;
for (i=0;i<n;i++)
p[i].Readdata();
for (i=0;i<n;i++)
p[i].Displaydata();
return 0;
}
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 15
Output:
Enter the number of object to be created2
Enter the Title name C++Programming
Enter the Author name Balaguru
Enter the Price 500
Enter the Number of copies 3
Enter the Title name CoreJava
Enter the Author name Xavier
Enter the Price 250
Enter the Number of copies 5
ABC PUBLISHERS
~~~~~~~~~~~~~~
INVOICE
~~~~~~~
==================================
Book Number : 1001
Title : C++Programming
Author Name : Balaguru
Price Per Book : 500
Total Amount : 1500
=================================
ABC PUBLISHERS
~~~~~~~~~~~~~~
INVOICE
~~~~~~~
==================================
Book Number : 1002
Title : CoreJava
Author Name : Xavier
Price Per Book : 250
Total Amount : 1250
==================================
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 16
CS9 - EMPLOYEE DETAILS USING CLASS
9. Create a C++ program to create a class employee contains the following members
in public.
Public members
eno integer
name 20 characters
des 20 characters
member Function
void get() to accept values for all data members
Declare the derived class called Salary which contain the following details.
Public members
bp, hra, da, pf, np float
member Function
void get1() to accept values for bp,hra,da and pf and invoke calculate()
calculate() calculate the np by adding bp,hra,da subtracting pf
display() Display all the details
Create the derived class object and read the number of employees.Call the function
get(),get1() for each employee and display the details.
Coding:
#include<iostream>
using namespace std;
class emp
{
public:
int eno;
char name[20], des[20];
void get()
{
cout<<"Enter the employee number:";
cin>>eno;
cout<<"Enter the employee name:";
cin>>name;
cout<<"Enter the designation:";
cin>>des;
}
};
class salary :public emp
{
float bp,hra, da,pf,np;
public:
void get1()
{
cout<<"Enter the basic pay:";
cin>>bp;
cout<<"Enter the HouseRent Allowance:";
cin>>hra;
cout<<"Enter the Dearness Allowance :";
cin>>da;
cout<<"Enter the Provident Fund:";
cin>>pf;
}
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 17
void calculate()
{
np=bp+hra+da-pf;
}
void display()
{
cout<<eno<<"\t"<<name<<"\t"<<des<<"\t"<<bp<<"\t"<<hra<<"\t"<<d
a<<"\t"<<pf<<"\t"<<np<<"\n";
}
};
int main()
{
int i, n;
char ch;
salary s[10];
cout<<"Enter the number of employee:";
cin>>n;
for (i =0; i < n; i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"\n\t\t\tEmployee Details\n";
cout<<"\ne_no \t e_name\t des \t bp \t hra \t da \t pf \t np \n";
for (i =0; i < n; i++)
{
s[i].display();
}
return 0;
}
Output: Enter the number of employee:2
Enter the employee number:1201
Enter the employee name:Ramkumar
Enter the designation:Engineer
Enter the basic pay:50000
Enter the House Rent Allowance:10000
Enter the Dearness Allowance :5000
Enter the Provident Fund:1000
Enter the employee number:1202
Enter the employee name:Viswanathan
Enter the designation:Engineer-Tech
Enter the basic pay:40000
Enter the House Rent Allowance:9000
Enter the Dearness Allowance :4500
Enter the Provident Fund:1000
Employee Details
e_no e_name des bp hra da pf np
1201 Ramkumar Engineer 50000 10000 5000 1000 64000
1202 Viswanathan Engineer-Tech 40000 9000 4500 1000 52500
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 18
CS10 -STUDENT DETAILS
1. Write a C++ program to create a class called Student with the following details
Protected member
Rno integer
Public members
void Readno(int); to accept roll number and assign to Rno
void Writeno(); To display Rno.
The class Test is derived Publically from the Student class contains the following
details
Protected member
Mark1 float
Mark2 float
Public members
void Readmark(float,float); To accept mark1 and mark2
void Writemark(); To display the marks
Create a class called Sports with the following detail
Protected members: score integer
Public members
void Readscore(int); To accept the score
void Writescore(); To display the score
The class Result is derived Publically from Test and Sports class contains the
following details
Private member: Total float
Public member
void display() assign the sum of mark1 ,mark2,score in total.
invokeWriteno(),Writemark() and Writescore() .Display the total also.
Coding:
#include<iostream>
using namespace std;
class Student
{
protected:
int Rno;
public:
void Readno(int r)
{
Rno=r;
}
void Writeno()
{
cout<<"\nRoll no : "<<Rno;
}
};
class Test :public Student
{
protected:
float Mark1,Mark2;
public:
void Readmark (float m1,float m2)
{
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 19
Mark1=m1;
Mark2=m2;
}
void Writemark()
{
cout<<"\n\n\tMarks Obtained\n ";
cout<<"\n Mark1 : "<<Mark1;
cout<<"\n Mark2 : "<<Mark2;
}
};
class Sports
{
protected:
int score;// score = Sports mark
public:
void Readscore (int s)
{
score=s;
}
void Writescore()
{
cout<<"\n Sports Score : "<<score;
}
};
class Result :public Test,public Sports
{
int Total;
public:
void display()
{
Total = Mark1 + Mark2 + score;
Writeno();
Writemark();
Writescore();
cout<<"\n\n Total Marks Obtained : "<< Total<<endl;
}
};
int main()
{
Result stud1;
stud1.Readno(1201);
stud1.Readmark(93.5,95);
stud1.Readscore(80);
cout<<"\n\t\t\t HYBRID INHERITANCE PROGRAM\n";
stud1.display();
return 0;
}
Output: HYBRID INHERITANCE PROGRAM
Roll no : 1201
Marks Obtained
Mark1 : 93.5
Mark2 : 95
Sports Score : 80
Total Marks Obtained : 268
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 20
No matter how
good and dedicated
teachers are,
students need to be
willing to learn.
Education is one thing,
No one can take away from you.
All the Best!
J. Kavitha, B.Sc, B.Ed, M.C.A, M.Phil., Computer Instructor Gr-I, GHSS, S.S.KULAM - CBE 21