Sunday, 21 January 2018

C++ program for Std VIII

1. Write  a program to add two numbers given by the user.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
c=a+b;
cout<<"Sum "<<c<<"\n";
getch();
}

2. Write a program to calculate the area of a Rectangle.
#include<iostream.h>
#include<conio.h>
void main()
{
int l,b,a,;
clrscr();
cout<<"Enter Length";
cin>>l;
cout<<"Enter Breadth";
cin>>b;
a=l*b;
cout<<"Area of Rectangle "<<a<<"\n";
getch();
}

3.Write a program to calculate the area of a Circle.
#include<iostream.h>
#include<conio.h>
void main()
{
float r,ar;
clrscr();
cout<<”enter radius”;
cin>>r;
ar=22/7*r*r;
cout<<”area of circle”<<ar<<endl;
getch();
}

4.Write a program to calculate the area and perimeter of a Rectangle.
#include<iostream.h>
#include<conio.h>
void main()
{
int l,b,a,p;
clrscr();
cout<<"Enter Length";
cin>>l;
cout<<"Enter Breadth";
cin>>b;
a=l*b;
p=2*(l+b);
cout<<"Area of Rectangle "<<a<<"\n";
cout<<"Perimeter of Rectangle "<<p<<"\n";
getch();
}

5.Write a program to find the total and average of a student who has appeared for three
   subjects.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
clrscr();
cout<<"Enter Marks Of A";
cin>>a;
cout<<"Enter Marks of B";
cin>>b;
cout<<”Enter Marks of C;
cin>>c;
d=a+b+c;
cout<<”Total Marks of Three Subjects<<d;
e=(a+b+c)/2;
cout<<”Average Marks Of Three Subjects”<<e;
getch();
}

6. Write a program to find the third angle of a triangle if the two angles is given by the user.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
cout<<”enter angle 1”;
cin>>a;
cout<<”enter angle 2”;
cin>>b;
c=a+b;
d=180-c;
cout<<”Third Angle”<<d<<endl;
getch();
}

7. Write a program to convert meter to centimeter.
#include<iostream.h>
#include<conio.h>
void main()
{
float m,cm;
clrscr();
cout<<”enter meter”;
cin>>m;
cm=m*100;
cout<<”centimeter=”<<cm<<endl;
getch();
}

8. Write a program to convert hour into minutes and seconds.
#include<iostream.h>
#include<conio.h>
void main()
{
int h,m,s;
clrscr();
cout<<”enter hours”;
cin>>h;
m=h*60;
cout<<”Hours In Minutes”<<m<<endl;
s=h*60*60;
cout<<”Hours In Seconds”<<s<<endl;
getch();
}

9. Write a program to convert kilometer to yards.
#include<iostream.h>
#include<conio.h>
void main()
{
float  km,y;
cout<<”enter kilometer”;
cin>>km;
y=1094*km;
cout<<”yards=”<<y<<endl;
getch();
}

10.  Write a program to convert centigrade temperature to Fahrenheit temperature
#include<iostream.h>
#include<conio.h>
void main()
{
int c.f;
clrscr();
cout<<"enter temperature in centigrade";
cin>>c;
f=(9*c)/5+32;
cout<<"temperature in farenhiet"<<f;
getch();
}  

11.   Write a program to convert seconds into Hour, Minute, and Seconds
#include<iostream.h>
#include<conio.h>
void main()
{
int s,m,hr,rs;
clrscr();
cout<<"enter seconds";
cin>>s;
m=s/60;
rs=s%60;
hr=s/3600
rs=s%3600;
cout<<"time in minutes"<<m;
cout<<"time in hour"<<hr;
cout<<"time in seconds"<<rs;
getch();
}

12.    Write a program to convert centimeter to meter and Centimeter
#include<iostream.h>
#include<conio.h>
void main()
{
int cm,m,rcm;
clrscr();
cout<<"enter length in centimeter";
cin>>cm;
m=cm/100;
rcm=cm%100;
cout<<"length in meter"<<m;
cout<<"length in centimeter"<<rcm;
getch();
}

13.    Write a program, A person goes to Bank to withdraw certain amount of money. If the bank gives the change in Rs 2000 , Rs 500, Rs 100, Rs 50. Find out how many note the person receives
#include<iostream.h>
#include<conio.h>
void main()
{
int amt,thoutwo,fivhun,hun,fifty;
clrscr();
cout<<"enter amount to be withdrawn";
cin>>amt;
thoutwo =amt/2000;
amt =amt%2000;
fivhun =amt/500;
amt =amt%500;
hun =amt/100;
amt=amt%100;
fifty =amt/50;
cout<<"2000*"<<thoutwo<<endl;
cout<<"500*"<<fivhun<<endl;
cout<<"100*"<<hun<<endl;
cout<<"50*"<<fifty<<endl;
getch();
}

1. Write a program to check whether the person is eligible to vote or not.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter age”;
cin>>a;
if(a>=18)
cout<<”Eligible”;
else
cout<<”not Eligible”;
getch();
}

2. Write a program to check whether the person is rich or poor on his salary. If the salary is less than or equal to 10000 consider him poor else rich.
#include<iostream.h>
#include<conio.h>
void main()
{
int s;
cout<<”enter salary”;
cin>>s;
if(s<=10000)
cout<<”poor”;
else
cout<<”rich”;
getch();

3. Write a program to check whether the person will get commission on no commission on his Sales. If sales is greater than 50000 he will get commission else no commission.
#include<iostream.h>
#include<conio.h>
void main()
{
int s;
cout<<”enter sales”;
cin>>s;
if(s>50000)
cout<<”he will get commission ”;
else
cout<<”he will not get commission”;
getch();
}

4. Write a program to check whether the person is eligible to vote or not. If the person is not eligible to vote find out how many years he has to wait.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter the age of the person”;
cin>>a;
if(a<=18)
cout<<”he/she have to wait”<<(18-a);
else
cout<<”eligible for vote”;
getch();
}

5. Write a program to check whether the student has passed or failed on his marks. If yhe total mark is greater  than or equal to 180 consider his pass or else fail.
#include<iostream.h>
#include<conio.h>
void main()
{
inta,b,c,d;
cout<<”enter the first mark”;
cin>>a;
cout<<”enter the second mark”;
cin>>b;
cout<<”enter the third mark”;
cin>>c;
d=a+b+c;
if(d>=180)
cout<<”pass”;
else
cout<<”fail”;
getch();
}

6.       Write a program to check whether the number is odd or not.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter the number”;
cin>>a;
if(a%2==0)
cout<<”even number”;
else
cout<<”odd”;
getch();
}

7.       Write a program to check whether the number is divisible by 5 or not.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter the number”;
cin>>a;
if(a%5==0)
cout<<”divisible by 5”;
else
cout<<”not divisible by 5”;
getch();
}

8.   Write a program to check whether the person has made profit or loss or no profit or loss. If the cost price and selling price is entered by user.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter cost price”;
cin>>a;
cout<<”enter selling price”;
cin>>b;
if(a>b)
cout<<”loss”;
else if(b>a)
cout<<”profit”;
else
cout<<”no profit no loss”;
getch();
}

9. Write a program to find out the greatest angle of the triangle if the angles is given by the user
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,max;
cout<<"Enter the three angles of the triangle";
cin>>a>>b>>c;
if(a>b && a>c)
max=a;
else if(b>a && b>c)
max=b;
else
max=c;
cout<<"The greatest angle of the triangle is "<<max;
getch();
}

10. Write a program to find whether a person is child, teen, youth, or old on his age. If his age is less than 14 consider is as child, between 14 to 20 both inclusive teen, between 21 to 45 both inclusive youth and above 45 old
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<"enter age";
cin>>a;
if(a<14)
cout<<"child";
else if(a>14 && a<21)
cout<<"teen";
else if(a>25 && a<45)
cout<<"youth";
else
cout<<"old";
getch();
}

11. Write a program to accept the three sides of the triangle and find whether it is equilateral, isosceles, scalene
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,max;
cout<<"Enter the three angles of the triangle";
cin>>a>>b>>c;
if(a==b && a==c && b==c)
cout<<”equilateral”;
else if(a==b || a==c || b==c)
cout<<”isosceles”;
else
cout<<”scalene”;
getch();
}