北京市住房和城乡建设厅官方网站,建筑图纸怎样识图,上海外贸服装,做网站给女朋友目录
复习题
1.C程序的模块叫什么#xff1f;
2.#include 预处理器编译指令的用处#xff1f;
3.using namespace std; 该语句是干什么用的#xff1f;
4.什么语句可以打印一个语句hello,world#xff0c;然后重新换行#xff1f;
5.什么语句可以用来创…目录
复习题
1.C程序的模块叫什么
2.#include 预处理器编译指令的用处
3.using namespace std; 该语句是干什么用的
4.什么语句可以打印一个语句hello,world然后重新换行
5.什么语句可以用来创建名为cheeses的整型变量
6.什么语句可以用来将值32赋值给cheeses
7.从键盘输入的值读入变量cheeses中的语句是
8.写出打印We have X varieties of cheese的语句其中X是当前输入值。
9.下面的函数原型指出了关于函数的哪些信息
10.定义函数时是什么情况下不必使用关键字return
11.假设main()函数包含以下代码
第二章编程练习
我的题解test01-07对应相应题号
复习题
1.C程序的模块叫什么
答C 程序的模块叫做函数。2.#include 预处理器编译指令的用处
答在编译之前将iostream里面的文件内容替换编译指令iostream为内置类型类型对象提供了输入输出支持同时也支持文件的输入输出类的设计者可以通过对iostream库的扩展来支持自定义类型的输入输出操作。3.using namespace std; 该语句是干什么用的
答using 是预编译器指令使得程序使用std名称空间中的定义4.什么语句可以打印一个语句hello,world然后重新换行
//第一种
couthello,world\n;//第二种
couthello,worldendl;
5.什么语句可以用来创建名为cheeses的整型变量
int cheeses;
6.什么语句可以用来将值32赋值给cheeses
cheeses 32;
7.从键盘输入的值读入变量cheeses中的语句是
cincheeses;
8.写出打印We have X varieties of cheese的语句其中X是当前输入值。
coutWe have cheese varieties of cheeseendl;
9.下面的函数原型指出了关于函数的哪些信息
int froop(double t); void rattle(int n); int prune(void);
int froop(double t); /*指出函数在调用需要输入的参数是double类型函数的返回值是一个int类型。*/void rattle(int n); /*函数调用是需要输入的参数是int类型函数无返回值。*/int prune(void); /*不接受任何参数的输入函数的返回值是int类型*/
10.定义函数时是什么情况下不必使用关键字return
当函数的返回值的类型是void时不用在函数中使用return。
11.假设main()函数包含以下代码
cout请输入你的PIN;
而编译器指出cout是一个未知标识符导致该问题的原因是写出可能的三种情况并给出解决办法
答案
原因
未使用using命名空间解决方案
1. 函数开头添加 using namespace std;
2. cout对象前添加 using std::cout
3. 在cout对象前添加 std::cout
第二章编程练习
1. 编写一个C程序它显示您的姓名和地址。
2. 编写一个C程序它要求用户输入一个以long为单位的距离然后将它转换为码一long等于220码。
3. 编写一个C程序它使用3个用户定义的函数包括main()并生成下面的输出
Three blind mice
Three blind mice
See how they run
See how they run
其中一个函数要调用两次该函数生成前两行另一个函数也被调用两次并生成其余的输出。
4. 编写一个程序让用户输入其年龄然后显示该年龄包含多少个月如下所示
Enter your age: 29
5. 编写一个程序其中的main()调用一个用户定义的函数以摄氏温度值为参数并返回相应的华氏温度值。该程序按下面的格式要求用户输入摄氏温度值并显示结果
Please enter a Celsius value: 20
20 degrees Celsius is 68 degrees Fahrenheit.
下面是转换公式
华氏温度 1.8 * 摄氏温度 32.0
6. 编写一个程序其main()调用一个用户定义的函数以光年值为参数并返回对应天文单位的值。该程序按下面的格式要求用户输入光年值并显示结果
Enter the number of light yeras: 4.2
4.2 light years 265608 astronomical units.
天文单位是从地球到太阳的平均距离约150000000公里或93000000英里光年是光一年走的距离约10万亿公里或6万亿英里除太阳外最近的恒星大约离地球4.2光年。请使用double类型转换公式为
1光年 63240天文单位
7. 编写一个程序要求用户输入小时数和分钟数。在main()函数中将这两个值传递给一个void函数后者以下面这样的格式显示这两个值
Enter the number of hours: 9
Enter the number of minutes: 28
Time: 9:28
我的题解test01-07对应相应题号
#includeiostream
using namespace std;void test01()
{cout name endl;cout address endl;
}void test02()
{int l;cout 请输入一个以long为单位的距离: ;cin l;cout l * 220 码 endl;
}void test03_1()
{cout Three blind mice endl;
}void test03_2()
{cout See how they run endl;
}void test04()
{int age;cout Enter your age : ;cin age;cout 您的年龄转化为月共有 age * 12 个月 endl;
}void test05()
{int T;cout Please enter a Celsius value : ;cin T;cout T degrees Celsius is T*1.832 degrees Fahrenheit. endl;
}void test06()
{double y;cout Enter the number of light years: ;cin y;cout y light years y * 63240 astronomical units. endl;}void test07()
{int h, m;cout Enter the number of hours : ;cin h;cout Enter the number of minutes : ;cin m;cout Time: h : m endl;
}
int main()
{test01();test02();test03_1();test03_1();test03_2();test03_2();test04();test05();test06();test07(); return 0;
}运行结果