Professional Documents
Culture Documents
11th Computer Science Chapter 9 Study Material English Medium1
11th Computer Science Chapter 9 Study Material English Medium1
com
VOLUME – II
CHAPTER – 9
INTRODUCTION TO C++
HANDS ON PRACTICE PROGRAMS
1. Write C++ programs to interchange the values of two variables.
a. Using with third variable
Coding:
#include <iostream>
using namespace std;
int main()
{
int n1, n2, temp;
cout<<"Enter 1st Number: ";
cin>>n1;
cout<<"Enter 2nd Number: ";
cin>>n2;
//displaying numbers before swapping
cout<<"Before Swap"<<n1<<n2;
//swapping
temp=n1;
n1=n2;
n2=temp;
//displaying numbers after swapping
}
www.Padasalai.Net
cout<<"\nAfter Swap"<<n1<<n2;
system("pause");
return 0;
Coding:
#include<iostream>
using namespace std;
int main( )
{
int r;
float area,peri;
cout<<"enter radius";
cin>>r;
area = 3.14*r*r*;
peri = 2*3.14*r;
cout<<"area= "<<area;
cout<<"\n perimeter = "<<peri;
system("pause");
return 0;
}
www.Padasalai.Net
float area;
cout<<"Enter height and base : ";
cin>>height>>base;
area= (0.5)*height*base;
cout<<"Area of triangle is : "<<area;
system("pause");
return 0;
}
Page 2
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
3. Write a C++ to find the total and percentage of marks you secured from
10th Standard Public Exam. Display all the marks one-by-one along with
total and percentage. Apply formatting functions.
Coding:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int rollno,tam,eng,mat,sci,soc,total;
float percentage;
char name[20], div[10];
cout << "Input the Roll Number of the student :";
cin >> rollno;
cout << "Input the Name of the Student :";
cin >> name;
cout << "Input the marks of Tamil, English, Maths, Science, & Social";
cin >>tam>>eng>>mat>>sci>>soc;
total=tam+eng+mat+sci+soc;
percentage = total/5.0;
if (percentage >= 60)
strcpy(div,"First");
else if (percentage < 60 && percentage >= 48)
strcpy(div,"Second");
www.Padasalai.Net
else if (percentage <48 && percentage >= 36)
strcpy(div,"Pass");
else
strcpy(div, "Fail");
cout << "Roll No : "<< rollno <<endl << "Name of Student : " << name <<endl;
cout << "Marks in Tamil : "<<tam<< endl;
cout << "Marks in English : "<<eng<< endl;
cout << "Marks in Maths : "<<mat<< endl;
cout << "Marks in Science : "<<sci<< endl;
cout << "Marks in Social Science : "<<soc<< endl;
cout << "Total Marks = " << total <<endl;
cout << "Percentage = " << percentage <<endl;
cout << "Division = " << div <<endl;
system("pause");
return 0;
}
CHAPTER – 10
FLOW OF CONTROL
HANDS ON PRACTICE PROGRAMS
1. Temperature – conversion program that gives the user the option of
converting Fahrenheit to Celsius or Celsius to Fahrenheit and depending
upon user's choice.
Page 3
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
Coding:
#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"1. For Celsius To Fahrenheit. \n";
cout<<"2. For Fahrenheit To Celsius. \n";
cout<<"3. For Exit\n\n";
cout<<"Enter Your Choice \n ";
cin>>a;
switch(a)
{
double cel,feh;
case 1:
cout<<"Enter The Temperature In Celsius\n";
cin>>cel;
feh=(cel*9/5)+32;
cout<<"\nTemperature In Fahrenheit Is = "<<feh ;
break;
case 2:
cout<<"Enter The Temperature In Fahrenheit\n";
cin>>feh;
cel=(feh-32)*5/9;
www.Padasalai.Net
cout<<"\nTemperature In Celsius Is = "<<cel ;
break;
case 3:
exit(0);
default:cout<<"\nEnter The Right Choice \n";
break;
}
system("pause");
return 0;
}
2. The program requires the user to enter two numbers and an operator.
It then carries out the specified arithmetical operation: addition,
subtraction, multiplication or division of the two numbers. Finally, it
displays the result.
Coding:
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
char ch;
cout<<”Enter the Two Numbers”;
cin>>a>>b;
cout<<”\nEnter the Choice”;
Page 4
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
cout<<”\nAddition(+)”;
cout<<”\nSubtraction(-)”;
cout<<”\nMultiplication(*)”;
cout<<”\nDivision(/)”;
cin>>ch;
switch(ch)
{
case „+‟:
c=a+b;
cout<<”\nThe Addition of two numbers are=”<<c;
break;
case „-„:
c=a-b;
cout<<”\nThe Subtraction of two numbers are=”<<c;
break;
case „*‟:
c=a*b;
cout<<”\nThe Multiplication of two numbers are=”<<c;
break;
case „/‟:
c=a/b;
cout<<”\nThe Division of two numbers are=”<<c;
break;
default:
cout<<”\nYou chose the Wrong Character”;
} www.Padasalai.Net
break;
system(“pause”);
return 0;
}
Page 5
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
}
else
{
cout<<ch<<”is special character”;
}
system("pause");
return 0;
}
www.Padasalai.Net
char ch;
cout<<"Enter any character: ";
cin>>ch;
if(ch>=65&&ch<=90)
cout<<endl<<"You entered an uppercase character";
else if(ch>=48&&ch<=57)
cout<<endl<<"You entered a digit";
else if(ch>=97&&ch<=122)
cout<<endl<<"You entered a lowercase character";
else
cout<<endl<<"You entered a special character";
system("pause");
return 0;
}
Page 6
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
www.Padasalai.Net
#include<iostream>
using namespace std;
int main()
{
int i,n;
cout<<"enter the value of the integer";
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
cout<<i<<endl;
}
system("pause");
return 0;
}
Page 7
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
A B C D E 5
A B C D E F
a) Coding:
#include<iostream>
using namespace std;
int main()
{
char ch='A';
int n;
for(int i=1;i<=6;i++)
{
ch = 'A';
for(int j=1;j<=i;j++)
{
cout<< ch<< " ";
ch++;
}
cout<< "\n";
}
system("pause");
return 0;
Page 8
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
b) Coding:
#include<iostream>
using namespace std;
int main()
{
for(int i=1;i<=5;i++)
{
for(int j=5;j>=i;j--)
{
cout<<j<<"\t";
}
cout<<"\n";
}
system("pause");
return 0;
}
c) Coding:
#include<iostream>
using namespace std;
int main()
{
www.Padasalai.Net
int n;
for(int i=4,sp=0;i>0;i--,sp++)
{
for(int k=0;k<=sp;k++)
cout<<" "<<" ";
for(int j = 1;j<2*i ;j++)
{
cout<<"#"<<" ";
}
cout<<"\n";
}
system("pause");
return 0;
}
Page 9
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
{ www.Padasalai.Net
using namespace std;
int main()
for(int i=21;i<=30;i++)
{
cout<<i<<”\n”;
}
system(“pause”);
return 0;
}
Page 10
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
PART – III
3. Write a C++ program to print multiplication table of a given number.
Coding:
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the Number To Find Multiplication Table ";
cin>>n;
for(int i=1;i<=10;i++)
{
cout<<n<<" * "<<i<<" = "<<n*i<<endl;
}
return 0;
}
www.Padasalai.Net
clrscr();
int i,a=-1,b;
for(i=1;i<=40;i+=3)
{
a*=-1;
b=i;
b*=a;
cout<<b<<" ";
}
system(“pause”);
return 0;
}
PART – IV
3. Write a program to find the LCM and GDC of two numbers.
Coding:
//Program to find the LCM
#include <iostream>
using namespace std;
int main()
{
int n1, n2, max;
cout << "Enter two numbers: ";
cin >> n1 >> n2;
max = (n1 > n2) ? n1 : n2;
Page 11
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
do
{
if (max % n1 == 0 && max % n2 == 0)
{
cout << "LCM = " << max;
break;
}
else
++max;
} while (true);
return 0;
}
Coding:
//Program to find the GCD
#include <iostream>
using namespace std;
int main()
{
int n1, n2;
cout << "Enter two numbers: ";
cin >> n1 >> n2;
while(n1 != n2)
{
else www.Padasalai.Net
if(n1 > n2)
n1 -= n2;
n2 -= n1;
}
cout << "GDC = " << n1;
return 0;
}
Page 12
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
if(i%2==0)
ans+=(pow(-1,j))*((pow(x,i))/(fact));
}
cout<<"\n The sum of the series is:"<<ans;
return 0;
}
www.Padasalai.Net
5. Write a program to find sum of the series
S = 1 + x + x2 +..... + xn
Coding:
#include <iostream>
using namespace std;
int main()
{
clrscr();
long i,n,x,sum=1;
cout<<“1+x+x^2+……+x^n”;
cout<<“\n Enter the value of x and n:”;
cin>>x>>n;
for(i=1;i<=n;++i)
sum+=pow(x,i);
cout<<“\n Sum=”<<sum;
system(“pause”);
return 0;
}
CHAPTER – 11
FUNCTIONS
HANDS ON PRACTICE PROGRAMS
Page 13
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
1. Program that reads two strings and appends the first string to the
second. For example, if the first string is entered as Tamil and second
string as nadu, the program should print Tamilnadu. Use string library
header.
Coding:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char s1[ ]=”Tamil”,s2[ ]=”nadu”;
strcat(s1,s2);
puts(s1);
system("pause");
return 0;
}
{
www.Padasalai.Net
int main()
char ch;
cout<<"Enter the Character";
ch=getchar();
cout<<"The Character is changed to Upper Case="<<toupper(ch);
system("pause");
return 0;
}
Page 14
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
}
www.Padasalai.Net
cout<<"\nThe Return Value of isalnum(ch) is :"<<r;
Page 15
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html
www.Padasalai.Net www.TrbTnpsc.com
{
if(a<b)
a=0;
else
b=0;
}
7. Program that invokes a function calc ( ) which intakes two integers and
an arithmetic operator and prints the corresponding result.
Coding:
#include<iostream>
using namespace std;
void calc(int x, int y)
{
int z;
z=x+y;
cout<<”The Sum of the Two Integers are=”<<z;
}
int main()
{
int a,b;
cout<<”Enter the Two Integers”;
cin>>a>>b;
www.Padasalai.Net
calc(a,b);
system(“pause”);
return 0;
}
Page 16
http://www.trbtnpsc.com/2018/06/latest-plus-one-11th-study-materials-tamil-medium-english-medium-new-syllabus-based.html