正文

C++语言程序设计试题[1]2008-09-08 17:37:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/yzrj/37991.html

分享到:

说明:在本试卷中规定整型(int)数据占用4个字节的存储单元。   一、选择题(每小题1分,共6分)   1.由C++目标文件连接而成的可执行文件的缺省扩展名为              。         A.  cpp                         B.  exe         C.  obj                         D.  lik 2.在下面的一维数组定义中,哪一个有语法错误。                        A.   int  a[ ]={1,2,3}               B.   int  a[10]={0}         C.   int  a[ ]                      D.   int  a[5] 3.在下面的函数声明中,存在着语法错误的是                。         A.   void  BC(int  a , int)           B.  void  BD(int , int)         C.   void  BE(int , int=5)            D.  int  BF(int  x ; int  y) 4. 假定AB为一个类,则该类的拷贝构造函数的声明语句为              。         A.  AB &(AB  x)                 B.  AB(AB  x)         C.  AB(AB  &)                   D.  AB(AB * x) 5.对于结构中定义的成员,其隐含访问权限为            。         A.  public                        B.  protected         C.  private                       D.  static 6.当使用fstream流类定义一个流对象并打开一个磁盘文件时,文件的隐含打开方式为       。         A.  ios::in                      B.  ios::out         C.  ios::int | ios::out              D.  没有   二、填空题(每小题2分,共24分) 1.执行“cout  <<43<<’-‘<<18<<’=’<<43-18<<endl;”语句后得到的输出结果为       。 2.已知’A’~’Z’的ASCII码为65~90,当执行“char  ch=14*5+2; cout  <<ch<<endl;”语句序列后,得到的输出结果为          。 3.使用const 语句定义一个标识符常量时,则必须对它同时进行         。 4.表达式x=x+1表示成增量表达式为          。 5.若x=5,y=10,则x>y和x<=y的逻辑值分别为         和         。 6.执行“typedef  int  ABC[10];”语句把ABC定义为具有10个整型元素的        。 7.假定p所指对象的值为25,p+1所指对象的值为46,则执行“(*p)++;”语句后,p所指对象的值为         。 8.假定一个二维数组为a[M][N],则a[i]的地址值(以字节为单位)为                。 9.假定要访问一个结构指针p所指对象中的b指针成员所指的对象,则表示方法为                    。 10.设px是指向一个类动态对象的指针变量,则执行“delete  px;”语句时,将自动调用该类的         。 11.若需要把一个函数“void  F( );”定义为一个类AB的友元函数,则应在类AB的定义中加入一条语句:              。 12.若要在程序文件中进行标准输入输出操作,则必须在开始的 # include 命令中使用              头文件。   三、下列程序运行后的输出结果(每小题6分,共36分) 1. # include <iostream.h> void main() {        int s=0;        for (int i=1;  ; i++) {               if (s>50) break;               if (i%2==0)  s+=i;        }        cout  <<"i,s="<<i<<","<<s<<endl; }   2. # include <iostream.h> void main() {        char a[]="abcdabcabfgacd";        int i1=0,i2=0,i=0;        while (a[i]) {               if (a[i]=='a') i1++;               if (a[i]=='b') i2++;               i++;        }        cout <<i1<<' '<<i2<<endl; }   3. # include <iomanip.h> void main() {        int a[9]={2,4,6,8,10,12,14,16,18};        for (int i=0; i<9; i++) {               cout <<setw(5)<<*(a+i);               if ((i+1)%3==0) cout <<endl;        } }   4. # include <iomanip.h> void LE(int * a,int * b) {        int x=*a;        *a=*b;  *b=x;        cout <<*a<<' '<<*b<<endl; } void main() {     int x=10,y=25;     LE(&x,&y); cout <<x<<' '<<y<<endl; }   5. # include <iostream.h> class A {        int a,b; public :        A() { a=b=0; }        A(int aa,int bb) {               a=aa; b=bb;               cout <<a<<' '<<b<<endl;        } }; void main() {        A x,y(2,3),z(4,5); }   6. # include <iostream.h> template <class TT> class FF {        TT a1,a2,a3; public :        FF(TT b1,TT b2,TT b3) {               a1=b1; a2=b2; a3=b3;        }        TT Sum() { return a1+a2+a3; } }; void main() {        FF <int> x(2,3,4),y(5,7,9);        cout <<x.Sum()<<' '<<y.Sum()<<endl; }     四、写出下列每个函数的功能(每小题6分,共24 分) 1.double SF(double x,int n) {     // n为大于等于0的整数     double p=1,s=1;     for (int i=1; i<=n; i++) {            p*=x;            s+=p/(i+1);     }     return s; }   2. float FH() {     float x,y=0,n=0;     cin >>x;     while (x!=-1) {            n++; y+=x;            cin >>x;     }     if (n==0) return y; else return y/n; }   3.  # include <iostream.h> void WA(int a[],int n) {        for (int i=0; i<n-1; i++) {               int k=i;               for (int j=i+1; j<n; j++)                      if (a[j]<a[k]) k=j;                      int x=a[i]; a[i]=a[k]; a[k]=x;        } }   4.  # include <iomanip.h> # include <fstream.h> void JB(char * fname)        // 可把以fname所指字符串作为文件标识符的文件称为fname文件        // 假定该文件中保存着一批字符串,每个字符串的长度均小于20 {        ifstream fin(fname);        char a[20];        int i=0;        while (fin>>a) {               cout <<a<<endl;               i++;        }        fin.close();        cout <<"i="<<i<<endl; }   五、编写一个函数,统计出具有n个元素的一维数组中大于等于所有元素平均值的元素个数并返回。(10分)    int  Count(double a[],int n);   // 此为该函数的声明。  

阅读(2635) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册