码迷,mamicode.com
首页 > 其他好文 > 详细

Problem B: 农夫果园 简单点,出题的方式简单点

时间:2017-04-13 20:49:31      阅读:428      评论:0      收藏:0      [点我收藏+]

标签:out   app   cas   std   log   ++   ase   price   names   

我走过最长的路,就是教主的套路
#include <iostream> #include <string> using namespace std; class Fruit { public: double price; double weight; double income; virtual void input(){cin>>price>>weight;} virtual double total(){return income;} }; class Apple:public Fruit { int m,n; public: void input() { double a,b; cin>>a>>b; price=a; weight=b; income=price*weight*30; } virtual double total() { return income; } }; class Banana:public Fruit { int m,n; public: virtual void input() { double a,b; cin>>a>>b; price=a; weight=b; income=price*weight*25; } virtual double total() { return income; } }; class Pear:public Fruit { int m,n; public: virtual void input() { double a,b; cin>>a>>b; price=a; weight=b; income=price*weight*20; } virtual double total() { return income; } }; 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 B: 农夫果园 简单点,出题的方式简单点

标签:out   app   cas   std   log   ++   ase   price   names   

原文地址:http://www.cnblogs.com/masterchd/p/6705939.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!