Chapter 2
2.1
#include <iostream>
int main()
{
using namespace std ;
cout << "XWG\n" << "HZAU";
cin.get();
return 0;
}
2.2
#include <iostream>
int main()
{
using namespace std;
double lon;
cin >> lon;
cout << lon << "long = " << lon * 220 << "m";
cin.get();
cin.get();
return 0;
}
2.3
#include <iostream>
using namespace std;
void s();
void t();
int main()
{
t();
t();
s();
s();
cin.get();
}
void t()
{
cout << "Three blind mice\n";
}
void s()
{
cout << "See how they run\n";
}
2.4
#include <iostream>
int main()
{
using namespace std;
int age;
cout << "Enter your age: ";
cin >> age;
cout << endl << age << " age include " << age * 12 << " month";
cin.get();
cin.get();
}
2.5
#include <iostream>
double C2F(double);
int main()
{
using namespace std;
double Celsius, Fahrenheit;
cout << "Please enter a Celsius value: ";
cin >> Celsius;
Fahrenheit = C2F(Celsius);
cout << Celsius << " degrees Celsius is " << Fahrenheit << " degrees Fahrenheit.";
cin.get();
cin.get();
}
double C2F(double Celsius)
{
return 1.8 * Celsius + 32;
}
2.7
#include <iostream>
using namespace std;
void out(int, int);
int main()
{
int minutes, hours;
cout << "Enter the number of hours: ";
cin >> hours;
cout << "Enter the number of minutes: ";
cin >> minutes;
out(hours, minutes);
cin.get();
cin.get();
}
void out(int hours, int minutes)
{
cout << "Time: " << hours << ":" << minutes;
}