2.6 复习题
1,函数
2,用iostream文件的内容替换该行
3,使std名称空间中的名称都可用 /使得程序可以使用std名称空间中的定义
4,cout<<"Hello,world"<<endl;
5,int cheeses;
6,cheeses=32;
7,cin>>cheeses;
9,返回值类型 形参类型,形参个数,函数名称
10,返回值类型为void时
11,未在函数中添加using namespace std;语句 /在函数中添加using ... /在函数外添加using.../使用std::cout<<打印语句
2.7 编程练习
#include<iostream>
using namespace std;
int main()
{
cout<<"张先仙"<<endl;
cout<<"广东省肇庆市";
return 0;
}
#include<iostream>
using namespace std;
int main()
{
long x;
cout<<"请输入一个以long为单位的距离:\n";
cin>>x;
cout<<x<<" long为: ";
cout<<x*220<<"码";
return 0;
}
#include<iostream>
using namespace std;
void fun1()
{
cout<<"Three blind mice\n";
}
void fun2()
{
cout<<"See how they run"<<endl;
}
int main()
{
fun1();
fun1();
fun2();
fun2();
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int age;
cout<<"Enter your age:";
cin>>age;
cout<<endl;
cout<<age*12<<" month";
return 0;
}
#include<iostream>
using namespace std;
double fun(int val) {
return 1.8*val+32.0;
}
int main()
{
int val;
cout<<"Please enter a Celsius value:";
cin>>val;
cout<<endl;
cout<<val<<" degrees Celsius is "<<fun(val)<<" degrees Fahreheit\n";
return 0;
}
,
#include<iostream>
using namespace std;
void fun(int a,int b) {
cout<<"Time: "<<a<<":"<<b;
}
int main()
{
int hours,minutes;
cout<<"Enter the number of hours:";
cin>>hours;
cout<<"Enter the number of minutes:";
cin>>minutes;
cout<<endl;
fun(hours,minutes);
return 0;
}