首页 > 代码库 > 1000.1 Letters and Words homework 12

1000.1 Letters and Words homework 12


#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

 

//your code will be here
class Land

{

public:

 Land() : price_(0) {}

 explicit Land(int price);

 // calculate how much Feng Gor can earn from the land

 virtual double CalMoney() = 0;

protected:

 // price of unit area

 int price_;

};

 

class Square : public Land

{

public:

 Square(double len, int price);

 double CalMoney();

private:

 //length of side of a square

 double len_;

};


 

class Circle : public Land

{

public:

 Circle(double radius, int price);

 double CalMoney();

private:

 //length of radius of a circle

 double radius_;

};

Circle::Circle(double radius, int price){
 radius_ = radius;
 price_ = price;
}
double Circle::CalMoney(){
 return acos(-1)*price_ * radius_ * radius_;
}
 
Square::Square(double len, int price){
 len_ = len;
 price_ = price;
}
 
double Square::CalMoney(){
 return len_ * len_ * price_;
}
 
 void  Accountant::DevelopEstate(Land* land){
 money_ += land->CalMoney();
}
 
double Accountant::CheckMoney(){
 return money_;
}
 
 
 
 
 
 
 
 

class Accountant

{

public:

 Accountant() : money_(0) {}

 // develop a land, earn the value of the land

 void DevelopEstate(Land* land);

 // return the value of money_

 double CheckMoney();

private:

 double money_;

};
 

 
 
 
 
 

int main(int argc, const char *argv[])

{

 Accountant py;

 Circle *a = new Circle(100, 10000);

 Square *b = new Square(100, 50000);

 py.DevelopEstate(a);

 cout << setprecision(10) << py.CheckMoney() << endl;

 py.DevelopEstate(b);

 cout << setprecision(10) << py.CheckMoney() << endl;

 

 return 0;

}

 

1000.1 Letters and Words homework 12