第二章 开始学习C++
编程练习:
#include<iostream>
using namespace std;
int main()
{
cout << "My name is Irving Chen." << endl;
cout << "My address is SYSU." << endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
cout << "My name is Irving Chen." << endl;
cout << "My address is SYSU." << endl;
return 0;
}
#include<iostream>
using namespace std;
void mice(void);
void run(void);
int main()
{
mice();
mice();
run();
run();
return 0;
}
void mice()
{
cout << "Three blind mice" << endl;
}
void run()
{
cout << "See how they run" << endl;
}
#include<iostream>
using namespace std;
int main()
{
int age;
cout << "Enter your age: ";
cin >> age;
cout << 12*age << " months" << endl;
return 0;
}
#include<iostream>
using namespace std;
double to_Fahrenheit(double);
int main()
{
double val, fah;
cout << "Please enter a Celsius value: ";
cin >> val;
fah = to_Fahrenheit(val);
cout << val << " degrees Celsius is " << fah << " degrees Fahrenheit." << endl;
return 0;
}
double to_Fahrenheit(double val)
{
return (32.0 + 1.8*val);
}
#include<iostream>
using namespace std;
double to_Astro(double);
int main()
{
double ly;
cout << "Enter the number of light years: ";
cin >> ly;
cout << ly << " light years = " << to_Astro(ly) << " astronomical units." << endl;
return 0;
}
double to_Astro(double ly)
{
return ly*63240;
}