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

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

}

44.#include

class point{private:float x; public:void f(float a){x=a;} void f( ){x=0;}

friend float max(point& a,point& b); };

float max(point& a,point& b) {return(a.x>b.x)? a.x:b.x;} main( ){

point a,b;

a.f(2.2);b.f(3.3); cout< } 45.#include template class f{

private:T x,y;

public:void f1(T a,T b){x=a;y=b;} T max( ){retum(x>y)?x:y;} };

main( ){ f a;

a.f1(1.5,3.8); ’ cout<}

四、完成程序题(本大题共5小题,每小题4分,共20分) 46.完成下面类中的成员函数的定义。 class point {

private: int m,n; public:

point(int,int); point(point&); };

point::point(int a,int b) { m=a; ________=b; }

point::point(________) {

m=t.m; n=t.n;

}

47.下面是一个输入半径,输出其面积和周长的C++程序,在下划线处填上正确的语句。 #include

using namespace std; ________pi=3.14159; void main( ) {

double r;

cout<<″r=″; ___________ ;

double l=2.0*pi*r; double s=pi*r*r;

cout<<″\n The long is:″< cout<<″The area is:″< } 48.在下划线处填上缺少的部分。 #include #include

using namespace std; class complex {

public: int real; int imag;

complex(int r=0,int i=0) {

real=r; imag=i; } };

complex operator+(________,complex& b) {

int r=a.real+b.real; int i=a.imag+b.imag; return_________; }

void main( ) {

complex x(1,2),y(3,4),z; z=x+y; cout< }

49.程序的输出结果如下: 1,9 50,30

请根据输出数据在下面程序中的下划线处填写正确的语句。 源程序如下:

#include

using namespace std; class base {

private: int m; public: base( ){ };

base(int a):m(a){} int get( ){return m;} void set(int a){m=a;} };

void main() {

base*ptr=new base[2]; ptr- >set(30); ptr= _________; ptr- >set(50); base a[2]={1,9};

cout< cout

cout<<________< delete[ ]ptr; }

50.在下面横线处填上求两个浮点数之差的cha函数的原型声明、调用方法。 #include

using namespace std; void main( ) {

float a,b;

________//函数cha的原型声明 a=12.5; b=6.5;

float c=_________; //调用函数cha cout< }

float cha(float x,float y) {

float w; w=x-y; return w; }

五、程序分析题(本大题共4小题,每小题5分,共20分) 51.给出下面程序的输出结果。 #include

template class Sample { T n; public:

Sample(T i){n=i;}

int operator==(Sample &); };

template

int Sample::operator==(Sample&s) {

if(n==s.n) return 1; else

return 0; }

void main( ) {

Samplesl(2),s2(3); .

cout<<″s1与s2的数据成员″<<(sl==s2 ?″相等″:″不相等″)< Samples3(2.5),s4(2.5);

cout<<″s3与s4的数据成员″<<(s3==s4 ? ″相等″:″不相等″)< } 52.给出下面程序的输出结果。 #include

using namespace std; template

T max(T ml,T m2)

{return(m1>m2)?ml:m2:} void main( ) { cout< cout< }

53.给出下面程序的输出结果 #include

using namespace std; class A { public: int x; A( ) { }

A(int a){x=a;}

int get(int a){return x+a;} }; void main( ) { A a(8);

int(A::*p)(int); p=A::get;

cout<<(a.*p)(5)< A*pi=&a;