1、1中山大学授予学士学位工作细则第六条考 试 作 弊 不 授 予 学 士 学 位计 算 机 科 学 系 2009 上 学 期 程 序 设 计 I 期 末 考 试 试 题 (A)任 课 教 师 : 肖 菁 、 吴 维 刚 考 试 形 式 : 闭 卷 考 试 时 间 : 2 小 时年级: 09 专业: 计科、网工、信安 姓名: _ 学号: _成绩 _ 1. Single Answer Questions (Only one choice is correct). 20points.Choose the alternative(s) that best completes the statement
2、or answers the question.1) _ translates high-level language program into machine language program. A) CPU B) A compiler C) An assembler D) The operating system 2) _ is an object-oriented programming language. A) Pascal B) Java C) Ada D) C 3) Which of the following is a valid user-defined identifier?
3、 A) _343 B) 9X C) 8+9 D) class 4) To improve readability and maintainability, you should declare _ instead of using literal values such as 3.14159. A) classes B) constants C) variables D) functions 5) What is the value of (double)(5/2)? A) 2.5; B) 2.0; C) 2; D) 3; E) 3.0; 6) Suppose x is a char vari
4、able with a value b. What is the printout of the statement cout 0)if (y 0)cout 0 and y 0“;else if (z 0)cout 0“; A) x 0 and y 0; B) x 0; C) no printout. D) x =5) D) (x = 1) | (x != 1) 10) What is the value of “1.0 + 1.0 + 1.0 = 3.0“? A) true B) false C) There is no guarantee that 1.0 + 1.0 + 1.0 = 3.
5、0 is true.11) What is the execution result of the following statements? char *p =”abcdefgh”; p+=3;cout#include using namespace std;int countVowels(char *text)int novowels;for(int x =0; xstr; /Get the text string from keboardcout#include using namespace std;enum TYPE CAT, DOG, TORTOISE, OTHER;class P
6、etpublic:Pet()strcpy(name, “unknown“);age = 0;type = OTHER;Pet(char *name, int age,TYPE type)strcpy(this-name, name);this-age=age;this-type=type;516)17)18)19)20)21)22)23)24)25)26)27)28)29)30)31)32)33)34)35)36)37)38)39)40)return 0;void showSound()switch (type)case CAT:coutusing namespace std;int num
7、=0;void func1()static int num_1=0;num_1+;num+;6cout using namespace std;int func(int number, int sn)int factor;if(number = 1) return 1;factor =2;while(number %factor!=0) factor+;if(sn =0) coutusing namespace std;7#define MAXWIN 3class Windowpublic:Window()coutn;if (is_circle_num(n,10)else cout”false
8、”endl;return 0; 95. Programming design. 20points.Please write a program to handle an Addressbook. What to do?1. Design a class Addressbook that encapsulates your friends information, e.g. name, phone number, address;a) The class should provide functions to read information from keyboard and set the
9、data fields accordingly;b) The class should also provide a function to print your friends information in your addressbook into a file named “output.txt”. 2. Write a main function to show how to create Addressbook objects and call the functions.a) Your friends information is originally input from keyboard.Requirements and hints:1. Make sure that the data fields are marked as private to protect them from illegal access. 2. You are required to store 3 friends information in your addressbook.