https://sites.google.
com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
XI STD COMPUTER SCIENCE C++Programs 2024 - 2025
Sl.No Program Output
#include <iostream>
using namespace std;
int main() GOVT. HR.SEC.SCHOOL
{ MUKHASAPARUR
1. School Address cout << "\n GOVT. HR.SEC.SCHOOL ";
CUDDALORE DT
cout << "\n MUKHASAPARUR ";
cout << "\n CUDDALORE DT "; PIN 606001
cout << "\n PIN 606001" ;
}
#include <iostream>
using namespace std;
2. வ ட தி int main() Enter Radius: 8
{ The area of circle = 200.96
பர பளைவ int radius;
க டறி float area;
cout << "\n Enter Radius: ";
C++ நிர .(area cin >> radius;
of circle) area = 3.14 * radius * radius;
cout << "\n The area of circle = " << area;
}
#include <iostream>
using namespace std;
int main()
{ Enter Mark 1: 45
int m1, m2, m3, sum;
Enter Mark 2: 50
3. cout << "\n Enter Mark 1: ";
cin >> m1; Enter Mark 3: 55
ெதாைக (SUM cout << "\n Enter Mark 2: "; The sum = 150
of 3 marks) cin >> m2;
cout << "\n Enter Mark 3: ";
cin >> m3;
sum = m1 + m2 + m3;
cout << "\n The sum = " << sum;
}
#include <iostream>
using namespace std; Enter your age: 21
int main() You are eligible for
{ voting....This statement is
int age;
always executed.
4. if cout << "\n Enter your age: ";
cin >> age;
if (age >= 18)
cout<< "\n You are eligible for voting ...."; Enter your age: 17
cout << "This statement is always executed."; This statement is always
return 0; executed.
}
#include <iostream>
using namespace std;
int main() Enter a number: 54
{ The given number54 is Even
int num, rem;
cout<< "\n Enter a number: ";
cin>>num;
rem = num % 2; Enter a number: 31
5. if..else if (rem==0) The given number 31 is Odd
cout<< "\n The given number" <<num<< " is
Even";
else
cout<< "\n The given number "<<num<< " is
Odd";
return 0;
}
1 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
#include <iostream>
using namespace std;
int main() Enter the Marks :70
{ Your grade is 1st class !!
int marks;
cout<<" Enter the Marks :";
cin>>marks; Enter the Marks :59
if( marks >= 60 ) your grade is 2nd class !!
6. if -else-if cout<< "Your grade is 1st class !!" <<endl;
else if( marks >= 50 && marks < 60) Enter the Marks :49
cout<< "your grade is 2nd class !!" <<endl; your grade is 3rd class !!
else if( marks >= 40 && marks < 50)
cout<< "your grade is 3rd class !!" <<endl;
else Enter the Marks :39
cout<< "You are fail !!" <<endl; You are fail !!
return 0;
}
#include <iostream>
using namespace std;
int main() Enter any two numbers: 23
7. நிப தைன { 45
ெசய றி int a, b, largest;
cout << "\n Enter any two numbers: ";
(Conditional cin >> a >> b; Largest number : 45
operator) largest = (a>b)? a : b;
cout << "\n Largest number : " << largest;
return 0;
}
#include <iostream>
using namespace std;
int main()
Enter week day number: 1
{
int num; Sunday
cout << "\n Enter week day number: ";
cin >> num; Enter week day number: 2
switch (num) Monday
{
8. switch case 1 : cout << "\n Sunday"; break; Enter week day number: 3
case 2 : cout << "\n Monday"; break; Tuesday
case 3 : cout << "\n Tuesday"; break;
case 4 : cout << "\n Wednesday"; break; Enter week day number: 4
case 5 : cout << "\n Thursday"; break;
Wednesday
case 6 : cout << "\n Friday"; break;
case 7 : cout << "\n Saturday"; break;
default: cout << "\n Wrong input....";
}
}
#include <iostream>
using namespace std;
int main ()
{ 1 2 3 4 5 6
7 8 9 10
9. for int i;
for(i = 1; i < 10; i ++ )
cout<<i<<"\t";
return 0;
}
#include <iostream>
using namespace std;
int main () 1 2 3 4 5 6
{ 7 8 9 10
int i=1;
10. while while(i<=10)
{
cout<<i<<"\t";
i+=1;
}
return 0;
}
2 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
#include <iostream>
using namespace std;
int main () 1 2 3 4 5 6
{ 7 8 9 10
int i=1;
11. do…while do
{
cout<<i<<"\t";
i+=1;
}while(i<=10);
return 0;
}
#include <iostream>
using namespace std;
12. while மட ைக
int main () The sum of 1 to 10 is 55
பய ப தி 1 த {
10 வைர உ ள int i=1,sum=0;
while(i<=10)
எ கள ெதாட
{
டைல sum=sum+i;
ெவள ய நிர i++;
எ க( The sum of 1 to
}
cout<<"The sum of 1 to 10 is "<<sum;
10 using while loop) return 0;
}
#include <iostream>
13. do-while() using namespace std;
மட கிைன int main ()
பய ப தி 10 த 1 { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
வைர உ ள எ கைள int n = 10;
do
ெவள ய ட நிர
{
எ க(display the series cout<<n<<", ";
10,9,8,…..,1 using n--;
do.while loop) }while (n>0) ;
}
# include <iostream>
using namespace std;
int main() 1 3 5 7 9
{
int n=1;
jump:
{
if(n<10)
14.go to
{
cout<<n<<'\t';
n+=2;
goto jump;
}
return 0;
}
}
# include <iostream>
using namespace std;
int main ()
{ Count : 1
15.break int count = 1; Count : 2
do Count : 3
{ Count : 4
cout<< "Count : " << count <<endl;
if( count > 3)
3 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
{
break;
}
count ++;
}while( count < 20 );
return 0;
}
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i<= 10; i++) 1 2 3 4 5 7 8 9 10
{
16. continue if (i == 6)
continue;
else
cout<<i<< " ";
}
return 0;
}
#include<iostream>
using namespace std;
int main() {
int n;
long factorial = 1.0; Enter a positive integer: 5
Factorial of 5 = 120
cout << "Enter a positive integer: ";
cin >> n;
17. ஒ
எ ண ெதாட if (n < 0)
cout << "Error! Factorial of a negative
ெப கல(Factorial)
number doesn't exist.";
கண கி C++ நிர else {
ஒ ைற எ க for(int i = 1; i <= n; ++i) {
factorial *= i;
}
cout << "Factorial of " << n << " = " <<
factorial;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n, t1 = 0, t2 = 1,t3 = 0;
cout << "Enter the number of terms: ";
cin >> n;
18. ஃப ேபானாசி எ cout << "Fibonacci Series: "; Enter the number of terms: 10
வ ைச(Fibonacci series) cout << t1 << ", "; Fibonacci Series: 0, 1, 1, 2, 3, 5,
(0 1 1 2 3 5 8 …….) cout << t2 << ", "; 8, 13, 21, 34,
for (int i = 1; i <= n-2; ++i)
க டறி C++
{
நிர ஒ ைற t3= t1 + t2;
எ க. t1 = t2;
t2 = t3;
cout << t3 << ", ";
}
return 0;
}
4 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
#include <iostream>
#include <conio.h>
using namespace std;
int main() A
{ AB
19. A int i,j,rows; ABC
AB rows=6; ABCD
ABC for(i=1; i<=rows; i++){ ABCDE
ABCD for(j=1; j<=i; j++){ ABCDEF
ABCDE cout<<((char)(j+64));
ABCDEF }
cout<< endl;
}
getch();
return 0;
}
#include<iostream>
using namespace std;
int main ()
{
int i,j; 54321
20. 5 4 3 2 1 for(i=1; i<=5; i++) 5432
5432 { 543
543 for(j=5; j>=i; j--) 54
54 {
5
5 cout<<j<<" ";
}
cout<<"\n";
}
return 0;
}
#include<iostream> Enter the Table number to print : 7
using namespace std; 1x7=7
21. ெகா க ப ட
int main( ) 2x7=14
எ ண ெப க { 3x7=21
வா பா ைட int n; 4x7=28
அ சி C++ நிர cout<<"Enter the Table number to print : "; 5x7=35
cin>>n; 6x7=42
ஒ ைற எ க 7x7=49
for(int i=1;i<=10;i++)
(Multiflication Table) cout<<i<<"x"<<n<<"="<<i*n<<endl; 8x7=56
return 0; 9x7=63
} 10x7=70
22. ப வ எ #include<iostream>
using namespace std; 1,4,7,10,13,16,19,22,25,28,31,34,
ெதாடைர int main( ) 37,40,
அ சி வத கான {
for (int i=1; i<=40 ; i+=3)
நிர கைள எ க. cout << i<<',' ;
(a) 1 4 7 10...... 40 return 0; }
#include <iostream>
using namespace std;
int sum (int x, int y)
{ return (x + y); }
int main () Enter Number 1:56
23.ெசய { Enter Number 2:45
(funtion) example int a,b ; The sum = 101
cout<<"\n Enter Number 1:";
cin>>a;
cout<<"\n Enter Number 2:";
cin >>b;
cout<<"\n The sum = "<<sum (a,b); }
5 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
#include <iostream>
using namespace std; Enter Radius :8
double area(const double r,const double
pi=3.14) The Area of Circle =200.96
{
return(pi*r*r);
24. னய }
int main ()
ெசய க {
(Default Argument) double rad,res;
cout<<"\nEnter Radius :";
cin>>rad;
res=area(rad);
cout << "\nThe Area of Circle ="<<res;
return 0;
}
#include <iostream>
using namespace std;
int sum (int x, int y)
{
return (x + y); Enter Number 1:56
} Enter Number 2:45
int main () The sum = 101
25.inline function {
int a,b ;
cout<<"\n Enter Number 1:";
cin>>a;
cout<<"\n Enter Number 2:";
cin >>b;
cout<<"\n The sum = "<<sum (a,b);
}
#include<iostream>
using namespace std;
int x=45; // Global Variable x Value of global x is 45
26. வைரெய ைல int main() Value of local x is 10
ெதள ப {
ெசய றி (Scope int x = 10; // Local Variable x
cout << "\nValue of global x is " << ::x;
resolution operator)
cout << "\n\nValue of local x is " << x;
return 0;
}
#include <iostream>
using namespace std;
27. C++ ெமாழிய 10 int main()
மதி கைள { Enter Number 1= 50
int num[10], even=0, odd=0; Enter Number 2= 51
உ ளடாக ெப
for (int i=0; i<10; i++) Enter Number 3= 52
அதி ஒ ைற { Enter Number 4= 53
எ கள எ ண க cout<< "\n Enter Number " << i+1 <<"= "; Enter Number 5= 54
ம இர ைட cin>>num[i]; Enter Number 6= 55
if (num[i] % 2 == 0) Enter Number 7= 56
எ கள ++even; Enter Number 8= 57
எ ண ைகைய else Enter Number 9= 58
கா பத கான நிர ++odd; Enter Number 10= 59
} There are 5 Even Numbers
(Count odd cout << "\n There are "<< even <<" Even There are 5 Odd Numbers
numbers &Even Numbers";
numbers). cout << "\n There are "<< odd <<" Odd
Numbers";
}
6 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
#include <iostream>
using namespace std;
class add
{
int a,b;
public:
int sum;
void getdata()
class add
{
int a,b; 151515
public:
28. உ ளைம int sum;
ெபா ள void getdata()
{
பய பா ைட a=5;
b=10;
வள நிர sum = a+b;
(The use of Local & }
} a1;
global Object) add a2;
int main()
{
add a3;
a1.getdata();
a2.getdata();
a3.getdata();
cout<<a1.sum;
cout<<a2.sum;
cout<<a3.sum;
return 0;
}
# include <iostream> Memory allocation for object p1
using namespace std; 12
class product Memory allocation for object
{ p2 12
int code, quantity;
float price;
29. ெபா கான
public:
நிைனவக இட void assignData();
ஒ கீ ைட void Print();
};
வள int main()
நிர (memory {
product p1, p2;
allocation of objects) cout<<"\n Memory allocation for object p1 "
<<sizeof(p1);
cout<<"\n Memory allocation for object p2 "
<<sizeof(p2);
return 0;
}
#include<iostream>
using namespace std; Enter the Roll Number 45
30. ெபா class X Enter the Average 55.5
{ Roll number:- 45
இய நிைலய int n; Average :- 55.5
ெதாட த float avg;
public:
(Dynamic initialization X(int p,float q)
of objects) { n=p;
avg=q;
}
7 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
void disp()
{
cout<<"\n Roll number:- " <<n;
cout<<"\n Average :- "<<avg;
}
};
int main()
{
int a ; float b;
cout<<"\nEnter the Roll Number";
cin>>a;
cout<<"\nEnter the Average";
cin>>b;
X x(a,b); // dynamic initialization
x.disp();
return 0;
}
#include<iostream>
using namespace std;
class Data
{
int i, j;
public:
int k;
Data()
{
cout<<"\n Non Parametrerized Non Parametrerized constructor
constructor"; Parametrerized constructor
i=0; Copy constructor
j=0; 0 0
} 10 20
Data(int a,int b) 10 20
{
cout<<"\n Parametrerized constructor";
i=a;
j=b;
}
31. ஆ கிகள Data(Data &a)
வைகக (Types of {
constructor) cout<<"\n Copy constructor";
i=a.i;
j=a.j;
}
void display() //member function
{
cout<<"\n"<< i<<"\t"<<j;
}
};
int main()
{
Data d1,d2(10,20),d3(d2);
d1.display();
d2.display();
d3.display();
return 0;
}
8 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
#include<iostream>
using namespace std;
class simple
{
private: Constructor of class-simple
int a, b; Enter values for a and b 10 15
public:
simple() The two integers are .. 10 15
{
a= 0 ; The sum = 25
b= 0; Destructor is executed
cout<< "\n Constructor of class-simple ";
}
void getdata()
{
cout<<"\n Enter values for a and b ";
32. ஆ கி ம cin>>a>>b;
அழி ப EXAMPLE }
(example of constructor void putdata()
{
& Destructor) cout<<"\nThe two integers are .. ";
cout<<a<<"\t"<<b<<endl;
cout<<"\n The sum = "<<a+b;
}
~simple()
{
cout<<"\n Destructor is executed ";
}
};
int main()
{
simple s;
s.getdata();
s.putdata();
return 0;
}
#include <iostream>
using namespace std;
void print(int i)
{ It is integer 10
cout<< " It is integer " << i <<endl; It is float 10.1
It is string Ten
}
void print(double f)
{
33. ெசய cout<< " It is float " << f <<endl;}
void print(string c)
பண மி (Function
{
overloading) cout<< " It is string " << c <<endl;
}
int main()
{
print(10);
print(10.10);
print("Ten");
return 0;
}
9 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
#include<iostream> Constructor without
using namespace std; parameters..
class add Parameterized constructor...
{ Copy Constructor ...
int num1, num2, sum; Enter data ... 15
public: 20
add()
{ Object a :
cout<<"\n Constructor without parameters.. The numbers are..15 20
"; The sum of the numbers are..
num1= 0; num2= 0; sum = 0; 35
} Object b :
add ( int s1, int s2 ) The numbers are..10 20
{ The sum of the numbers are..
cout<<"\n Parameterized constructor... "; 30
num1= s1; num2=s2; sum=0; Object c..
} The numbers are..10 20
add (add &a) The sum of the numbers are..
{ 30
cout<<"\n Copy Constructor ... ";
num1= a.num1;
num2=a.num2;
sum = 0;
}
void getdata()
{
cout<<"\nEnter data ... ";
cin>>num1>>num2;
34. ஆ கி }
பண மி void addition()
{
(Constructor sum=num1+num2;
overloading) }
void putdata()
{
cout<<"\n The numbers are..";
cout<<num1<<'\t'<<num2;
cout<<"\n The sum of the numbers are.. "<<
sum;
}
};
int main()
{
add a, b (10, 20) , c(b);
a.getdata();
a.addition();
b.addition();
c.addition();
cout<<"\n Object a : ";
a.putdata();
cout<<"\n Object b : ";
b.putdata();
cout<<"\n Object c.. ";
c.putdata();
return 0;
}
10 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
#include<iostream>
using namespace std;
class complex
{
int real,img;
public:
void read()
{ Enter the First Complex
cout<<"\nEnter the REAL PART : "; Number
cin>>real; Enter the REAL PART : 3
cout<<"\nEnter the IMAGINARY PART : ";
cin>>img; Enter the IMAGINARY PART :
} 4
complex operator +(complex c2)
{
complex c3; Enter the Second Complex
c3.real=real+c2.real; Number
35. ெசய றி c3.img=img+c2.img; Enter the REAL PART : 5
பண மி return c3;
(operator } Enter the IMAGINARY PART :
void display() 8
overloading) {
cout<<real<<"+"<<img<<"i";
} SUM = 8+12i
};
int main()
{
complex c1,c2,c3;
int choice, cont;
cout<<"\n\nEnter the First Complex
Number";
c1.read();
cout<<"\n\nEnter the Second Complex
Number";
c2.read();
c3=c1+c2; // binary + overloaded
cout<<"\n\nSUM = ";
c3.display();
return 0;
}
# include <iostream>
using namespace std;
class student //base class Enter roll no and name .. 12101
{ KUMAR
private :
char name[20]; Enter lang,eng,phy,che,csc,mat
int rno; marks.. 99 97 52 65 89 95 90
36. எ கா : public:
ஒ வழி மர ம void acceptname() Roll no :-12101
( Single inheritance ) { Name :-KUMAR
cout<<"\n Enter roll no and name .. ";
cin>>rno>>name; Marks Obtained
} Language.. 99
void displayname() English .. 97
{ Physics .. 52
cout<<"\n Roll no :-"<<rno; Chemistry.. 65
cout<<"\n Name :-"<<name<<endl; Comp.sci.. 89
} Maths .. 95
11 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
};
class exam : public student //derived class
with single base class
{
public:
int mark1, mark2
,mark3,mark4,mark5,mark6,total;
void acceptmark()
{
cout<<"\n Enter lang,eng,phy,che,csc,mat
marks.. ";
cin>>mark1>>mark2>>mark3>>mark4>>m
ark5>>mark6;
}
void displaymark()
{
cout<<"\n\t\t Marks Obtained ";
cout<<"\n Language.. "<<mark1;
cout<<"\n English .. "<<mark2;
cout<<"\n Physics .. "<<mark3;
cout<<"\n Chemistry.. "<<mark4;
cout<<"\n Comp.sci.. "<<mark5;
cout<<"\n Maths .. "<<mark6;
}
};
int main()
{
exam e1;
e1.acceptname(); //calling base class function
using derived class object
e1.acceptmark();
e1.displayname(); //calling base class
function using derived class object
e1.displaymark();
return 0;
}
#include<iostream>
using namespace std;
class base
{
public:
base()
{ Constructor of base class...
cout<<"\n Constructor of base class..."; Constructor of derived ...
} Constructor of derived1 ...
~base() Destructor of derived2 ...
37. ஆ கிக ,
{ Destructor of derived ...
அழி ப க cout<<"\n Destructor of base class.... "; Destructor of base class....
}
வ ைச ைற (The
};
order of constructor & class derived:public base
Destructor) {
public :
derived()
{
cout << "\n Constructor of derived ...";
}
~derived()
{
cout << "\n Destructor of derived ...";
}
12 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
};
class derived1 :public derived
{
public :
derived1()
{
cout << "\n Constructor of derived1 ...";
}
~derived1()
{
cout << "\n Destructor of derived2 ...";
}
};
int main()
{
derived1 x;
return 0;
}
38.ப வ எ #include<iostream> 1 3 5 7 9 11 13 15 17 19 21 23
using namespace std; 25 27 29 31 33 35 37 39 41 43
ெதாடைர
int main( ) 45 47 49 51 53 55 57 59 61 63
அ சி வத கான { 65 67 69 71 73 75
நிர கைள எ க. for (int i=1; i<=75 ; i+=2)
1 3 5 7...... 75 cout << i<<' ' ;
June 2019 return 0;
}
#include<iostream>
using namespace std;
int main() 5 ,10 ,15 ,20 ,25 ,30 ,35 ,40 ,45
39. ப வ எ
{ ,50 ,
ெதாடைர int i=5;
அ சி வத கான while(i<=50)
{
நிர கைள எ க.
cout <<i<<" ," ;
(While loop) i=i+5;
5,10,15,20,…..50, }
Mar - 2019
return 0;
}
#include<iostream>
40. ப வ எ
using namespace std; 21 22 23 24 25 26 27 28
ெதாடைர int main() 29 30
அ சி வத கான {
int i;
நிர கைள எ க
for(i=21;i<=30;i++)
(for loop) cout <<i<<" " ;
21 22 23 24 25……30 return 0;
sep -2021
}
Prepared by S. Saminathan M.C.A.,B.Ed.,M.Phil.,
Computer Instructor Grade I
GHSS – MUKHASAPARUR
CUDDALORE DT.
[email protected] 13 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT