第二章
第一题:
#include <iostream>
using namespace std;
int main()
{
cout<<"Horace.Kem"<<" Ganjiang East Road NO.333, Suzhou, Jiangsu, China";
}
第二题:
#include <iostream>
using namespace std;
int main()
{
int dist;
cout<<"Please enter the distance in long:";
cin>>dist;
cout<<"The distance in yards is:"<<220*dist<<endl;
}
第三题:
#include <iostream>
using namespace std;
void fun1();
void fun2();
int main()
{
fun1();
fun1();
fun2();
fun2();
}
void fun1()
{
cout<<"Three blind mice"<<endl;
}
void fun2()
{
cout<<"See how they run"<<endl;
}
第四题:
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Enter your age: ";
cin>>age;
cout<<"The number of months is: "<<12*age<<endl;
}
第五题:
#include <iostream>
using namespace std;
int main()
{
double Celsius,Fahrenheit;
cout<<"Please enter a Celsius value: ";
cin>>Celsius;
Fahrenheit=1.8*Celsius+32;
cout<<Celsius<<" degrees Celsius is "<<Fahrenheit<<
" degrees Fahrenheit"<<endl;
}
第六题:
#include <iostream>
using namespace std;
double astro(double);
int main()
{
double lightyear,astronomical;
cout<<"Enter the number of light years: ";
cin>>lightyear;
astronomical=astro(lightyear);
cout<<lightyear<<" light years = "<<
astronomical<<" astronomical units."<<endl;
}
double astro(double ly)
{
return 63240*ly;
}
第七题:
#include <iostream>
using namespace std;
void clock(int,int);
int main()
{
int hours,minutes;
cout<<"Enter the number of hours: ";
cin>>hours;
cout<<"Enter the number of minutes: ";
cin>>minutes;
clock(hours,minutes);
}
void clock(int h,int m)
{
cout<<"Time: "<<h<<":"<<m<<endl;
}