Question

In: Computer Science

Code in C++ programming language description about chose favorite fruit and wage color of fruit in lesson Class object (Multiple class).

Code in C++ programming language description about chose favorite fruit and wage  color of fruit in lesson Class object (Multiple class).

Solutions

Expert Solution

#include

#include

#include

using namespace std;

enum Color{RED=0,BLUE,GREEN,YELLOW};

string colors[]={"RED","BLUE","GREEN","YELLOW"};

class fruit{

  protected:

    string name;

    enum Color color;

  public:

    fruit(string name,Color clr)

    :name(name), color(clr){}

    void input(){

      int cl;

      cout<<" Enter name fruit: ";cin.sync();getline(cin,name);

      cout<<" 0.RED\n 1.BLUE\n 2.GREEN\n 3.YELLOW"<

      cout<<" Enter color of fruit: ";

      cin>>cl;

      if(cl==0) color=RED;

      else if(cl==1) color=BLUE;

      else if(cl==2) color=GREEN;

      else if(cl==3) color=YELLOW;

      else color=GREEN;

    }

    void printResult(){

      cout<

    }

};

class apple:public fruit{

  protected:

    float kilo;

  public:

    apple(string name, Color color,float kg)

    :fruit(name,color),kilo(kg){}

    void setKilo_ap(){

      cout<<" Input kilo: ";cin>>kilo;

    }

    void printKilo(){

      fruit::printResult();

      cout<<"Kilo = "<

    }

};

class banana: public fruit{

  protected:

    float kilo;

  public:

    banana(string name,Color color)

    :fruit(name,color){}

    void print(){

      fruit::printResult();

      fruit::input();

  }

   void setKilo_ba(){      

    cout<<" Input kilo: ";cin>>kilo;

  }

  void printKilo(){

    cout<<"Kilo = "<

  }

};

int main(){

  apple ap("Apple",RED,1.25);

  banana ba("Banana",YELLOW);ap.printKilo();

  ba.printResult();ba.printKilo();

  cout<

  

  ap.input();cin.sync();ap.setKilo_ap();

  ba.input();ba.setKilo_ba();

  cout<

  

  ap.printKilo();

  ba.printResult();ba.printKilo();

  cout<

}


Related Solutions

Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson copy constructor example.
Class object in C++ programming language description about lesson copy constructor example.
Class object in C++ programming language description about lesson static variable example.
Class object in C++ programming language description about lesson static variable example.
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson inheritance multi level example.
Class object in C++ programming language description about lesson inheritance multi level example.
Class object in C++ programming language description about lesson unary overloading function example.
Class object in C++ programming language description about lesson unary overloading function example.
Code in C++ programming language description about lesson Calculator (multiple, sum, dived, sub) example.
Code in C++ programming language description about lesson Calculator (multiple, sum, dived,  sub) example.
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT