在C++语言的面向对象设计框架中,________是程序的基本组成单元。
求n(n=3)个学生的最高分和最低分及姓名,已有 student类声明和main函数,完成 student类的实现部分。
#include
#include< string.h>
class student
{char name[10];
int deg;
public:
student(char na[]="",int d=0);
char*getname();
friend int compare(student &s1,student &s2);
int getdeg();
};
void main()
{student st[]={student("王强",74), student("李刚",68), student("张雪",84)};
int i=0, min=0, max=0;
for(i=1;i<3;i++)
{if(compare(st[max],st[i])==-1)
max=i;
if(compare(st[min],st[i])==1)
min=i;
}
cout<"最高分:"< cout<<"最低分:"<<(*(st+min)).getdeg()<"姓名:" }
给出下面程序输出结果。
#include
class Base
{private:
int Y;
public:
Base(int y=0){Y=y;cout<<"Base("< ~Base(){cout<<"~Base()\n";} void print(){cout< }; class Derived:public Base {private: int Z; public: Derived(int y,int z):base(y) {Z=z; cout<<"Derived("< } ~Derived(){cout<<"~Derived()\n"; void print() {base::print() cout< }; void main() {Derive d(10,20); d.print(); }
给出下面程序的输出结果。
#include
class A
{public:
A(){al=0;}
A(int i)al=i;}
void printout(){cout<
private:
int al;
};
class B:public A
{public:
B(){b1=0;}
B(int i,int j,int k);
void printout();
private:
int bl;
A aa;
};
B::B(int i,int j,int k):A(i),aa(j)
{bl=k;}
void B::printout()
{A::printout();
cout< void main() {B tt2]; tt [0=B(9,3,5); t[1]=B(8,4,7); for(int i=0;i<2;i++) tt[i].printout(); }
#include
#include
class arr
{____________
int s;
public:
Arr(int a[],int n)
{v=a;
s=n;
}
int size(){return s;}
int&operator()(int n);
};
____________()(int n)
{if(n>s)
{cerr<<"下标越界!"< exit(1); } return v[n]; }
程序的输出结果如下:
30
9
请根据输出数据在下面程序中的下横线处填写正确的语句。
#include
class Test
{private:
int m;
public:
Test(int i=0)
{m=i;}
void show()
{cout< void set(int i) {m=i;} }; void main() {Test*p1= new Test[2],*p2; p2=p1; p1->set(30); p1->show(); Test[2]={1,9}; ___________ p1->show(); pl=p2; ___________//释放空间 }
在下面程序的横线处填上适当内容,完成类的定义。
class line;
class box
{private:
int color;
int upx, upy;
int lowx, lowy;
public:
____________
void set_color (int c){color=c;}
void define_box (int xl, int yl, int x2, int y2)
{upx=x1;upy=y1;lowx=x2;lowy=y2;}
};
class line
{private:
int color;
int startx, starty;
int endx, endy;
public:
friend int same_color( line 1, box b);
void set_color (int c){color=c;}
void define_line(____________)
{startx =x1;starty =yl;endx =x2;endy =y2;}
};
int same_color( line 1, box b)
{if (1.color =b.color)return 1;
return 0;
}
#include
#include
class dis
{private:
double x,y;
public:
dis(________){x=x1;y=y1;}
double getx(){return x;}
double gety(){return y;}
________double log(dis&,dis&);
};
double dis::log(dis&a,dis&b)
double px=a.x-b.x;
double py=a.y-b.y;
return sqrt(px*px+py*py);
}
void main()
dis pl(3.5,4.5),p2(5.5,6.5);
double d=dis::log(p1,p2);
cout<<"The distance is"< }
在下列程序的横线处填上适当的语句,使输出为:0,2,10
#include
#include
class Magic
{double x;
public:
Magic(double d=0.00)(fabs(d))
{}
Magic operator+(___________)
{
return Magic(srt(x*x+c.x*c.x));
}
___________operator<<(ostream& stream,Magic &c)
{stream< return stream; } }; void main() {Magic ma; cout< }
#include
class Test
{int x,y;
public:
void fun(int i,int j)
{x=i;y=j;}
void show()
{cout<<"x="< if(y) cout<<",y="< }; void main() {Test a; A.fun(1); A.show(); A.fun(2,4); A.show(); }
#include
};
void main()
{A*p;
B b(3,5);
p=&b;
p->fun();
}
2005年初级经济师考试《旅游经济专
初级旅游经济师试题及答案一
初级旅游经济师试题及答案二
2005年初级经济师考试《邮电经济专
初级经济师试题及答案1(邮电经济)
初级经济师试题及答案1(保险经济)
初级经济师试题及答案2(邮电经济)
初级经济师试题及答案2(保险经济)
初级经济师试题及答案3(保险经济)
2014年经济师初级考试真题《建筑经