ǰλãҳ > 自考C试题及答案套合集 - 百度文库
void swap(int &a,int &b) {a=a+b; b=a-b; a=a-b; }
void main() {int a=19,b=15;
cout<<\swap(&a,&b); swap(a,b); cout<<\}
5. #include
int * const p=&i; int *p=&i; cout<<*p< cout<<*p< ġɳ(5С⣬ÿС4֣20) 1. ߴʵݣʹִнΪ\ #include char * pdata; mystring(int len) {pdata=new charlen+1; } ~mystring() {delete pdata;} void show(){cout< void fun(mystring** array,int len) {mystring*old=*array; _*array=new mystring(len)______; memcpy(*array, old, len); } void main() {mystring str(20); mystring*pstr=&str; mystring**ppstr=&pstr; strcpy(str.pdata,\fun(ppstr, 20); str.show();_______ } 2. ߴʵ־䣬Ķ塣 class line; class box { private: int color; int upx, upy; int lowx, lowy; public: friend int same_color(line l, box b); void set_color (int c){color=c;} void define_box (int x1, int y1, 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 l,box b); void set_color (int c) {color=c;} void define_line (int x1,int y1,int x2,int y2) {startx=x1;starty=y1;endx=x2;endy=y2;} }; int same_color(line l, box b) {if (l.color==b.color) return 1; return 0; } 3. ֱб߳ȡ #include friend Line;__________ public: Point(double i=0,double j=0) {x=i;y=j;} Point(Point &p) {x=p.x;y=p.y;} }; class Line {private: Point p1,p2; public: Line(Point &xp1,Point &xp2):p1(xp1),p2(xp2)________{} double GetLength(); }; double Line::GetLength() {double dx=p2.x-p1.x; double dy=p2.y-p1.y; return sqrt(dx*dx+dy*dy); } void main() { Point p1,p2(6,8); Line L1(p1,p2); cout< 4. ĵߴʵ־䣬ʹóִнΪ40 #include static int x______; Test (int i=0) {x=i+x;} int Getnum() {return Test::x+7;} }; int Test::x=33_______; void main() {Test test; cout< 5. гĿոʵ־䣬ʹΪ0210 #include Magic(double d=0.00):x(fabs(d)) {} Magic operator+(Magic &c______) { return Magic(sqrt(x*x+c.x*c.x)); } friend ostream& operator<<(ostream & stream,Magic & c) { stream< void main() {Magic ma; cout< 塢(2С⣬ÿС5,10) 1. гдִеĽ #include
92ƪĵ