2.7.1
#include <iostream>
using namespace std;
int main(void)
{
cout << "姓名:XXX" << endl;
cout << "地址:XXX" << endl;
return 0;
}
2.7.2
#include <iostream>
using namespace std;
int main(void)
{
cout << "请输入以long为单位的距离:";
int temp;
cin >> temp;
cout << "转换为码后: " << temp * 220 << endl;
return 0;
}
2.7.3
#include <iostream>
using namespace std;
void One(void);
void Two(void);
int main(void)
{
One();
One();
Two();
Two();
return 0;
}
void One(void)
{
cout << "Three blind mice" << endl;
}
void Two(void)
{
cout << "See how they run" << endl;
}
2.7.4
#include <iostream>
using namespace std;
int main(void)
{
cout << "请输入您的年龄:";
int year;
cin >> year;
cout << year << "年有" << year * 12 << "个月" << endl;
return 0;
}
2.7.5
#include <iostream>
using namespace std;
int Fahrenheit(int);
int main(void)
{
cout << "Please enter a Celsius value: ";
int Fah;
cin >> Fah;
cout << Fah << " degrees Celsius is " << Fahrenheit(Fah) << " degrees Fahrenheit." << endl;
return 0;
}
int Fahrenheit(int num)
{
return num * 1.8 + 32;
}
2.7.6
#include <iostream>
using namespace std;
double Astronomy(double);
int main(void)
{
cout << "Enter the number of light years:";
double Ast;
cin >> Ast;
cout << Ast << " light years = " << Astronomy(Ast) << " astronomical units." << endl;
return 0;
}
double Astronomy(double num)
{
return num * 63240;
}
2.7.7
#include <iostream>
using namespace std;
void ShowTime(int, int);
int main(void)
{
int hour, min;
cout << "Enter the number of hours: ";
cin >> hour;
cout << "Enter the number of minutes: ";
cin >> min;
ShowTime(hour, min);
return 0;
}
void ShowTime(int hour, int min)
{
cout << "Time: " << hour << ':' << min << endl;
}