---
四、完成程序题(本大题共5小题,每小题4分,共20分)
1. 在下面程序横线处填上适当内容,使程序执行结果为:\。
#include
char * pdata; mystring(int len)
{pdata=new char[len+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