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;

}

时间: 2024-08-01 09:29:09

1000.1 Letters and Words homework 12的相关文章

1000. Letters and Words homework 12

#include<iostream>#include<sstream>#include<cstring>using namespace std;int main(){ char s[1000]; string str; int count = 0; int count1 = 0;    cin.get(s,1000,'\0');    for(int i = 0; i < strlen(s); i++) {  if((s[i] >= 'a' &&am

Python学习之路12?模块与包

一 模块 1.1 什么是模块? 一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 1.2 为何要使用模块? 如果你退出python解释器然后重新进入,那么你之前定义的函数或者变量都将丢失,因此我们通常将程序写到文件中以便永久保存下来,需要时就通过python test.py方式去执行,此时test.py被称为脚本script. 随着程序的发展,功能越来越多,为了方便管理,我们通常将程序分成一个个的文件,这样做程序的结构更清晰,方便管理.这时我们不仅仅可以把

python 各模块

01 关于本书 02 代码约定 03 关于例子 04 如何联系我们 1 核心模块 11 介绍 111 内建函数和异常 112 操作系统接口模块 113 类型支持模块 114 正则表达式 115 语言支持模块 12 _ _builtin_ _ 模块 121 使用元组或字典中的参数调用函数 1211 Example 1-1 使用 apply 函数 1212 Example 1-2 使用 apply 函数传递关键字参数 1213 Example 1-3 使用 apply 函数调用基类的构造函数 122

转:Python标准库(非常经典的各种模块介绍)

Python Standard Library 翻译: Python 江湖群 10/06/07 20:10:08 编译 0.1. 关于本书 0.2. 代码约定 0.3. 关于例子 0.4. 如何联系我们 核心模块 1.1. 介绍 1.2. _ _builtin_ _ 模块 1.3. exceptions 模块 1.4. os 模块 1.5. os.path 模块 1.6. stat 模块 1.7. string 模块 1.8. re 模块 1.9. math 模块 1.10. cmath 模块

动态规划——H 最少回文串

We say a sequence of characters is a palindrome if it is the same written forwards and backwards. For example, ‘racecar’ is a palindrome, but ‘fastcar’ is not. A partition of a sequence of characters is a list of one or more disjoint non-empty groups

C#多线程和异步(三)——一些异步编程模式

一.任务并行库 任务并行库(Task Parellel Library)是BCL中的一个类库,极大地简化了并行编程,这里以Parallel.For和Parallel.ForEach为例.在C#中for/foreach循环使用十分普遍,如果迭代不依赖与上次迭代的结果时,把迭代放在 不同的处理器上并行处理 将很大地提高运行效率,Parallel.For和Parallel.ForEach就是为这个目的而设计的. 一个栗子: 1 static void Main(string[] args) 2 { 3

UVA-11584:Partitioning by Palindromes(基础DP)

今天带来一个简单的线性结构上的DP,与上次的照明系统(UVA11400)是同一种类型题,便于大家类比.总结.理解,但难度上降低了. We say a sequence of characters is a palindrome if it is the same written forwards and backwards. For example, 'racecar' is a palindrome, but 'fastcar' is not. A partition of a sequenc

UVA11584-Partitioning by Palindromes(动态规划基础)

Problem UVA11584-Partitioning by Palindromes Accept: 1326  Submit: 7151Time Limit: 3000 mSec Problem Description Input Input begins with the number n of test cases. Each test case consists of a single line of between 1 and 1000 lowercase letters, wit

java例题_32 取一个整数a从右端开始的4~7位

1 /*32 [程序 32 左移右移] 2 题目:取一个整数 a 从右端开始的 4-7 位. 3 */ 4 5 /*分析 6 * 从右端开始的第四位相当于原数除以1000后结果的最后一位数, 7 * 而4~7位就相当于再除以1000的结果下再对10000取余! 8 * 可以int也可以long类型 9 * */ 10 11 package homework; 12 13 import java.util.Scanner; 14 15 public class _32 { 16 17 public