1000.1 Letters and Words homework 12

Posted 任我主宰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 5258. 得分最高的单词集合 Maximum Score Words Formed by Letters

CodeForces - 864B Polycarp and Letters

804.Unique Morse Code Words

按元素名称组合/合并列表

Codeforces Round #436 (Div. 2), problem: (B) Polycarp and Letters

[POI2006]OKR-Periods of Words