C++重要题目一

 1 #include<iostream>
 2 class Boat;//必须事先声明
 3 class Car
 4 {
 5     int size;
 6 public:
 7     void setSize(int j){size=j;}
 8     int getSize(){return size;}
 9     friend int leisure(int time,Car& aobj,Boat& bobj);
10 };
11 class Boat:Car//此处的Car可要可不要
12 {
13     int size;
14 public:
15     void setSize(int j){size=j;}
16     int getSize(){return size;}
17     friend int leisure(int time,Car& aobj,Boat& bobj);
18 };
19 int leisure(int time,Car& aobj,Boat& bobj)
20 {
21     return time*aobj.size*bobj.size;
22 }
23 int main()
24 {
25     Car c1;
26     c1.setSize(2);
27     Boat b1;
28     b1.setSize(3);
29     std::cout<<leisure(5,c1,b1)<<std::endl;
30     system("pause");
31 }

 

posted @ 2013-05-30 22:01  herizai  阅读(150)  评论(0编辑  收藏  举报