1 选择题
1.1 C语言中,字符(char)型数据在计算机内存中的存储形式是:
A) 反码 B) 补码 C) EBCDIC码 D) ASCII码
1.2 C语言中,下列不合法的字符常量是
A) '\xff' B) 'y=' C) '&' D) '\028'
(8进制转义表示的字符只能是0-7,'\028'的字符实际变成了'8')
1.3 下列关于常成员函数的描述中,正确的是:
A) 常成员函数只能修改常数据成员;
B) 常成员函数只能修改一般数据成员;
C) 常成员函数不能修改任何数据成员;
D) 常成员函数只能通过常对象调用;
1.4 虚函数必须是类的 _____
A) 成员函数
B) 友元函数
C) 构造函数
D) 析构函数
1.5 已知类X成功地重载了–、=、+和这几个运算符,则其中肯定属于成员函数的运算符是____
A) +和=
B) 和后置++
C) =和
D) 前置–和
1.6 如果表达式–x/y中的“–”和“/”都是作为作为友元函数重载的运算符,采用运算符函数调用格式时,请表达式为______
A) operator/(x.operator–(),y)
B) operator/(operator–(x),y)
C) x.operator–().operator/(y)
D) y.operator/(operator–(x))
1.7 关于类模板,下列表述中不正确的是_____________
A) 类模板中声明的类称为模板类;
B) 类模板只能有虚拟类型参数;
C) 类模板本身在编译中不会生成任何代码;
D) 类模板的成员函数都是模板函数;
1.8 C++流中重载了运算符<<,它是一个______
A) 用于输出操作的成员函数
B) 用于输入操作的成员函数
C) 用于输入操作的非成员函数
D) 用于输出操作的非成员函数
2 填空
2.1 C语言中的标识符可分为关键字、用户定义标识符、预定义标识符三部分;
2.2 设变量a的二进制数是00101101,若想通过运算a^b使a的高四位取反,低四位保持不变,则b的二进制数就是11110000;
2.3 模板类求三个数中的最大值
template <class T> class G3{ T data; public: G3(T a,T b,T c); T getData(){ return data; } }; template<class T> G3<T>::G3(T a,T b,T c){ if(a>b && a>c) data = a; else if(b>c) data = b; else data = c; }
3 判断题
3.1 关键字是编程语言中预先定义并实现一定功能的一类单词。
3.2 一个变量的作用域的开始位置完全取决于变量定义语句的位置。
3.3 标准库函数fgets(s,n,f)的功能是:从文件f中读取长度不超过n-1的字符串存入指针s所指的内存。
3.4 若fp是指向某文件的指针,且已读到文件的开发,则库函数feof(fp)的返回值是非零值;
3.5 公有继承时基类中的private成员在派生类中仍是private的。 F,不可访问;
3.6 派生类的默认继承方式是private;
3.7 虚函数不得声明为静态函数;
4 填写程序的输出结果
4.1 嵌套循环使用同一循环控制变量的问题
#include <iostream> using namespace std; int main() { int x = {5,4,3,2,1}; int i,*p,m=0; for(p=x,i=1;p+i<=x+4;i++) { cout<<*(p+i); for(i=0;i<4;i++){ m+=p; cout<<"\t"<<m; } } getchar(); return 0; } /* 4 5 9 12 14 */
4.2 esle的悬挂问题
#include <iostream> using namespace std; int main() { int a=2,b=-1,c=2; if(a<b) if(b<0) c=0; else c+=1; cout<<c<<endl; getchar(); return 0; }
4.3 strlen函数的实现以'\0‘为结束标志
printf("%d\n",strlen("s\n\016\0end")); // 3
4.4 基类和派生类都封装有类对象的构造和析构顺序
#include <iostream> using namespace std; class Data { public: Data(int x){ Data::x = x; cout<<"Data cons."<<endl; } ~Data(){ cout<<"Data des."<<endl; } private: int x; }; class Base { public: Base(int x):dl(x){ cout<<"Base cons."<<endl; } ~Base(){ cout<<"Base des."<<endl; } private: Data dl; }; class Derived:public Base { public: Derived(int x):Base(x),d2(x){ cout<<"Derived cons."<<endl; } ~Derived(){ cout<<"Derived des."<<endl; } private: Data d2; }; int main() { { Derived obj(5); } getchar(); } /* Data cons. Base cons. Data cons. Derived cons. Derived des. Data des. Base des. Data des. */
4.5 函数传值(对象),调用默认构造函数
#include <iostream> using namespace std; class CC{ public: CC(){cout<<'1'; } ~CC(){ cout<<'0'; } }; void test(CC c){ cout<<'2'; } int main() { { CC c; test(c); } fflush(stdin); getchar(); } /* 1200 */
5 编程题
5.1 输出一个二位数的平方根表:
#include <fstream> #include <iomanip> #include <cmath> using namespace std; void sqrttable(){ ofstream table("c:\\sqrtTable.txt",ios_base::trunc); table<<" |"; int i; for(i=0;i<10;i++) table<<setw(5)<<i<<" "; table<<endl<<"-----+"; for(i=0;i<10;i++){ table<<"----------"; } table<<fixed<<setprecision(6); for(i=0;i<10;i++){ table<<endl<<setw(2)<<i<<" |"; for(int j=0;j<10;j++) table<<setw(10)<<sqrt(i*10+j); } table.close(); system("c:\\sqrtTable.txt"); } int main() { sqrttable(); }
-End-
本文【计算机二级c语言题库及答案_c语言计算机二级题库】由作者: 悲观锁 提供,本站不拥有所有权,只提供储存服务,如有侵权,联系删除!
本文链接:https://www.cuoshuo.com/blog/4295.html