Home Web Board ProblemSet Standing Status Statistics

Problem E: 农夫果园

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1338  Solved: 1085
[Submit][Status][Web Board]

Description

秋天到了,果园里的水果成熟了,商贩们来收水果了,农夫们都希望自己的水果能卖个好价钱。
现在果园里有三种水果正在销售,苹果(Apple)、香蕉(Banana)、梨(Pear)。每次销售都会记录下水果的种类、单价和总量,input()函数可以读取每条销售记录的单价和总量,total()函数可以计算出这次销售的总价。
但是,销售员在记录时忙中出错,各中水果的单价和总量的单位没有统一。单价是每公斤的价格,而水果是按箱记录的。其中,苹果一箱按30公斤计算,香蕉一箱按25公斤计算,梨一箱按20公斤计算。每种水果每次销售的总价是“单价*总量*每箱公斤数”。
现在,你来设计一个程序帮忙计算果园卖出水果的总价。由于total()函数对每种水果的计算方式都不一样,因此使用多态来实现。
-----------------------------------------------------------------------------
你设计并实现这个水果类的派生体系,使得main()函数能够运行并得到正确的输出。调用格式见append.cc

Input

输入的第一个整数n,表示后面有n条水果收购的记录。每条记录分为3部分,水果种类、单价和总量。

Output

输出为一行,表示整个果园卖出水果的总价。

Sample Input

5Apple 4.2 100Banana 8.8 50Apple 4.5 200Banana 7.8 100Pear 3.7 100

Sample Output

Total Price : 77500

HINT

Append Code

append.c, append.cc,

[Submit][Status][Web Board]

한국어<  中文 فارسی English ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin

#include <iostream>
using namespace std;
class Fruit
{
public:virtual void input() = 0;virtual double total()  const = 0;
public:Fruit( ) { }
protected:double uprice;int num;
};
class Apple : public Fruit
{
public:void input() {  cin >> uprice; cin >> num; }double total()  const { return uprice * num * 30; }
public:Apple( ) : Fruit() {  }
};class Banana : public Fruit
{
public:void input() {  cin >> uprice; cin >> num; }double total()  const { return uprice * num * 25; }
public:Banana( ) : Fruit() {  }
};class Pear : public Fruit
{
public:void input() {  cin >> uprice; cin >> num; }double total()  const { return uprice * num * 20; }
public:Pear( ) : Fruit() {  }
};int main()
{Fruit* fruit;string fruit_name;double sum = 0.0;int cases;cin >> cases;for(int i = 1; i <= cases; i++){cin >> fruit_name;if(fruit_name == "Apple")fruit = new Apple();if(fruit_name == "Banana")fruit = new Banana();if(fruit_name == "Pear")fruit = new Pear();fruit->input();sum += fruit->total();delete fruit;}cout << "Total Price : " << sum << endl;return 0;
}

Problem E: 农夫果园相关推荐

  1. Problem A: 农夫果园

    Problem A: 农夫果园 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 2089  Solved: 1702 [Submit][Status][ ...

  2. 实验9:Problem C: 农夫果园

    Home Web Board ProblemSet Standing Status Statistics Problem C: 农夫果园 Problem C: 农夫果园 Time Limit: 1 S ...

  3. Problem C: 农夫果园

    Description 一果农,家里有苹果树.梨树,2016年收成不错,现在需要你来编程,求一下去年总共收获了多少斤的水果. Input 第一行N表示之后有N行输入. 之后的N行输入,每行一个水果.包 ...

  4. SDUSTOJ1670 Problem C: 农夫果园

    Description 秋天到了,果园里的水果成熟了,商贩们来收水果了,农夫们都希望自己的水果能卖个好价钱. 现在果园里有三种水果正在销售,苹果(Apple).香蕉(Banana).梨(Pear).每 ...

  5. linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.

    所有的base 都要取消注释 mirrorlist 加上注释 另外所有的enable都要设为零 目录 今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现y ...

  6. A + B Problem

    1001: A + B Problem Description 计算 A + B. Input 多组测试数据,每组测试数据占一行,包括2个整数. Output 在一行中输出结果. Sample Inp ...

  7. Error:(49, 1) A problem occurred evaluating project ':guideview'. Could not read script 'https://r

    出现问题如下: Error:(49, 1) A problem occurred evaluating project ':guideview'. > Could not read script ...

  8. #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)

    题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...

  9. ADPRL - 近似动态规划和强化学习 - Note 3 - Stochastic Infinite Horizon Problem

    Stochastic Infinite Horizon Problem 3.Stochastic Infinite Horizon Problem 定义3.1 无限范围的马尔可夫决策过程 (Marko ...

最新文章

  1. 智能算法把奥巴马识别成白人,AI也学会歧视了?
  2. 微信小程序 获取用户信息 官网例程 详解
  3. 视频 + PPT | 数字化运营,从理论到实践
  4. bootstrap加载mysql数据库_bootstrap后台管理系统前后台实现(含数据库)
  5. python3.6串口编程实例_使用python3实现操作串口详解
  6. [转] left join/right join/inner join操作演示
  7. 微课|中学生可以这样学Python(2.2.3节):in和is
  8. 大数据的核心价值表现在哪里
  9. 产品经理的工作感想(2)
  10. Spring IOC的三种主要注入方式?
  11. viper4android 机顶盒,利用VIPer53封装上系统实现经济型机顶盒供电
  12. 分页组件extremeComponents的使用
  13. 西门子200PLC指令详解——位逻辑指令
  14. 计算机网络-名词解释整理
  15. pthread_attr_setinheritsched,pthread_attr_setschedparam函数详解
  16. 通过温度湿度计算露点
  17. android wear iphone7,多款Android Wear手表不兼容苹果iPhone7
  18. 电脑白屏,电脑白屏是怎么回事?是系统的原因还是
  19. 坐地铁,玩Android
  20. 避雷:六种职场着装可能导致你面试失败

热门文章

  1. 接口测试工具(下篇)——命令行工具curl
  2. 阿里刘振飞:我们用了10年,从去IOE到OceanBase世界第一!
  3. EOJ 3452- 唐纳德先生和假骰子
  4. 【Debias】Model-Agnostic Counterfactual Reasoning for Eliminating Popularity Bias in RS(KDD‘21)
  5. 明源云童继龙:围绕地产生态链,做好数字化转型加速器
  6. 《MATLAB语音信号分析与合成(第二版)》:第10章 语音信号的合成算法
  7. 什么事DDoS?什么事ADS?看ADS如何治愈DDoS伤痛
  8. 互联网行业常见数据分类:用户数据、行为数据、业务数据
  9. Oracle 300问
  10. 用户注册邮箱通知和短信通知详解(php)