2.7.1
#include <iostream>
using namespace std;
int main()
{
cout << "姓名:张三" << endl;
cout << "地址:武汉" << endl;
return 0;
}
2.7.2
#include <iostream>
using namespace std;
int main()
{
int distance; //以long为单位
cin >> distance;
cout << distance << " long = " << distance * 220 << "码" << endl;
return 0;
}
2.7.3
#include <iostream>
void func1();
void func2();
int main()
{
func1();
func1();
func2();
func2();
return 0;
}
void func1()
{
std::cout << "Three blind mice" << std::endl;
}
void func2()
{
std::cout << "See how they run " << std::endl;
}
2.7.4
#include <iostream>
using namespace std;
int main()
{
int age;
cout << "Enter your age: ";
cin >> age;
cout << "It is " << age * 12 << " months" << endl;
return 0;
}
2.7.5
void convert(double n);
int main()
{
double celsius;
cout << "Please enter a Celsius value: ";
cin >> celsius;
convert(celsius);
return 0;
}
void convert(double n)
{
cout << n << " degrees Celsius is " << n * 1.8 + 32.0 << " degrees Fahrenheit." << endl;
}
2.7.6
#include <iostream>
using namespace std;
void convert(double n);
int main()
{
double lightyear;
cout << "Enter the number of light years: ";
cin >> lightyear;
convert(lightyear);
return 0;
}
void convert(double n)
{
cout << n << " light years = " << n * 63240 << " astronomical units." << endl;
}
2.7.7
#include <iostream>
using namespace std;
void showInfo(int hour, int minute);
int main()
{
int hour;
int minute;
cout << "Enter the number of hours: ";
cin >> hour;
cout << "Enter the number of minutes: ";
cin >> minute;
showInfo(hour, minute);
return 0;
}
void showInfo(int hour, int minute)
{
cout << "Time: " << hour << ":" << minute << endl;
}