fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class priceName
  7. {
  8. public:
  9. string getName()
  10. {
  11. return name;
  12. }
  13. double getPrice()
  14. {
  15. return price;
  16. }
  17. void setName(string i)
  18. {
  19. this->name=i;
  20. }
  21. void setPrice(double i)
  22. {
  23. this->price=i;
  24. }
  25. private:
  26. string name;
  27. double price;
  28. };
  29.  
  30. class iFood
  31. {
  32. public:
  33. iFood(string i, double j)
  34. {
  35. pn.setName(i);
  36. pn.setPrice(j);
  37. }
  38. void show()
  39. {
  40. cout<<pn.getName()<<" : "<<pn.getPrice()<<endl;
  41. }
  42. private:
  43. priceName pn;
  44. };
  45.  
  46. class iDrink
  47. {
  48. public:
  49. iDrink(string i, double j)
  50. {
  51. pn.setName(i);
  52. pn.setPrice(j);
  53. }
  54. void show()
  55. {
  56. cout<<pn.getName()<<" : "<<pn.getPrice()<<endl;
  57. }
  58. private:
  59. priceName pn;
  60. };
  61.  
  62. int main(void)
  63. {
  64.  
  65. iFood food("apple",0.99);
  66. iDrink drink("coke",1.99);
  67.  
  68. food.show();
  69. drink.show();
  70.  
  71. return(0);
  72. }
  73.  
Success #stdin #stdout 0.02s 2860KB
stdin
Standard input is empty
stdout
apple : 0.99
coke : 1.99