重新编写以下程序,将1系l数 leisure 改为友元:
//===================================
//ex0806.cpp
//===================================
#include<iostream>
//-----------------------------------
class Car{
int size;
public:
void setSize(int j){ size = j; }
int getSize(){ return size; }
};//---------------------------------
class Boat{
int size;
public:
void setSize(int j) { size = j; }
int getSize() { return size; }
};//---------------------------------
int leisure(int time, Car& aobj, Boat& bobj){
return time * aobj.getSize() * bobj.getSize();
}//----------------------------------
int main(){
Car c1;
c1.setSize(2);
Boat b1;
b1.setSize(3);
std: :cout<<leisure(5, c1,b1);
}//==================================

//=================================== //EX0806.cpp //=================================== #include<iostream> //----------------------------------- class Boat; class Car{ int size; public: void setSize(int j){ size = j; } int getSize()const{ return size; } friend int leisure(int t, const Car& c, const Boat& b); };//--------------------------------- class Boat{ int size; public: void setSize(int j) { size = j; } int getSize()consy{ return size; } friend int leisure(int t, const Car& c, const Boat& b); };//--------------------------------- int leisure(int t, const Car& c, const Boat& b){ return t * c.size * b.size; }//---------------------------------- int main(){ Car c; c.setSize(2); Boat b; b.setSize(3); std: :cout<<leisure(5, c,b); }//==================================