2.1
#include<iostream>
using std::cout;
using std::endl;
int main()
{
cout<<"My Name is :"<<endl<<"My address is:"<<endl;
return 0;
}
2.2
#include<iostream>
using std::cout;
using std::endl;
using std::cin;
int main()
{
double l;
int yard = 22;
cin>>l;
cout<<yard * l << endl;
return 0;
}
2.3
#include<iostream>
using std::cout;
using std::endl;
void Print1()
{
cout<<"Three blind mice"<<endl;
}
void Print2()
{
cout<<"See how they run"<<endl;
}
int main()
{
Print1();
Print1();
Print2();
Print2();
return 0;
}
2.4
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int age, months;
cout<<"Enter your age: ";
cin>>age;
months = age * 12;
cout<<months<<endl;
return 0;
}
2.5
#include<iostream>
#include<iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
using std::setprecision;
double f(double C)
{
return 1.8 * C + 32.0;
}
int main()
{
double C, F;
cout.setf(ios::fixed);
cout<<"Please Enter a Celsius value: ";
cin>>C;
cout<<setprecision(1)<<C<<" degrees Celsius is "<<setprecision(1)<<f(C)<<" degrees Fahrenheit"<<endl;
return 0;
}
2.6
#include<iostream>
#include<iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
using std::setprecision;
double f(double C)
{
return C * 63240;
}
int main()
{
double LightYear, F;
cout.setf(ios::fixed);
cout<<"Enter the number of light years: ";
cin>>LightYear;
cout<<setprecision(1)<<LightYear<<" light years is "<<f(LightYear)<<" astronomical units"<<endl;
return 0;
}
2.7
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
void Time(int h, int m)
{
cout<<"Time: "<<h<<":"<<m<<endl;
}
int main()
{
int h, m;
cin>>h>>m;
Time(h, m);
return 0;
}