Professional Documents
Culture Documents
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int choice;
float ctemp,ftemp;
cout << "1.Celsius to Fahrenheit" << endl;
cout << "2.Fahrenheit to Celsius" << endl;
cout << "Choose between 1 & 2 : " << endl;
cin>>choice;
if (choice==1)
{
cout << "Enter the temperature in Celsius : " << endl;
cin>>ctemp;
ftemp=(1.8*ctemp)+32;
cout << "Temperature in Fahrenheit = " << ftemp << endl;
}
else if(choice==2)
{
cout << "Enter the temperature in Fahrenheit : " << endl;
cin>>ftemp;
ctemp=(ftemp-32)/1.8;
cout << "Temperature in Celsius = " << ctemp << endl;
}
else
{
cout<< “Wrong Choice!”<<endl;
}
getch();
}
Output:
1.Celsius to Fahrenheit
2.Fahrenheit to Celsius
Choose between 1 & 2 : 2
Enter the temperature in Fahrenheit : 98.6
Temperature in Celsius = 37.0000
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int choice;
float l,g;
cout << "1.Gallons to Liters" << endl;
cout << "2.Liters to Gallons" << endl;
cout << "Choose between 1 & 2 : " << endl;
cin>>choice;
if (choice==1)
{
cout << "Enter the volume in gallons : " << endl;
cin>>g;
l=g*3.7854;
cout << "Volume in Liters = " << l << endl;
}
else if(choice==2)
{
cout << "Enter the volume in liters : " << endl;
cin>>l;
g=l/3.7854;
cout << "Volume in Gallons = " << g << endl;
}
else
{
cout<< “Wrong Choice!”<<endl;
}
getch();
}
Output:
1.Gallons to Liters
2.Liters to Gallons
Choose between 1 & 2 : 1
Enter the volume in gallons : 2.5
Volume in Liters = 9.4635
#include<iostream.h>
#include<conio.h>
#include<string.h>
class complex
{
private:
float real;
float imag;
};
Output:
#include<iostream.h>
#include<conio.h>
void main()
{
int i,a=0,n;
cout<<"Enter the no. of elements in the series : ";
cin>>n;
for(i=1;i<=n;i++)
{
a=a+i;
}
cout<<"Sum of “<<n<<” natural numbers is"<<a;
getch();
}
Output:
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int a,b;
cout<<”Enter number A : “;
cin>>a;
cout<<”Enter number B : “;
cin>>b;
cout<<”Before swapping : “<<endl;
cout<<”A = “<<a;
cout<<”B = “<<b;
swap(&a,&b);
cout<<”After swapping : “<<endl;
cout<<”A = “<<a;
cout<<”B = “<<b;
getche();
}
Output:
Enter number A : 1
Enter number B : 2
Before swapping :
A=1
B=2
After swapping :
A=2
B=1
#include <iostream.h>
#include <conio.h>
class time
{
private:
int hh;
int mm;
int ss;
public:
void enter();
void disp();
friend time add(time, time);
};
void time::enter()
{
cout<<"Hours : ";
cin>>hh;
cout<<"Minutes: ";
cin>>mm;
cout<<"Seconds: ";
cin>>ss;
};
void time::disp()
{
cout<<"\n\nResultant Time :";
cout<<"\nHours : "<<hh;
cout<<"\nMinutes: "<<mm;
cout<<"\nSeconds: "<<ss;
};
void main()
{
time o,o1, o2;
clrscr();
cout<<"\nEnter the First Time :\n";
o1.enter();
cout<<"\n\nEnter the Second Time :\n";
o2.enter();
o=add(o1,o2);
o.disp();
getch();
}