地大23春c++程序设计-模拟测试答案非答案

[复制链接]
楼主: admin

2万

主题

3万

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
72282
 楼主| 发表于 2023-3-30 09:42:03 | 显示全部楼层
include<iostream.h>int change(int x,int &y,int &z,int *dp){   z=x--+--y;  *dp=x-y--;        return(x+y);}void main(){    int a=8,b=8,c=8,d=8;  a=change(a,b,c,&d);  cout<<a<<','<<b<<','<<c<<','<<d<<endl;}  

[答案]:13,6,15,0

   

15.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2万

主题

3万

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
72282
 楼主| 发表于 2023-3-30 09:42:03 | 显示全部楼层
include<iostream.h>class CPoint{     private:int X,Y;  public:   CPoint(int i, int j) {X=i; Y=j;}   virtual int Area(){  return 0;}};class CRectangle:public CPoint{     private:int W,H;  public:   CRectangle(int i, int j, int k, int l) :CPoint(i,j) {W=k;  H=l; }   int Area() {return  W*H;}};void fun(CPoint &s) { cout<<"Area="<<s.Area()<<endl;  }void main()  { CRectangle r(2, 3, 6, 8);  fun(r);  }

[答案]:Area=48

   

16.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2万

主题

3万

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
72282
 楼主| 发表于 2023-3-30 09:42:03 | 显示全部楼层
include <iostream.h>int fun(int n){   int r;  if(n==1||n==2)     r=1;  else   r=fun(n-1)+fun(n-2);    return  r;}void main(){  cout<<fun(6)<<endl;  }

[答案]:8

   

17.什么叫类?什么叫对象?

[答案]:类是封装了数据和方法的一种抽象数据类型(2分).

对象是类的一个实例(2分).18.在C++语言中,请说明结构体和联合体的异同点.

[答案]:结构体数据类型的变量可以同时存储int,long,char和double型等已有数据类型的数据,这些数据使用不同的存储空间,而联合体虽然表面上可以存储int,long,char或double等已有数据类型的数据,但它们共享其占用空间最多的成员所分配的存储空间,对某个成员赋值将影响其它成员的数值.

   

19.函数之间的参数传递的形式有哪几种?

[答案]:传值传递方式,地址传递方式,引用方式.

   

20.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2万

主题

3万

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
72282
 楼主| 发表于 2023-3-30 09:42:03 | 显示全部楼层
include <iostream.h>class B{ public:   B(int i) {  cout<<"constructing B "<<i<<endl;  }};class C: public B{ public:   C(int a, int b,int c):B(a),memberB(b)   { cout<<"constructing C "<<c<<endl;}private:   B memberB;};void main(){ C obj(1,2,3);  }

[答案]:constructing B 1

constructing B 2

constructing C 321.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2万

主题

3万

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
72282
 楼主| 发表于 2023-3-30 09:42:03 | 显示全部楼层
include<iostream.h>class CPoint{     private:int X,Y;  public:   CPoint(int i, int j) {X=i; Y=j;}   virtual int Area(){  return 0;}};class CTriangle:public CPoint{     private:int W,H;  public:   CTriangle (int i, int j, int k, int l) :CPoint(i,j) {W=k;  H=l; }   int Area() {return  W*H/2;}};void fun(CPoint &s) { cout<<"Area="<<s.Area()<<endl;  }void main()  { CTriangle r(9, 8, 7, 6);  fun(r);  }

[答案]:Area=21

   

22.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2万

主题

3万

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
72282
 楼主| 发表于 2023-3-30 09:42:03 | 显示全部楼层
include <iostream.h>class myclass{private:  int a,b;    static int s;  public:    myclass(int x,int y){ a=x;  b=y; s++; }  ~myclass(){s--;}    void print(){  cout <<s<< endl; }} ;int myclass::s=0;void main(){   myclass m1(1,2),m2(4,5);    m1.print();  { myclass  m3(6,7);   m3.print();  }  m2.print();}

[答案]:2

3

223.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2万

主题

3万

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
72282
 楼主| 发表于 2023-3-30 09:42:03 | 显示全部楼层
include <iostream.h>class point    {      private:int x,y;     public:          point(int a=0,int b=0){  cout <<"A object is created"<<endl; }          ~point(){  cout<<"A object is destroyed"<<endl; }   };void main(){  point  a1,a2,*p;p= new point;}

[答案]:A object is created

A object is created

A object is created

A object is destroyed

A object is destroyed24.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2万

主题

3万

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
72282
 楼主| 发表于 2023-3-30 09:42:03 | 显示全部楼层
include<iostream.h>int  t(int x,int &y,int *cp,int z){   --x;  ++y;  *cp=--x+y++;  z=x+*cp ;    return z;  }void main(){    int a=3, b=3,c(3),d(3);    d+=t(a,b,&c,d);    cout<<a<<b<<c<<d<<endl; }

[答案]:3559

   

附件是答案,转载注明

答案来源:www.ybaotk.com

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

精彩课程推荐
|网站地图|网站地图