100% found this document useful (1 vote)
173 views10 pages

C++ Programs:: Welcome To C++ Programming Welcome To Don Bosco Egmore

The document provides 18 C++ programs to perform various calculations: 1) Print a message 2) Find the sum of 2 numbers 3) Find the product of 3 numbers 4) Find the perimeter of a rectangle 5) Calculate simple interest 6) Find the circumference of a circle 7) Find the volume of a cylinder 8) Find the volume of a cube 9) Swap two values using a third variable 10) Find the volume of a sphere

Uploaded by

Justin Benito
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
100% found this document useful (1 vote)
173 views10 pages

C++ Programs:: Welcome To C++ Programming Welcome To Don Bosco Egmore

The document provides 18 C++ programs to perform various calculations: 1) Print a message 2) Find the sum of 2 numbers 3) Find the product of 3 numbers 4) Find the perimeter of a rectangle 5) Calculate simple interest 6) Find the circumference of a circle 7) Find the volume of a cylinder 8) Find the volume of a cube 9) Swap two values using a third variable 10) Find the volume of a sphere

Uploaded by

Justin Benito
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/ 10

C++ 

Programs:  Class 11
1.  Write a C++ program to print the following message 
    Welcome to C++ Programming 
    Welcome to Don Bosco‐Egmore 
//To print a message 
# include <iostream> 
using namespace std; 
int main() 

  cout<<" Welcome to C++ Programming"<<endl; 
  cout<<” Welcome to Don Bosco‐Egmore”; 

Output :  

 
 
2.  Write a C++ program to find the sum of 2 numbers. 
//sum of 2 numbers 
# include <iostream> 
using namespace std; 
int main() 

  int a,b,c; 
  cout<<"Enter any two numbers:"; 
  cin>>a>>b; 
  c=a+b; 
  cout<<"Sum of 2 numbers = "<<c; 
  return 0; 

 
Output :  

 
3.  Write a C++ program to find the product of 3 numbers. 
//product of 3 numbers 
# include <iostream> 
using namespace std; 
int main() 

  int a,b,c,d; 
  cout<<"Enter any three numbers:"; 
  cin>>a>>b>>c; 
  d=a*b*c; 
  cout<<"Product of 3 numbers = "<<d; 
  return 0; 

 
Output :  

 
4.    Write a C++ Program to find the perimeter of a rectangle. 
//perimeter of a rectangle 
# include <iostream> 
using namespace std; 
int main() 

  float l,b,p;  
  cout<<"\n Enter Length & Breadth: ";  
  cin>>l>>b;  
  p=2*(l+b); 
  cout<<"\n Perimeter of a Rectangle = "<<p; 
  return 0; 

Output :  

 
5.    Write a C++ Program to calculate Simple Interest. 
//Simple Interest 
# include <iostream> 
using namespace std; 
int main() 

  float p,n,r,si; 
  cout<<"Enter Principal Amount:"; 
  cin>>p; 
  cout<<"Enter No. of years:"; 
  cin>>n; 
  cout<<"Enter Rate of Interest:"; 
  cin>>r; 
  si=(p*n*r)/100; 
  cout<<"Simple Interest="<<si; 
  return 0; 

Output :  

   
6.    Write a C++ Program to find the Circumference of a Circle. 
//Circumference of a Circle 
# include <iostream> 
using namespace std; 
int main() 

  float c,r; 
  cout<<"Enter Radius:"; 
  cin>>r; 
  c=2*3.14*r; 
  cout<<"Circumference of a Circle="<<c; 
  return 0; 

Output :  

  

7.    Write a C++ Program to find the Volume of Cylinder. 
//Volume of Cylinder 
# include <iostream> 
using namespace std; 
int main() 

  float v,r,h; 
  cout<<"Enter Radius & Height:"; 
  cin>>r>>h;; 
  v=3.14*r*r*h; 
  cout<<"Volume of a Cylinder="<<v; 
  return 0; 

Output :  

   
8.    Write a C++ Program to find the Volume of Cube. 
//Volume of Cube 
# include <iostream> 
using namespace std; 
int main() 

  float v,a; 
  cout<<"Enter Side:"; 
  cin>>a; 
  v=a*a*a; 
  cout<<"Volume of a Cube="<<v; 
  return 0; 

Output :  

9.    Write a C++ Program to swap two values using the third variable. 
 
//Swapping two nos using Third Variable 
# include <iostream> 
using namespace std; 
int main() 

  int a,b,c; 
  cout<<"Enter any two numbers:"; 
  cin>>a>>b; 
  c=a; 
  a=b; 
  b=c; 
  cout<<"After Swapping the values are "<<a<<"\t"<<b; 
  return 0; 

Output :  

   
10.   Write a C++ Program to find the Volume of Sphere. 
//Volume of Sphere 
# include <iostream> 
using namespace std; 
int main() 

  float v,r; 
  cout<<"Enter Radius:"; 
  cin>>r; 
  v=1.3*3.14*r*r*r; 
  cout<<"Volume of Sphere = "<<v; 
  return 0; 

Output :  

11.   Write a C++ Program to find the total marks of three subjects. 
 
# include <iostream> 
using namespace std; 
int main() 

  int m1,m2,m3,sum;  
  cout<<"\n Enter three Marks: ";  
  cin>>m1>>m2>>m3;  
  sum=m1+m2+m3;  
  cout<<"\n The sum = "<<sum; 
  return 0; 

Output :  

12.   Write a C++ Program to find the Area of Circle. 
//Area of Circle 
# include <iostream> 
using namespace std; 
int main() 
{  
  int radius;  
  float area;  
  cout<<"\n Enter Radius: ";  
  cin >> radius;  
  area = 3.14 * radius * radius;  
  cout<<"The area of circle = "<<area; 

 
Output :  

13.   Write a C++ Program to find the Curved Surface Area of a Cylinder. 
 
//Curved Surface Area of a Cylinder 
# include <iostream> 
using namespace std; 
int main() 

  float pi = 3.14, radius, height, CSA; 
  cout << "\n Curved Surface Area of a cylinder"; 
  cout << "\n Enter Radius (in cm): "; 
  cin >> radius; 
  cout << "\n Enter Height (in cm): "; 
  cin >> height; 
  CSA  = (2*pi*radius)*height; 
  cout << "\n Radius: " << radius <<"cm"; 
  cout << "\n Height: " << height << "cm"; 
  cout << "\n Curved Surface Area of a Cylinder is " << CSA <<" sq. cm."; 

 
Output :  

 
14.   Write a C++ Program to find the Perimeter & Area of a Semi Circle. 
//Perimeter & Area of a Semi Circle 
# include <iostream> 
using namespace std; 
int main() 

  int radius; 
  float pi = 3.14; 
  cout << "\n Enter Radius (in cm):"; 
  cin >> radius; 
  float perimeter = (pi+2)*radius; // dynamic initialization 
  float area = (pi*radius*radius)/2; // dynamic initialization 
  cout<<"\n Perimeter of the semicircle is "<<perimeter<<"cm"; 
  cout<<"\n Area of the semicircle is "<<area<<"sq.cm"; 

Output :  

 
 
15.   Write a C++ Program to swap two values without using the third variable. 
//Swapping two nos without using third variable 
# include <iostream> 
using namespace std; 
int main() 

  int a,b; 
  cout<<"Enter any two numbers:";   
  cin>>a>>b; 
  a=a+b; 
  b=a‐b; 
  a=a‐b; 
  cout<<"After Swapping, values are "<<a<<"\t"<<b; 
  return 0; 

 
Output :  

 
 
16.  Write a C++ Program to find the perimeter and area of a quadrant. 
 

 
 
//Area & Perimeter of a Quadrant 
# include <iostream> 
using namespace std; 
int main() 

  float r,aq,pq; 
  cout<<"Enter Radius:";   
  cin>>r; 
  aq=0.25*3.14*r*r; 
  pq=(1.57+2)*r; 
  cout<<"Area of a Quadrant = "<<aq<<endl; 
  cout<<"Perimeter of a Quadrant = "<<pq; 
  return 0; 

 
   
Output :  

 
 
17.  Write a C++ Program to find the Area of a Triangle. 
 
//Area of a Triangle 
# include <iostream> 
using namespace std; 
int main() 

  float a,b,h; 
  cout<<"Enter Base & Height:";   
  cin>>b>>h; 
  a=(b*h)/2; 
  cout<<"Area of a Triangle = "<<a; 
  return 0; 

 
Output :  

 
 
18.  Write a C++ Program to convert the temperature from Celsius to Fahrenheit. 
F = (C × 9/5) + 32
//to convert the temperature from Celsius to Fahrenheit 
# include <iostream> 
using namespace std; 
int main() 

  float c,f; 
  cout<<"Enter Celsius:";   
  cin>>c; 
  f=(c*1.8)+32; 
  cout<<"Fahrenheit = "<<f; 
  return 0; 

 
Output :  

 
19.  Write a C++ program to calculate Net Salary. 
//To Calculate Net Salary 
# include <iostream> 
# include <iomanip> 
using namespace std; 
int main() 

  float basic, da, hra, gpf, tax, gross, np; 
  char name[30]; 
  cout<<"\n Enter Basic Pay: "; 
  cin>>basic; 
  cout<<"\n Enter D.A : "; 
  cin>>da; 
  cout<<"\n Enter H.R.A: "; 
  cin>>hra; 
  gross=basic+da+hra; // sum of basic, da and hra 
  gpf=(basic+da) * 0.10; // 10% 0f basic and da 
  tax=gross*0.10; //10% of gross pay 
  np=gross‐(gpf+tax); //netpay = earnings ‐ deductions 
  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) << "Gross Pay : " << setw(10) << gross << endl; 
  cout << setw(25) << "G.P.F : " << setw(10) << gpf << endl; 
  cout << setw(25) << "Income Tax : " << setw(10)<< tax << endl; 
  cout << setw(25) << "Net Pay : " << setw(10) << np << endl; 

Output :  

 
 
20.  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. 
 
//to find the total and percentage of marks secured from 10th Std Public Exam 
# include <iostream> 
using namespace std; 
int main() 

  float regno,tamil,eng,maths,sci,ss,total,percent; 
  cout<<"Enter Reg_Number:"; 
  cin>>regno; 
   
cout<<"Enter Tamil Mark:"; 
  cin>>tamil; 
  cout<<"Enter English Mark:"; 
  cin>>eng; 
  cout<<"Enter Maths Mark:"; 
  cin>>maths; 
  cout<<"Enter Science Mark:"; 
  cin>>sci; 
  cout<<"Enter Social Mark:"; 
  cin>>ss; 
  total=tamil+eng+maths+sci+ss; 
  percent=((total/500)*100); 
  cout<<"‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐"<<endl; 
  cout<<"10th Standard Board Exam Results"<<endl; 
  cout<<"‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐"<<endl; 
  cout<<"Register Number = "<<regno<<endl; 
  cout<<"Tamil Mark = "<<tamil<<endl; 
  cout<<"English Mark = "<<eng<<endl; 
  cout<<"Maths Mark = "<<maths<<endl; 
  cout<<"Science Mark = "<<sci<<endl; 
  cout<<"Social Science Mark = "<<ss<<endl; 
  cout<<"Total Marka = "<<total<<endl; 
  cout<<"Percentage = "<<percent; 
  return 0; 

 
Output :  

 
 

You might also like