0% found this document useful (0 votes)
5 views24 pages

computer science practical 1

The document outlines the practical curriculum for Computer Science in the 11th standard, detailing ten exercises in C++ along with their respective coding tasks. It specifies the distribution of marks for internal and external assessments, totaling 20 marks. Additionally, it provides a list of programming exercises, including topics such as gross salary calculation, percentage evaluation, palindrome checking, and array manipulation.

Uploaded by

murugammalr6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views24 pages

computer science practical 1

The document outlines the practical curriculum for Computer Science in the 11th standard, detailing ten exercises in C++ along with their respective coding tasks. It specifies the distribution of marks for internal and external assessments, totaling 20 marks. Additionally, it provides a list of programming exercises, including topics such as gross salary calculation, percentage evaluation, palindrome checking, and array manipulation.

Uploaded by

murugammalr6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

www.tntextbooks.

in

PRACTICAL COMPUTER SCIENCE


11

Instructions:

1. Ten exercises from C++ are practiced in the practical classes

2. One question from C++ with internal choice

3. Distribution of Marks

I. Internal Assessment: 5 Marks

Record Book 5 Marks

II. External Assessment: 15 Marks

(a) C++ Program coding 10 Marks

(b) Execution & Output 5 Marks

Total 20 Marks

298

11th Std Computer Science_ Practical.indd 298 06-01-2023 15:14:21


www.tntextbooks.in

INDEX

Sl. Question Page


Program Name
No. Number Number

1 CS1 Gross Salary 300

2 CS2 Percentage 301

3 CS3 Palindrome 302

4 CS4 Number Conversion 303

5 CS5 Fibonacci Prime Series 305

6 CS6 Insert / Delete elements in an array 307

7 CS7 Boundary element of a matrix 310

8 CS8 ABC Publishers 312

9 CS9 Employee details using class 316

10 CS10 Student Details 318

299

11th Std Computer Science_ Practical.indd 299 06-01-2023 15:14:21


www.tntextbooks.in

CS1 - GROSS SALARY

Write a C++ program to input basic salary of an employee and calculate its Gross
CS-1
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>
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<< "\n\t Basic Pay ................"<< basic<<endl;
cout<< "\t Dearness Allowance ......." << da <<endl;
cout<< "\t House Rent Allowance......"<< hra <<endl;
cout<< "\t ------------------------------------------"<<endl;
cout<< "\t Gross Salary.............."<<gross <<endl;

300

11th Std Computer Science_ Practical.indd 300 06-01-2023 15:14:21


www.tntextbooks.in

cout<< "\t ------------------------------------------"<<endl;


return 0;
}
Output
Enter basic salary of an employee: 25000
Basic Pay : 25000
Dearness Allowance : 22500
House Rent Allowance : 6250
------------------------
Gross Salary : 53750
------------------------
CS2 - PERCENTAGE

Write a C++ program to check percentage of a student and display the division
CS-2 (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:
301

11th Std Computer Science_ Practical.indd 301 06-01-2023 15:14:21


www.tntextbooks.in

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;
}
Output 1
Enter your percentage: 79
You scored 79%
You have passed with First division
Output 2
Enter your percentage: 39
You scored 39%
Sorry: You have failed
CS3 - PALINDROME

Write a C++ program to enter any number and check whether the number is palindrome
CS-3 or not using while loop.

Coding

#include <iostream>
using namespace std;
int main()
{
int n,num, digit, rev =0;
cout<<"Enter a positive number: ";

302

11th Std Computer Science_ Practical.indd 302 06-01-2023 15:14:21


www.tntextbooks.in

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 a positive number to reverse: 1234
The reverse of the number is: 4321
The number is not a palindrome
Output 2
Enter a positive number to reverse: 1221
The reverse of the number is: 1221
The number is a palindrome
CS4 - NUMBER CONVERSION

CS-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 userselect the third option

Coding
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
303

11th Std Computer Science_ Practical.indd 303 06-01-2023 15:14:21


www.tntextbooks.in

int dec,d,i,temp,ch;
long int bin;
do
{
dec=bin=d=i=0;
cout<<"\n\n\t\tMENU\n1. Decimal to Binary number\n2.Binary to Decimal number\
n3.Exit\n";
cout <<"Enter your choice(1/2/3)";
cin>>ch;
switch (ch)
{
case 1: cout << "Enter a decimal number: "; cin >> dec;
temp=dec;
while (dec!=0)
{
d = dec%2;
bin += d * pow(10,i);
dec /= 2;
i++;
}
cout << temp << " in decimal = " << bin << " in binary" << endl ;break;
case 2: cout << "Enter a binary number: "; cin >> bin;
temp=bin;
while (bin!=0)
{
d = bin%10;
dec += d*pow(2,i);
bin /= 10;
i++;
}
cout << temp << " in binary = " <<dec << " in decimal";
break;
case 3: break;
default : cout<<"Invalid choice";
}
} while (ch!=3);
return 0;
}

Output 1
MENU
1.Decimal to Binary number
304

11th Std Computer Science_ Practical.indd 304 06-01-2023 15:14:21


www.tntextbooks.in

2.Binary to Decimal number


3.Exit
Enter your choice(1/2/3)1
Enter a decimal number: 23
23 in decimal = 10111 in binary
MENU
1.Decimal to Binary number
2.Binary to Decimal number
3.Exit
Enter your choice(1/2/3)2
Enter a binary number: 11001
11001 in binary = 25 in decimal
MENU
1.Decimal to Binary number
2.Binary to Decimal number
3.Exit
Enter your choice(1/2/3)3
Output 2
MENU
1.Decimal to Binary number
2.Binary to Decimal number
3.Exit
Enter your choice(1/2/3)4
Invalid choice
MENU
1.Decimal to Binary number
2.Binary to Decimal number
3.Exit
Enter your choice(1/2/3)3

CS5 - FIBONACCI PRIME SERIES

Write a C++ program using a user defined function to generate the Fibonacci series till
CS-5 n terms and print if each term is prime or Composite.

Coding

#include <iostream>
#include <stdlib.h>

305

11th Std Computer Science_ Practical.indd 305 06-01-2023 15:14:21


www.tntextbooks.in

using namespace std;


void Primechk (int a )
{ int j;
if ( a == 0 || a == 1 )
{ cout<< " NEITHER 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\tFIBONACCI SERIES\n " ;
fibo (n) ;
return 0;
}
306

11th Std Computer Science_ Practical.indd 306 06-01-2023 15:14:21


www.tntextbooks.in

Output
ENTER THE NUMBER OF TERMS 10
FIBONACCI SERIES
0 NEITHER PRIME NOR COMPOSITE
1 NEITHER PRIME NOR COMPOSITE
1 NEITHER PRIME NOR COMPOSITE
2 PRIME
3 PRIME
5 PRIME
8 COMPOSITE
13 PRIME
21 COMPOSITE
34 COMPOSITE

CS6 - INSERT / DELETE ELEMENTS IN AN ARRAY

Write a menu driven C++ program to Insert and Delete elements in a single dimension
CS-6 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++)
307

11th Std Computer Science_ Practical.indd 307 06-01-2023 15:14:21


www.tntextbooks.in

{
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";
cin>>pos;
308

11th Std Computer Science_ Practical.indd 308 06-01-2023 15:14:21


www.tntextbooks.in

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()

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
-----------------------

309

11th Std Computer Science_ Practical.indd 309 06-01-2023 15:14:21


www.tntextbooks.in

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
---------------------------

CS 7 - Boundary Element of a Matrix

CS-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)

310

11th Std Computer Science_ Practical.indd 310 06-01-2023 15:14:21


www.tntextbooks.in

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;
}

Output
Enter more than 3 number of rows and columns
44

311

11th Std Computer Science_ Practical.indd 311 06-01-2023 15:14:21


www.tntextbooks.in

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
1 2 3 4
5 8
9 2
3 4 5 6

CS8 - ABC PUBLISHERS

CS-8 Define a class named Publisher in C++ with the following descriptions

private members
Bookno integer
Title 20 characters

312

11th Std Computer Science_ Practical.indd 312 06-01-2023 15:14:21


www.tntextbooks.in

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()

313

11th Std Computer Science_ Practical.indd 313 06-01-2023 15:14:21


www.tntextbooks.in

{Bookno=id;
Title[0]='\0';
Author[0]='\0';
Price=0;
Totamt=0;
id++;
}
void Readdata();
void Displaydata();
};
void Publisher::Readdata()
{
int nocopies;
cout<<"Enter the Title name ";cin>>Title;
cout<<"Enter the Author name ";cin>>Author;
cout<<"Enter the Price ";cin>>Price;
cout<<"Enter 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";
314

11th Std Computer Science_ Practical.indd 314 06-01-2023 15:14:21


www.tntextbooks.in

}
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;
}

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
315

11th Std Computer Science_ Practical.indd 315 06-01-2023 15:14:21


www.tntextbooks.in

~~~~~~~
==================================
Book Number : 1002
Title : CoreJava
Author Name : Xavier
Price Per Book : 250
Total Amount : 1250
==================================

CS9 - EMPLOYEE DETAILS USING CLASS

Create a C++ program to create a class employee containg the following members
CS-9
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(){
316

11th Std Computer Science_ Practical.indd 316 06-01-2023 15:14:21


www.tntextbooks.in

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;
}
void calculate()
{
np=bp+hra+ da -pf;
}
void display()
{
cout<<eno<<"\t"<<name<<"\t"<<des<<"\t"<<bp<<"\t"<<hra<<"\t"<<da<<"\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++){
317

11th Std Computer Science_ Practical.indd 317 06-01-2023 15:14:21


www.tntextbooks.in

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_noe_name des bp hra da pf np
1201 Ramkumar Engineer 50000 10000 5000 1000 64000
1202 Viswanathan Engineer-Tech 40000 9000 4500 1000 52500
CS10 -STUDENT DETAILS

CS-10 Write a C++ program to create a class called Student with the following details

Protected member
Rno integer
Public members
318

11th Std Computer Science_ Practical.indd 318 06-01-2023 15:14:21


www.tntextbooks.in

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
319

11th Std Computer Science_ Practical.indd 319 06-01-2023 15:14:21


www.tntextbooks.in

{
protected:
float Mark1,Mark2;
public:
void Readmark (float m1,float m2)
{
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();
320

11th Std Computer Science_ Practical.indd 320 06-01-2023 15:14:21


www.tntextbooks.in

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

321

11th Std Computer Science_ Practical.indd 321 06-01-2023 15:14:21

You might also like