Guest User

Untitled

a guest
Apr 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class Fruit
  2. {
  3. private:
  4. std::string m_name;
  5. std::string m_color;
  6.  
  7. public:
  8. Fruit(std::string name, std::string color)
  9. : m_name(name), m_color(color)
  10. {
  11. }
  12.  
  13. std::string getName() const { return m_name; }
  14. std::string getColor() const { return m_color; }
  15.  
  16. };
  17.  
  18. class Apple : public Fruit
  19. {
  20. private:
  21. double m_fiber;
  22.  
  23. public:
  24. Apple(std::string name, std::string color, double fiber)
  25. :Fruit(name, color), m_fiber(fiber)
  26. {
  27. }
  28.  
  29. double getFiber() const { return m_fiber; }
  30.  
  31. friend std::ostream& operator<<(std::ostream &out, const Apple &a)
  32. {
  33. out << "Apple (" << a.getName() << ", " << a.getColor() << ", " << a.getFiber() << ")n";
  34. return out;
  35. }
  36. };
Add Comment
Please, Sign In to add comment