Saturday, June 2, 2018

C++ SET 2 FOR ENGINEERING STUDENTS

 SET – 2
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 whether the year is leap year or not.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter the year”;
cin>>a;
if(a%4==0)
else if(a%100==0)
else if(a%400==0)
cout<<”leap year”;
else
cout<<”not a leap year”;
getch();
}

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

10.   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
cout<<”profit”;
getch();
}

17. 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;
max=a>b?(a>c?a:c):(b>c?b:c);
cout<<"The greatest angle of the triangle is<<" "<<max;
getch();
}

19. Write a program to find the bill for the telephone. The telephone charges Rs. 275 from all households and allows 100 units free. If the unit exceeds 100 Rs. 2.00 is charged for extra unit above 100 along with Rs. 275
#include<iostream.h>
#include<conio.h>
void main()
{
double u,b;
cout<<"enter units consumed";
cin>>u;
if(u<=100)
b=275;
else
b=275+(u-100)×2.00;
cout<<"final bill";
getch();
}
20. Write a program to find the traveling allowance for a employee. The company gives the traveling allowance on the following table
Distance  Amount
<=20        Rs. 200
>20 & <=50 Rs 200 + Rs 3 per extra kilometer above 20
>50 & <=100 Rs 500 + Rs 3 per extra kilometer above 50
>100        Rs 10 per kilometer
#include<conio.h>
void main()
{
int d,b;
cout<<"enter distance";
cin>>d;
if(d<=20)
b=200;
else if(d>20&&d<=50)
b=200+(d-20)×3;
else if(d>50&&d<=100)
b=500+(d-50)×3;
else
b=d×10;
cout<<"final bill";
getch();
}

22. 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();
}

Wednesday, May 30, 2018

c++ SET 1 FOR ENGINEERING STUDENTS

 SET 1
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 calculate the total resistance of a circuit if the two resistors are    connected in series and connected in parallel.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float  r1,r2,a,b;
cout<<”Enter Resistor 1”;
cin>>r1;
cout<<”Enter Resistor 2”;
cin>>r2;
a=r1+r2;
cout<<”Total Resistance When Resistors Are Connected In Series”<<a<<endl;
b=(r1*r2)/(r1+r2);
cout<<”Total Resistance When Resistors Are Connected In Parallel”<<b<<endl;
getch();
}

7. 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();
}

8.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();
}

9. 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();
}

10. 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();
}

11.  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";
     getch();
     }  
12.    Write a program to convert yards to meter and kilometer
 #include<iostream.h>
     #include<conio.h>
     void main()
     {
     int y.km.m;
     clrscr();
     cout<<"enter length in yard";
     cin>>y;
     km=y*0.0009144
     cout<<"length in kilomtre"<<km;
     m=y*0.9144
     cout<<"length in metre"<<m;
     getch();
     }
17.    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();
     }
18.    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();
     }

20.    Write a program, A person goes to Bank to withdraw certain amount of money. If the bank gives the change in Rs 5 and Re 1 find out how many 5 Rs note and how many 1 Re note the person receives
     #include<iostream.h>
     #include<conio.h>
     #include<math.h>
     void main()
     {
     int amt,hun,fif,ten,two,one;
     clrscr();
     cout<<"enter amount to be withdrawn";
     cin>>amt;
     hun=amt/100;
     amt=amt%100;
     fif=amt/50;
     amt=amt%50;
     ten=amt/10;
     amt=amt%10;
     two=amt/2;
     amt=amt%2;
     one=amt/1;
     amt=amt%1;
     cout<<"100*"<<hun<<endl;
     cout<<"50*"<<fif<<endl;
     cout<<"10*"<<ten<<endl;
     cout<<"2*"<<two<<endl;
     cout<<"1*"<<one<<endl;
     getch();
     }