1、2006 年秋 Visual C+笔试试卷一、选择题1下列叙述中,不正确的是()A 一个函数中可以有多个 return 语句B 函数可通过 return 语句返回数据C 必须用一个独立的语句来调用函数D 函数 main 也可以带有参数2下列定义变量和常量的语句中,语法正确的是()A float i, j, int k;B const int i;C int const k = 1;D #define PI=3.14159263下列对于构造函数和析构函数的叙述中,正确的是()A构造函数可以重载,析构函数不能重载B 构造函数不能重载,析构函数可以重载C 构造函数可以重载,析构函数也可以重载D构造函
2、数不能重载,析构函数也不能重载4执行以下语句时,循环的次数是()for(int x = 0, y = 0; !x B cout q;Dcout #include int isvowel(char c) return (c = a | c = e | c = i | c = o | c = u); void pluralize(char *s)int len = strlen(s);char *p = s + len - 1;char *q = s + len - 2;if(*p = h /strcat 函数实现两个字符串的拼接else if(*p = s) strcat(p, “es“);el
3、se if(*p = y)if(isvowel(*q) strcat(p, “s“);else strcpy(p, “ies“);else if(*p = z)if(isvowel(*q) strcat(p, “es“);else strcat(p, “es“);else strcat(p, “s“);void main()char word620 = “wish“,“bus“,“toy“,“navy“,“quiz“,“computer“;for(int i = 0; i void f(int j)if(!j)cout int x = 2, y = x + 30;class Aint y;st
4、atic int x;public:operator int() return x + y;A operator +(int)return A(x+, y+);A(int x = 2, int y = 3) A:x = :x + x; A:y = :y + y; void print()cout char *f(char *s, char ch)char *p = s, *q = s;while(*q = *p+) if(*q != ch) q+;return s;void main()char s1 = “Hello How are you“, s2 = “1100101 11“;cout
5、class Aint x, y;public:A(int i, int j) x = i; y = j;operator+(int) cout void fun(char *str)char min, *q, *p;( 19 )min = *p+;while(*p != 0)if( 20 )min = *p; q = p;p+;p = q;while( 21 )*p = *(p - 1);( 22 )*p = min;void main()char str80;cin.getline(str, 80);fun(str); cout #define N 20 /整数的位数void add(int
6、 sum, int a, int b); /sum = a + b;void wrt( ( 23 ) );void main()int aN = 7,5,9,8,9,7,5,0,0,9,9,0,8,8;int bN = 7,7,5,3,1,2,8,8,9,6,7,7;int sumN;add(sum, a, b);wrt(“Integer a: “, a); wrt(“Integer b: “, b);wrt(“ Sum: “, sum);void add(int sum, int a, int b)int carry = 0, i; /carry 表示进位for(i = 0; i 0 -i)
7、cout = 0; -i) cout #include struct nodechar product20; /产品名称char category10; /产品类别node *next;node *create(void) /创建链表node temp, *p2 = char product20, category10;while(1)cout product category;if(strcmp(product, “end“) = 0) break;p2-next = new node;p2 = p2-next;strcpy(p2-product, product);strcpy(p2-ca
8、tegory, category);( 27 );return temp.next;void print(node *h) /输出链表while(h)cout product category next;cout next;delete p;node *insertascategory(node *h, node *p) /按类别插入结点node *p2 = 0, *p1 = h;if(h = 0)p-next = 0; return p;while(p1 p1 = p1-next; /找同类结点while(p1 p1 = p1-next; /定位在同类结点后p-next = p1;( 29
9、); /插入在 p1,p2 结点之间return h;node *classify(node *h) /按类别分类node *h2 = 0, *p;while(h)p = h;( 30 );h2 = insertascategory(h2, p);return h2;void main(void)node *h;h = create(); print(h);h = classify(h); print(h);deletechain(h);2006 年秋 Visual C+笔试试卷参考答案一、选择题1下列叙述中,不正确的是()A 一个函数中可以有多个 return 语句B 函数可通过 retur
10、n 语句返回数据C 必须用一个独立的语句来调用函数D 函数 main 也可以带有参数2下列定义变量和常量的语句中,语法正确的是()A float i, j, int k;B const int i;C int const k = 1;D #define PI=3.14159263下列对于构造函数和析构函数的叙述中,正确的是()A构造函数可以重载,析构函数不能重载B 构造函数不能重载,析构函数可以重载C 构造函数可以重载,析构函数也可以重载D构造函数不能重载,析构函数也不能重载4执行以下语句时,循环的次数是()for(int x = 0, y = 0; !x B cout q;Dcout #in
11、clude int isvowel(char c) return (c = a | c = e | c = i | c = o | c = u); void pluralize(char *s)int len = strlen(s);char *p = s + len - 1;char *q = s + len - 2;if(*p = h /strcat 函数实现两个字符串的拼接else if(*p = s) strcat(p, “es“);else if(*p = y)if(isvowel(*q) strcat(p, “s“);else strcpy(p, “ies“);else if(*p
12、 = z)if(isvowel(*q) strcat(p, “es“);else strcat(p, “es“);else strcat(p, “s“);void main()char word620 = “wish“,“bus“,“toy“,“navy“,“quiz“,“computer“;for(int i = 0; i void f(int j)if(!j)cout int x = 2, y = x + 30;class Aint y;static int x;public:operator int() return x + y;A operator +(int)return A(x+,
13、 y+);A(int x = 2, int y = 3) A:x = :x + x; A:y = :y + y; void print()cout char *f(char *s, char ch)char *p = s, *q = s;while(*q = *p+) if(*q != ch) q+;return s;void main()char s1 = “Hello How are you“, s2 = “1100101 11“;cout class Aint x, y;public:A(int i, int j) x = i; y = j;operator+(int) cout voi
14、d fun(char *str)char min, *q, *p;( 19 ) / q = p = strmin = *p+;while(*p != 0)if( 20 ) /min *pmin = *p; q = p;p+;p = q;while( 21 ) / p str*p = *(p - 1);( 22 ) / p-*p = min;void main()char str80;cin.getline(str, 80);fun(str); cout #define N 20 /整数的位数void add(int sum, int a, int b); /sum = a + b;void w
15、rt( ( 23 ) ); / int sum, int a, int bvoid main()int aN = 7,5,9,8,9,7,5,0,0,9,9,0,8,8;int bN = 7,7,5,3,1,2,8,8,9,6,7,7;int sumN;add(sum, a, b);wrt(“Integer a: “, a); wrt(“Integer b: “, b);wrt(“ Sum: “, sum);void add(int sum, int a, int b)int carry = 0, i; /carry 表示进位for(i = 0; i 0 -i) / I = N - 1cout
16、 = 0; -i) cout #include struct nodechar product20; /产品名称char category10; /产品类别node *next;node *create(void) /创建链表node temp, *p2 = char product20, category10;while(1)cout product category;if(strcmp(product, “end“) = 0) break;p2-next = new node;p2 = p2-next;strcpy(p2-product, product);strcpy(p2-catego
17、ry, category);( 27 ); / p2 - next = 0;return temp.next;void print(node *h) /输出链表while(h)cout product category next;cout next;delete p;node *insertascategory(node *h, node *p) /按类别插入结点node *p2 = 0, *p1 = h;if(h = 0)p-next = 0; return p;while(p1 p1 = p1-next; /找同类结点while(p1 p1 = p1-next; /定位在同类结点后p-next = p1;( 29 ); /p2-next = 0 /插入在 p1,p2 结点之间return h;node *classify(node *h) /按类别分类node *h2 = 0, *p;while(h)p = h;( 30 ); / h = h - nexth2 = insertascategory(h2, p);return h2;void main(void)node *h;h = create(); print(h);h = classify(h); print(h);deletechain(h);