编程考试试卷
计算机二级
编号
试卷名称
题数
编号
试卷名称
题数
-
1155 C语言数组77
-
1154 C语言中用户标识符的作用域和存储类29
-
1153 C语言对函数的进一步讨论21
-
1152 C语言字符串92
-
1151 C语言地址和指针42
-
1150 C语言函数38
-
1149 C语言字符型数据35
-
1148 C语言循环结构62
-
1147 C语言选择结构61
-
1146 C语言顺序结构33
-
1145 C程序设计的初步知识120
-
1144 C语言程序设计基本概念27
-
1115 2024年3月全国计算机等级考试真题(二级C语言)43
-
1113 2023年9月全国计算机等级考试真题(二级C语言)55
-
1112 2023年3月全国计算机等级考试真题(二级C语言)43
-
1111 2022年9月全国计算机等级考试真题(二级C语言)43
-
1046 2022年3月全国计算机等级考试真题(二级C语言)43
-
1043 2021年9月全国计算机等级考试真题(二级C语言)43
-
1041 2021年3月全国计算机等级考试真题(二级C语言)43
-
1040 2020年9月全国计算机等级考试真题(二级C语言)43
-
1039 2020年3月全国计算机等级考试真题(二级C语言)43
-
1038 2019年9月全国计算机等级考试真题(二级C语言)43
-
1037 2019年3月全国计算机等级考试真题(二级C语言)43
-
1036 2018年9月全国计算机等级考试真题(二级C语言)43
-
1035 2018年3月全国计算机等级考试真题(二级C语言)43
-
1034 2017年9月全国计算机等级考试真题(二级C语言)43
-
1033 2017年3月全国计算机等级考试真题(二级C语言)43
-
1032 2016年9月全国计算机等级考试真题(二级C语言)43
最新题目 更多
-
已知类模板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的是( )。
-
下列语句分别是不同程序中的第一个输入输出语句,若去掉其中的“<<left”,输出效果将发生变化的是( )。
-
有如下程序:#include <iostream> using namespace std; class GA{ public: virtual int f(){return 1;} }; class GB: public GA{ public: virtual int f(){return 2;} }; void show(GA g){cout<<g.f();} void display(GA &g){cout<<g.f();} int main(){ GA a; show(a); display(a); GB b; show(b); display(b); Return 0; }运行时的输出结果是( )。
-
下列不属于C++规定的类继承方式是( )。
-
下列关于构造函数的说法中,正确的是( )。
-
下列关于函数的说法中,正确的是( )。
-
(读者自行创建,注意每行第一个逗号后面有空格),其内容示例如下:2016/5/31 0:05, vawel001, 1, 12016/5/31 0:10, earpa001, 1, 1……第 1 列是传感器获取数据的时间,第 2 列是传感器的编号,第 3 列是传感器所在的楼层,第4 列是传感器所在的位置区域编号。问题2.读入 earpa001.txt 文件中的数据,统计 earpa001 对应的职员在各楼层和区域出现的次数,保存到 earpa001_count.txt 文件,每条记录一行,位置信息和出现的次数之间用英文半角逗号隔开、行尾无空格、无空行。参考格式如下:1-1,51-4,3……
-
(读者自行创建,注意每行第一个逗号后面有空格),其内容示例如下:2016/5/31 0:05, vawel001, 1, 12016/5/31 0:10, earpa001, 1, 1……第 1 列是传感器获取数据的时间,第 2 列是传感器的编号,第 3 列是传感器所在的楼层,第4 列是传感器所在的位置区域编号。 问题 1读入 sensor.txt 文件中的数据,提取出传感器编号为 earpa001 的所有数据,将结果输出并保存到 earpa001.txt 文件。输出格式要求:原数据文件中的每行记录写入新文件中、行尾无空格、无空行。参考格式如下:2016/5/31 7:11, earpa001, 2, 42016/5/31 8:02, earpa001, 3, 4……
-
输入张三学习的课程名称及成绩等信息,信息间采用空格分隔,每个课程一行,以空行和回车符结束录入,示例格式如下:数学 98输出结果保存在 PY202.txt 中。其中逗号为英文逗号,最低分课程是物理 74,平均分是 88.40。
-
使用 turtle 库的 turtle.fd()函数和 turtle.seth()函数绘制一个正方形,边长为 200 像素。
-
输入一个 9800~9811 的正整数 n,作为 Unicode 编码,把 n-1、n 和 n+1 这 3 个 Unicode编码对应字符按照如下格式要求输出:宽度为 11 个字符、加号字符+填充、居中。例如,输入“9802”输出“++++???++++”。
-
输入一段中文文本,不含标点符号和空格,保存为变量 s,采用 jieba 库对其进行分词,输出该文本中词语的平均长度,保留 1 位小数。例如,输入“黑化肥发灰会挥发”,输出“2.7”。
-
输入 4 个数字,各数字采用空格分隔,对应为变量 x0、y0、x1、y1。计算两点(x0,y0)和(x1,y1)之间的距离,输出这个距离,保留 1 位小数。例如,输入“3 4 8 0”,输出“6.4”。
-
函数fun的功能是:将s所指字符串中ASCII值为偶数的字符删除, 串中剩余字符形成一个新串放在t所指的数组中。 例如,若s所指字符串中的内容为:“ABCDEFGl2345”,其中字符 B的ASCII码值为偶数、…、字符2的ASCII码值为偶数、…都应当删 除,其它依此类推。最后t所指的数组中的内容应是:“ACEG135”。 注意:部分源程序存在文件PROG1.c中。 请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花 括号中填入你编写的若干语句。/**********code.c**********/ #include <stdio.h> #include <string.h> void fun(char *s,char t[]) { } void main() { char s[100],t[100]; printf("\nPlease enter string S:"); scanf("%s",s); fun(s,t); printf("\nThe result is: %s\n", t); }
-
给定程序MODI1.C中函数fun的功能是:从s所指字符串中,找出与t 所指字符串相同的子串的个数作为函数值返回。 例如,当s所指字符串中的内容为:“abcdabfab”,t所指字符串的 内容为:“ab”,则函数返回整数3。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的 结构!/**********code.c**********/ #include <stdio.h> #include <string.h> int fun (char *s, char *t) { int n; char *p,*r; n = 0; while(*s) { p = s; r = t; while (*r) if(*r == *p) { /**********found**********/ r++; p++ } else break; /**********found**********/ if(r == '\0') n++; s++; } return n; } void main() { char s[100],t[100]; int m; printf("\nPlease enter string S:"); scanf("%s", s); printf("\nPlease enter substring t:"); scanf("%s", t); m = fun(s,t); printf("\nThe result is: m = %d\n", m); } /**********-code.c**********/
-
人员的记录由编号和出生年、月、日组成,N名人员的数据已在主函数中存入结构体数组std中,且编号唯一。函数fun的功能是:找出指定编号人员的数据,作为函数值返回,由主函数输出,若指定编号不存在,返回数据中的编号为空串。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!/**********code.c**********/ #include <stdio.h> #include <string.h> #define N 8 typedef struct { char num[10]; int year,month,day; }STU; /**********found**********/ ①______ fun(STU *std,char *num) { int i; STU a={"",9999,99,99}; for (i=0; i<N; i++) /**********found**********/ if(strcmp(②______,num)==0) /**********found**********/ return (③______); return a; } void main() { STU std[N]={{"111111",1984,2,15}, {"222222",1983,9,21}, {"333333",1984,9,1}, {"444444",1983,7,15}, {"555555",1984,9,28}, {"666666",1983,11,15}, {"777777",1983,6,22}, {"888888",1984,8,19}}; STU p; char n[10]="666666"; p=fun(std,n); if(p.num[0]==0) printf("\nNot found !\n"); else { printf("\nSucceed !\n "); printf("%s %d-%d-%d\n", p.num, p.year, p.month, p.day); } } /**********-code.c**********/
-
请编写一个函数fun其功能是:将ss所指字符串中所有下标为奇数位 置上的字母转换为大写(若该位置上不是字母,则不转换)。 例如,若输入“abc4EFg”,则应输出“aBe4EF9”。 注意:部分源程序在文件PROG1.C文件中。 请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花 括号中填入你编写的若干语句。/**********code.c**********/ #include <stdio.h> #include <string.h> void fun(char *ss) { } main() { char tt[51]; printf( "\nPlease enter an character string within 50 characters:\n" ); gets(tt); printf("\n\nAfter changing, the string\n \"%s\"",tt); fun(tt) ; printf("\nbecomes\n \"%s\"",tt); }
-
给定程序MODI1.C中函数fun的功能是:读入一个字符串(长度 <20),将该字符串中的所有字符按ASCII码升序排序后输出。 例如,若输入:edcba,则应输出:abcde。 请改正程序中的错误,使它能统计出正确的结果. 注意:不要改动main函数,不得增行或删行,也不得更改程序的 结构!/**********code.c**********/ #include <stdio.h> #include <string.h> void fun(char t[]) { char c; int i, j; /**********found***********/ for(i = strlen(t);i;i--) for(j = 0; j < i; j++) /**********found***********/ if(t[j] < t[j + 1]) { c = t[j]; t[j] = t[j + 1]; t[j + 1] = c; } } void main() { char s[81]; printf("\nPlease enter a character string: "); gets(s); printf("\n\nBefore sorting:\n \"%s\"",s); fun(s); printf("\nAfter sorting decendingly:\n \"%s\"\n",s); } /**********-code.c**********/
-
给定程序中,函数fun的功能是:将a所指4×3矩阵中第k行的元素与第0行元素变换。例如,有下列矩阵:1 2 34 5 67 8 910 11 12若k为2,程序执行结果为:7 8 9 4 5 6 1 2 3 10 11 12 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!/**********code.c**********/ #include<stdio.h> #define N 3 #define M 4 /**********found**********/ void fun(int (*a)[N],int ①______) { int i,temp ; /**********found**********/ for(i=0;i < ②______;i++) { temp=a[0][i] ; /**********found**********/ a[0][i] = ③______; a[k][i] = temp; } } void main() { int x[M][N]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}},i,j; printf("The array before moving:\n\n"); for(i=0;i<M;i++) { for(j=0;j<N;j++) printf("%3d",x[i][j]); printf("\n\n"); } fun(x,2); printf("The array after moving:\n\n"); for(i=0;i<M;i++) { for(j=0;j<N;j++) printf("%3d",x[i][j]); printf("\n\n"); } } /**********-code.c**********/
-
请编写一个函数fun,它的功能是:求出一个2×M整型二维数组中 最大元素的值,并将此值返回调用函数。注意部分源程序存在文件 PROG1.C文件中。 请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花 括号中埴入你编写的若干语句。/**********code.c**********/ #include <stdio.h> #define M 4 int fun (int a[][M]) { } void main() { int arr[2][M]={5,8,3,45,76,-4,12,82}; printf("max =%d\n", fun(arr)); }