首页 > 代码库 > Problem B: 农夫果园 简单点,出题的方式简单点
Problem B: 农夫果园 简单点,出题的方式简单点
我走过最长的路,就是教主的套路
#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: 农夫果园 简单点,出题的方式简单点
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。