编程考试试卷
计算机二级
编号
试卷名称
题数
编号
试卷名称
题数
-
1213 全国计算机等级考试《二级C++语言程序设计》46
-
1197 全国计算机等级考试《二级Java语言程序设计》真题(五)40
-
1196 全国计算机等级考试《二级Java语言程序设计》真题(四)40
-
1195 全国计算机等级考试《二级Java语言程序设计》真题(三)40
-
1194 全国计算机等级考试《二级Java语言程序设计》真题(二)40
-
1193 全国计算机等级考试《二级Java语言程序设计》真题(一)40
-
1192 计算机二级Python语言程序设计模拟试卷47
-
1179 C语言《公共基础知识》数据库设计基础120
-
1178 C语言《公共基础知识》软件工程基础86
-
1177 C语言《公共基础知识》程序设计基础26
-
1176 C语言《公共基础知识》数据结构与算法126
-
1175 全国计算机等级考试《二级C语言程序设计》模拟试题(十)43
-
1174 全国计算机等级考试《二级C语言程序设计》模拟试题(九)43
-
1173 全国计算机等级考试《二级C语言程序设计》模拟试题(八)43
-
1172 全国计算机等级考试《二级C语言程序设计》模拟试题(七)43
-
1171 全国计算机等级考试《二级C语言程序设计》模拟试题(六)43
-
1170 全国计算机等级考试《二级C语言程序设计》模拟试题(五)43
-
1169 全国计算机等级考试《二级C语言程序设计》模拟试题(四)43
-
1168 全国计算机等级考试《二级C语言程序设计》模拟试题(三)42
-
1167 全国计算机等级考试《二级C语言程序设计》模拟试题(二)43
-
1166 全国计算机等级考试《二级C语言程序设计》模拟试题(一)42
-
1165 全国计算机等级考试《二级C语言程序设计》真题(六)43
-
1164 全国计算机等级考试《二级C语言程序设计》真题(五)43
-
1163 全国计算机等级考试《二级C语言程序设计》真题(四)43
-
1162 全国计算机等级考试《二级C语言程序设计》真题(三)43
-
1161 全国计算机等级考试《二级C语言程序设计》真题(二)43
-
1160 全国计算机等级考试《二级C语言程序设计》真题(一)43
-
1159 C语言文件31
-
1158 C语言位运算29
-
1157 C语言结构体和共用体70
最新题目 更多
-
若变量a的定义为“int a=8;”,则下列逻辑表达式中其值为false的 是( )。
-
请使用“答题”菜单或使用VC6打开考生文件夹proj3下的工程文件proj3,其中包含了类Integers和主函数main的定义。一个Integers对象就是一个整数的集合,其中包含0个或多个可重复的整数。成员函数 add将一个元素添加到集合中,成员函数remove从集合中删除指定的元素(如果集合中存在该元素),成员函数 filter去除集合中的所有负整数。请编写这个filter函数。此程序的正确输出结果应为:5 28 2 -4 5 3 2 -75 27 66 315 28 2 -4 5 3 2 -75 27 66 31 65 28 2 -4 5 3 2 -75 27 66 31 6 -195 28 2 -4 5 3 -75 27 66 31 6 -19 45 28 2 -4 5 3 -75 27 66 31 6 -19 45 28 2 5 3 27 66 31 6 4要求: 补充编制的内容写在//********333********与//********666******** 两行之间。不得修改程序的其他部分。 注意:相关文件包括:main.cpp、Integers.h。 程序最后已经调用WriteToFile函数,使用另一组不同的测试数据, 将不同的运行结果输出到文件out.dat中。输出函数writeToFile已经编译 为obj文件。 部分源程序如下:/**********code.c**********/ # include "Integers.h" # include <iomanip> Integers::Integers(int data[], int size): counter(0){ for(int i=0; i<size; i++) add(data[i]); } void Integers::add(int element){ if(counter<MAXELEMENTS) elemK[counter++] = element; } void Integers::remove(int element){ int j; for(j = counter - 1; j >= 0; j --) if(elem[j] == element) break; for(int i = j; i<counter - 1; i++) elem[i] = elem[i+1]; counter -- ; } void Integers::filter(){ //**********333********** //**********666********** } void Integers::show() const{ for(int i = 0; i<getCount(); i++) cout<<setw(4)<<getElement(i); cout<<endl; } int main(){ int d[] = {5,28,2,-4,5,3,2,-75,27,66,31}; Integers s(d,11); s.show(); s.add(6); s.show(); s.add(-19); s.show(); s.remove(2); s.show(); s.add(4); s.show(); s.filter(); s.show(); writeToFile("k:\k01\61010001\"); return 0; } /**********code.c**********/结果文件out.dat内容如下:0,27,-2,9,67,62 ,
-
请使用“答题”菜单或使用VC6打开考生文件夹proj3下的工程文件proj3,其中声明了CDeepCopy类,它是一个用于表示动态数组的类。请编写其中的复制构造函数。要求:补充编制的内容写在//********333********与//********666********两行之间。不得修改程序的其他部分。注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。部分源程序如下:/**********code.c**********/ # include "CDeepCopy.h" CDeepCopy :: ~CDeepCopy() { delete[] p ;} CDeepCopy:: CDeepCopy(int k) { n = k; p = new int[n]; } //构造函数实现 CDeepCopy:: CDeepCopy(const CDeepCopy& r) //复制构造函数 { /*******333*******/ /*******666*******/ } int main() { CDeepCopy a(2),d(3); a.p[0] = 1; d.p[0] = 666 //对象 a,d 数组元素的赋值 { CDeepCopy b(a); a.p[0] = 88 ; cout<<b.p[0] //显示内层局部对象的数组元素 } cout<<d.p[0]; //显示 d 数组元素 a.p[0] 的值 cout<<"d fade away:\n"; cout<<a.p[0] //显示 a 数组元素 a.p[0] 的值 writeToFile("k:\k01\61010001\"); return 0 } 结果文件 out.dat 内容如下: 5222 d fade away: 66 /**********code.c**********/
-
请使用“答题”菜单或使用VC6菜单打开考生文件夹proj2下的工程 proj2。此工程包含一个程序文件 main.cpp,其中有日期类Date、人员 类Person以及排序函数sortByAge和主函数main的定义。请在程序中的横 线处填写适当的代码,然后删除横线,以实现该程序。此程序的正确 输出结果应为:排序前:张三 男 出生日期:1978年4月20日王五 女 出生日期:1965年8月3日杨六 女 出生日期:1965年9月5日李四 男 出生日期:1973年5月30日排序后:张三 男 出生日期:1978年4月20日李四 男 出生日期:1973年5月30日杨六 女 出生日期:1965年9月5日王五 女 出生日期:1965年8月3日注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动“//**********found**********”。源程序如下:# include <iostream> using namespace std; class Date{ // 日期类 int year, month, day; // 年、月、日 public: Date(int year, int month, int day):year(year),month(month),day(day){} int getYear()const{ return year; } int getMonth()const{ return month; } int getDay()const{ return day; } }; class Person{ // 人员类 char name[14]; // 姓名 bool is_male; // 性别,为 true 时表示男性 Date birth_date; // 出生日期 public: Person(char * name, bool is_male, Date birth_date) //**********found********** strcpy(this -> name, _________); } const char * getName()const{ return name; } bool isMale()const{ return is_male; } Date getBirthdate()const{ return birth_date; } int compareAge(const Person &p)const{ //比较两个人的年龄,返回正数、0或负数,分别表示大于、等于和小于 int n; n = p.birth_data.getYear() - birth_data.getYear(); if( n != 0 ) return n ; //**********found********** ___________________________ if( n != 0 ) return n ; return p.birth_data.getDay() - birth_data.getDay(); } void show(){ cout<<endl; cout<<name<<' '; //显示姓名 //**********found********** << ___________________ //显示性别(“男”或“女”,双引号内不含空格) <<"出生日期" //显示出生日期 <<birth_date.getYear()<<"年" <<birth_date.getMonth() << "月" <<birth_date.getDay()<<"日"; } }; void sortByAge(Person ps[], int size){ //将人员数组按年龄由小到大顺序排序 //采用挑选排序算法 for(int i=0; i<size-1; i++ ){ int m = i; for(int j = i+1; j<size; j ++ ) if(ps[j].compareAge(ps[m])<0) m = j; if(m>i){ //**********found********** Person p = ______________________; ps[m] = ps[i]; ps[i] = p; } } } int main(){ Person staff[] = { Person("张三", true, Date(1978, 4, 20)), Person("王五", false, Date(1965,8,3)), Person("杨六", false, Date(1965,9,5)), Person("李四", true, Date(1973,5,30)) }; const int size = sizeof(staff)/sizeof(staff[0]); int i; cout<<endl<<"排序前:"; for(i=0; i<size; i++) staff[i].show(); sortByAge(staff,size); cout<<endl<<endl<<"排序后:"; for(i=0; i<size; i++) staff[i].show(); cout<<endl; return 0; }
-
请使用“答题”菜单或使用VC6菜单打开考生文件夹proj2下的工程 proj2,其中包含抽象类Shape的声明,以及在此基础上派生出的类 Rectangle和Circle的声明,两者都有计算对象面积的函数GetArea()和 计算对象周长的函数GetPerim()。The area of the Circle is 78.5The perimeter of the Circle is 31.4The area of the Rectangle is 24The perimeter of the Rectangle is 20注意:只能在横线处填写适当的代码,不要改动程序中的其他内 容,也不能删除或移动“//**********found**********”。 源程序如下:# include <iostream> using namespace std; class Shape { public: Shape(){} ~Shape(){} //**********found********** __________ float GetArea() = 0 //**********found********** __________ float GetPerim () = 0 }; class Circle : public Shape { public: Circle(float radius) : itsRadius(radius){ } ~Circle(){ } float GetArea() { return 3.14 * itsRadius * itsRadius; } float GetPerim () { return 6.28 * itsRadius; } private: float itsRadius; }; class Rectangle : public Shape { public: //**********found********** Rectangle(float len, float width): __________ {}; ~Rectangle(){}; virtual float GetArea() { return itsLength * itsWidth; } float GetPerim () { return 2 * itsLength + 2 * itsWidth; } virtual float GetLength() { return itsLength; } virtual float GetWidth() { return itsWidth; } private: float itsWidth; float itsLength; }; int main() { //**********found********** __________ sp = new Circle(5); cout << "The area of the Circle is " << sp -> GetArea () << endl; cout << "The perimeter of the Circle is " << sp -> GetPerim () << endl; delete sp; sp = new Rectangle(4, 6); cout << "The area of the Rectangle is " << sp -> GetArea() << endl; cout << "The perimeter of the Rectangle is " << sp -> GetPerim () << endl; delete sp; return 0; }
-
请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程文件 proj1,程序中位于每个“//ERROR*********found*********”下的语句行 有错误,请加以更正。更正后程序的输出应该是: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只能修改每个“//ERROR*********found*********”下的那一 行,不要改动程序中的其他内容。源程序如下:# include <iostream> using namespace std; class StudentInfo { protected: // ERROR ********* found ********* char Name[30] ; int Age; int ID; int CourseNum; float Record; public: // ERROR ********* found ********* void StudentInfo (char * name , int age, int ID , int courseNum , float record ); ~StudentInfo( ) { delete [ ] Name ; } float AverageRecord( ) { return Record/CourseNum; } void show( ) const; }; StudentInfo :: StudentInfo ( char * name, int age, int ID, int courseNum, float record) { Name = strdup(name); Age = age; this -> ID = ID; CourseNum = courseNum; Record = record; } // ERROR ********* found ********* void StudentInfo::show( ) { cout << "Name: " << Name << " " << "Age: " << Age << " " << " ID: " << ID << " CourseNum: " <<CourseNum<< " Record: " <<Record<< endl; } int main() { StudentInfo st("Smith",21,99999,12,970); st.show(); return 0; }
-
请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程文件 proj1。此工程包含程序文件 main.cpp,其中有类Door和主函数main的 定义。程序中位于每个“//ERROR*********found*********”下的语句行 有错误,请加以更正。更正后程序的输出应该是: 打开503号门...门是锁着的,打不开。打开503号门的 锁...锁开了。 打开503号门...门打开了。 打开503号门...门是开着的,无须再开门。 锁上503号门...先关门...门锁上了。 注意:只能修改每个“//ERROR********found*********”下的那一 行,不要改动程序中的其他内容。# include<iostream> using namespace std ; class Door{ int num; // 门号 bool closed; // true 表示门关着 bool locked; // true 表示门锁着 public: // ERROR ********* found ********* Door(int n) : num(n), closed(true), lock(true) { } bool isClosed( ) const { return closed; } // 门关着时返回 true,否则返回 false bool isOpened( ) const { return ! closed; } // 门开着时返回 true,否则返回 false bool isLocked( ) const{ return locked; } // 门锁着时返回 true,否则返回 false bool isUnlocked( ) const { return ! locked; } // 门未锁时返回 true,否则返回 false // ERROR ********* found ********* void open( ) const { // 开门 cout << endl << "打开" << num << "号门..."; if ( ! closed ) cout << "门是开着的,无须再开门。"; else if (locked) cout << "门是锁着的,打不开。"; else { closed = false; cout << "门打开了。"; } } void close ( ) { // 关门 cout << endl << "关上" << num << "号门..."; if(closed) cout << "门是关着的,无须再关门。"; else{ closed = true; cout << "门关上了。"; } } void lock( ) const { // 锁门 cout << endl << "锁上" << num << "号门..."; if(locked) cout << "门是锁着的,无须再锁门。"; else{ // ERROR ********* found ********* if(closed){ cout<<"先关门..."; closed = true; } locked = true; cout << "门锁上了。"; } } void unlock( ) { // 开锁 cout<< endl << "打开" << num << "号门的锁..."; if ( ! locked ) cout << "门没有上锁,无须再开锁。"; else{ locked = false; cout << "锁开了。"; } } }; int main( ) { Door door(503); door.open( ); door.unlock( ); door.open( ); door.open( ); door.lock( ); return 0; }
-
下列关于函数的说法中,正确的是( )。
-
下列关于构造函数的说法中,正确的是( )。
-
下列关于函数模板的说法,正确的是( )。
-
下列不属于C++预定义的流对象的是( )。
-
下列不属于C++关键字的是( )。
-
若变量a的定义为“int a=8;”,则下列逻辑表达式中其值为false的 是( )。
-
有如下程序段:int i = 2; do{ i *= i; cout<<'#'; if(i>1000)break; }while(1) ;运行这个程序段时,输出字符‘#’的个数是( )。
-
有如下程序段:int*a=new int[2]; a[0]=0; a[1]=1; int**b=&a: cout<<**b;运行这个程序段将输出( )。
-
已知函数foo定义如下:void foo ( int a,int&b,int*c) { a++; b++; (*c) ++; }且有如下程序段:int a=1,b=2,c=3; foo (a,b,&c) ; cout<<a<<b<<c;运行这个程序段的输出是( )。
-
已知类MyClass的定义如下:# include<iostream> using namespace std; class MyClass { private : static int static_data; const int const_data; public: MyClass ( int d ) : const_data ( d ) { } static void foo1 ( ) { cout << const_data ; //① } void foo2 ( ) const { cout << static_data ; //② } }; int MyClass :: static_data = 0 ;下列说法中正确的是( )。
-
已知类Base和类Derived的定义如下:class Base { int n ; public : Base ( int d ) : n( d ) { } } ; class Derived : public Base { public : ______________ } ;其中横线处应为类Derived的构造函数的定义。在下列构造函数的定义 中,正确的是( )。
-
已知类CC以成员函数方式重载了二元运算符*,c1和c2是CC类的 两个对象,则下列对该运算符的调用中错误的是( )。
-
已知类模板Test定义如下:template<typename T1,typename T2> class Test{ public: void foo(T2 t); };则以下针对foo函数的类外定义中语法正确的是( )。
-
有如下输出语句:cout<<setw(5)<<fixed<<setprecigion(3)<<3.1415926;此语句的输出结果是( )。
-
已知类MyClass的定义如下:class MyClass { private : int num ; public : MyClass ( int d ) : num ( d ) { } MyClass ( const MyClass& original ) : num ( original . num ) { } friend void print ( MyClass c ) { cout << c.num } } ;且有如下程序段:MyClass c(5) ; MyClass *p1; p1=&c; print(*p1) ; print(c) ;运行这个程序段的过程中,对类MyClass的复制构造函数的调用次数是 ( )。
-
已知类Test的定义如下:class Test{ private : static int num ; public : void print ( int num ) { cout << ++ num ; cout << ++ this -> num; } }; int Test::num=0;且有如下程序段:int main(){ Test t1,t2; t1.print(0); t2.print(1); return 0; }运行这个程序段的输出是( )。
-
已知类CC和函数test的定义如下:class CC { public : CC( ) { cout << '1'; } ~CC( ) { cout << '0'; } }; void test ( CC c ) { cout << '2'; }且有如下main函数:int main(){ CC c; test(c); return 0; }运行这个main函数的输出是( )。
-
已知类AA和BB的定义如下:class AA { public: AA(){cout<<'0';} ~AA(){cout<<'1';} }; class BB:public AA { public: BB(){cout<<'2';} ~BB(){cout<<'3';} };且有如下主函数定义:int main(){ BB b; return 0; }运行这个main函数的输出是( )。
-
已知类Base、Middle和Derived的定义如下:class Base { public : virtual void foo ( ) { cout << 'a'; } } ; class Middle : public Base { public : void foo ( ) { cout << 'b'; } } ; class Derived : public Middle { public : void foo ( ) { cout << 'c'; } } ;且有如下程序段:Base * p1; Middle * p2; Derived d; p1 = &d; p1 -> foo( ); p2 = &d; p2 -> foo( );运行这个程序段的输出是( )。
-
类Base及其派生类Derived的定义如下:class Base { private : int a ; public : int b ; friend class Derived ; } ; class Derived : public Base { public : void foo( ) { a = 0;//① b = 0;//② } } ;则下列说法正确的是( )。
-
已知类Time的定义如下:class Time { //时间类 private: int hour , minute , second ;//时、分、秒 public : Time ( int h , int m , int s ) : hour( h ), minute( m ), second( s ) { } ____________{ switch ( index ) { case 0 : return hour; case 1: return minute; default: return second; } } };其中横线处应为下标访问运算符[]的重载函数的函数头,横线处应填入 的代码是( )。
-
已知类Array的定义如下:class Array { public : int data[ 2 ]; Array( int n = 0 ) { int start ; if ( n <= 1 ) start = n - 1; else start = n; data[ 0 ] = start ; data[ 1 ] = start + 1 ; } };且有如下程序段:Array arr(2); cout<<arr.data[0]<<arr.data[1];则执行这个程序段的输出是( )。
-
有如下定义: int a[5]= 1,3,5,7,9),* p=a; 下列表达式中不能得到数值5的是( )。