#include <iostream>
#include <iomanip>
using namespace std;
class CFruit
{
public:
virtual void setprice(double price)=0;
virtual void setyields(double yields)=0;
virtual void toString()=0;
virtual ~CFruit(){}
protected:
double price; //价格
double yields; //总重量
};
/*以下需要考生实现
*/
int main(int argc, const char * argv[]) {
int mode;
string color;
double price;
double yield;
while(cin>>mode>>color>>price>>yield)
{
if(mode==0)
{
CApple c1;
c1.setprice(0);
c1.setyields(0);
c1.toString();
}
else if(mode==1)
{
CApple c1(color);
c1.setprice(price);
c1.setyields(yield);
c1.toString();
}
else
{
CFruit *ptr = new CApple(color);
ptr->setprice(price);
ptr->setyields(yield);
ptr->toString();
delete ptr;
}
}
}
0 REDD 0 0
1 BLUE 12 34
2 GREEN 0.3 1000
颜色:RED,价格:0,收成:0,收入:0
颜色:BLUE,价格:12,收成:34,收入:408
颜色:GREEN,价格:0.3,收成:1000,收入:300