Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Flower
- {
- protected:
- char name[100];
- int cost;
- char type[100];
- public:
- Flower(){}
- Flower(char *n, int p, char *t)
- {
- strcpy(name,n);
- cost=p;
- strcpy(type,t);
- }
- virtual int price()=0;
- char* getType()
- {
- return type;
- }
- char* getName()
- {
- return name;
- }
- char* getKind()
- {
- return type;
- }
- bool operator==(Flower &rhs)
- {
- return !strcmp(this->type,rhs.type);
- }
- };
- class PotFlower:public Flower
- {
- int bloomedFlowers;
- public:
- PotFlower(){}
- PotFlower(char *n, int p, char* t, int b):Flower(n,p,t)
- {
- bloomedFlowers=b;
- }
- int price()
- {
- return cost+bloomedFlowers;
- }
- };
- class CutFlower:public Flower
- {
- int daysSinceHarvested;
- public:
- CutFlower(){}
- CutFlower(char *n, int p, char *t, int d):Flower(n,p,t)
- {
- daysSinceHarvested=d;
- }
- int price()
- {
- return cost+((daysSinceHarvested<10)?20:(daysSinceHarvested<=35)?10:0);
- }
- };
- void specialFlowers(Flower **arr, int n, Flower &flower)
- {
- int id=-1;
- for(int i=0;i<n;i++)
- {
- if(flower==*arr[i]&&(id==-1 || arr[id]->price()<arr[i]->price()))
- id=i;
- }
- cout<<arr[id]->getName()<<" "<<arr[id]->getKind()<<" "<<arr[id]->price()<<endl;
- }
- int main() {
- char name[10], kind[10];
- int type, age, num, price;
- int n;
- cin >> n;
- Flower **flowers;
- flowers = new Flower*[n];
- for (int i = 0; i < n; i++) {
- cin >> type >> name >> price >> kind;
- if (type == 1) {
- cin >> age;
- flowers[i] = new CutFlower(name, price, kind, age);
- }
- else {
- cin >> num;
- flowers[i] = new PotFlower(name, price, kind, num);
- }
- }
- CutFlower nov("opuntia", 90, "cactus", 10);
- specialFlowers(flowers, n, nov);
- for (int i = 0; i < n; i++) delete flowers[i];
- delete [] flowers;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement