C 自考历年真题小集 联系客服

发布时间 : 星期三 文章C 自考历年真题小集更新完毕开始阅读6635efc2bb4cf7ec4afed008

void Print(______) {

______; }

void main() {

ClassA a; ClassB b; Print(a); Print(b); }

50.下列程序的运行结果如下: x=22,y=22

根据结果将程序补充完整。 #include

template <______> void f(______) {

if(sizeof(T1)>sizeof(T2)) x=(T1)y; else

y=(T2)x; }

void main(){ double x=134.2; int y=22; f(x,y);

cout<<″x=″<}

五、程序分析题(本大题共2小题,每小题5分,共10分) 请给出下面程序的输出结果 51. #include < iostream. h > class Class {

public:

static int var; Class() {

var+ +; } };

int Class::var = 0; void main() {

cout < < ″Class::var =″ < < Class: : var < < endl; Class cl ;

cout < <″cl. var=″ < Class c2, c3 ;

cout < < ″c2. var =″ < < c2. var < < endl; }

52. #include < iostream. h > class A {

public: A();

void Show() ; ~A(); private:

static int c; }; int A::c =0; A::A() {

cout < < ″constructor.″ < < endl; c+ =10; }

void A: :Show() {

cout< < ″c=″ < } A::~A() {

cout < < ″destructor. ″ < < endl; }

void main() {

A a,b; a. Show(); b. Show(); }

六、程序设计题(本大题共l小题,共10分)

53.利用LOCATION类,使用继承定义圆类CIRCLE,圆由圆心和半径构成。提供得到圆心坐标和半径的成员函数、以及计算圆的周长和面积的成员函数。在主程序中创建两个圆A和B,圆心坐标分别为(0,3)、(3,7),按如下格式输出两个圆的圆心坐标、周长和面积,并计算和输出两个圆的圆心之间的距离。考试大收集整理 A:(xl,y1,r1),Girth=g1,Area=a1 B:(x2,y2,r2),Girth=g2,Area=a2 A(xl,y1),B(x2,y2),Distance=d

定义LOCATION类,该类没有“继承”等现象。注意二维坐标点之间的距离公式。

class LOCATION{ double x,y;

public: virtual double getx()const{return x;}; virtual double gety()const{return y;}; virtual double dist(LOCATION &s)const;

LOCATION(double x,double y):x(x),y(y){};}; double LOCATION::dist(LOCATION &s)const{ double xd=s.x — x,yd=s.y — y; return sqrt(xd*xd+yd*yd);}