(*p)obj1: a=100 b=1.2 p->obj2: a=100 b=3.5 (*p)obj2: a=100 b=3.5 p->new: a=100 b=1.2 6、
fun1:9 fun2:18 7、
Now is2004.9.2310:20:50.
五、编程题
1、
#include
17
char name[20]; char author[20]; float sale; public:
Book(char n[]=\ { strcpy(name,n); strcpy(author,au); sale=s;
} ~Book() { cout<<\析构函数被调用!\
}
void setBook(char n[],char au[],float s) { strcpy(name,n); strcpy(author,au); sale=s;
}
void showBook() { cout<<\ cout<<\ cout<<\
} };
void main() { Book b;
18
b.showBook();
b.setBook(\ b.showBook(); }
#include
void point::set() {
cout<<\请输入坐标值:\ cin>>x>>y>>z; }
void point::getline(point p2) {
double l;
l=sqrt((x-p2.x)*(x-p2.x)+(y-p2.y)*(y-p2.y)+(z-p2.z)*(z-p2.z)); cout<<\这两点的距离为\} int main() {
point p1,p2; p1.set();
19
2、
p2.set();
p1.getline(p2); return 0;
}
#include
void settime(int newh=0,int newm=0,int news=0); void showtime(); private:
int hour,minute,second; };
void clock::settime(int newh,int newm,int news) {
hour=newh; minute=newm; second=news; }
void clock::showtime() {
cout<<\现在的时间为:\
cout< clock t1,t2,t3,t4; t1.settime(12,34,12); 20 3、