复习题
1 函数
2 用iostream头文件的内容替换源代码中的#include语句
3 使std名称空间中的内容全部直接可用
4 std::cout<<"hello world"<<endl;
5 int cheeses;
6 cheeses=32;
7 std::cin>>cheeses;
8 std::cout<<"We have "<<cheeses<<"varieties of cheese,";
9 参数数量和类型,返回值的类型
10 main函数可以省略 返回值为void的函数可以不使用
11 没指定名称空间
std::cout
using namespace std
using std::cout
编程练习
1
#include<iostream>
int main(void)
{
std::cout<<"姓名"<<std::endl<<"地址"<<std::endl;
return 0;
}
2
#include<iostream>
int main(void)
{
using namespace std;
int i;
cout<<"input a distance in long\n";
cin>>i;
cout<<"the distance is "<<i*220<<"foot"<<endl;
return 0;
}
3
#include<iostream>
void blind(void);
void see(void);
int main(void)
{
blind();
blind();
see();
see();
return 0;
}
void blind(void)
{
using namespace std;
cout<<"Three blind mice"<<endl;
}
void see(void)
{
using namespace std;
cout<<"See how they run"<<endl;
}
4
#include<iostream>
int main(void)
{
using namespace std;
int age;
cout<<"Enter your age: ";
cin>>age;
cout<<"it has "<<age*12<<"months"<<endl;
return 0;
}
5
#include<iostream>
double reverse(double);
int main(void)
{
using namespace std;
double c;
cout<<"please enter a Celsius value: ";
cin>>c;
cout<<c<<" degree Celsius is "<<reverse(c)<<" degree Fahrenheit."<<endl;
return 0;
}
double reverse(double i)
{
return i*1.8+32;
}
6
#include<iostream>
double reverse(double);
int main(void)
{
using namespace std;
double l;
cout<<"Enter the number of light years: ";
cin>>l;
cout<<l<<" light years = "<<reverse(l)<<" astronomical units."<<endl;
return 0;
}
double reverse(double i)
{
return i*63240;
}
7
#include<iostream>
void showtime(int,int);
int main(void)
{
using namespace std;
int h,m;
cout<<"Enter the number of hours: ";
cin>>h;
cout<<"Enter the number of minutes: ";
cin>>m;
showtime(h,m);
return 0;
}
void showtime(int i,int j)
{
std::cout<<"Time: "<<i<<":"<<j<<std::endl;
}