fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // Base class
  6. class nut
  7. {
  8. public:
  9. void setType(int almond, int walnut )
  10. {
  11. almond ;
  12. walnut;
  13. }
  14. protected:
  15. char type;
  16. };
  17.  
  18. class almond_butter: public nut
  19. {
  20.  
  21. public:
  22. string getNutrient()
  23. {
  24. cout<<"Protein: 30g "<<endl;
  25. }
  26.  
  27.  
  28.  
  29. // Derived class
  30. class almond: public nut
  31. {
  32. public:
  33. string getType()
  34. {
  35. int choice;
  36. cout<<" Choose type of nuts:"<<endl;
  37. cout<<"1. Almond Butter"<<endl;
  38. cout<<"2. Almond Milk"<<endl;
  39. cin>>choice;
  40.  
  41. if(choice==1)
  42. {
  43. almond al;
  44. cout<<al.getNutrient()<<endl;
  45. }
  46. else if(choice==2)
  47. {
  48.  
  49. cout<<"This is the type of almond"<<endl;
  50. cout<<" Almond Butter "<<endl;
  51. cout<<"Characteristics: "<<endl;
  52. cout<<"Details----------------------------------------------------------"<<endl;
  53. cout<<"Protein: 30g "<<endl;
  54. cout<<"Carbohydrates:28g "<<endl;
  55. cout<<"Cholesterol: 0 "<<endl;
  56. cout<<"Calories:60cal "<<endl;
  57. cout<<" Almond Milk "<<endl;
  58. cout<<"Characteristics: "<<endl;
  59. cout<<"Details---------------------------------------------------------"<<endl;
  60. cout<<"Protein: 20 "<<endl;
  61. cout<<"Carbohydrates:20 "<<endl;
  62. cout<<"Cholesterol: 0 "<<endl;
  63. cout<<"Calories: 52 cal "<<endl;
  64. }
  65.  
  66.  
  67. else
  68. {
  69. cout<<"Invalid"<<endl;
  70. }
  71. }
  72.  
  73. };
  74.  
  75. int main(void)
  76. {
  77. almond al;
  78. int choice;
  79. cout<<" Choose type of nuts:"<<endl;
  80. cout<<"1. Almond Butter"<<endl;
  81. cout<<"2. Almond Milk"<<endl;
  82. cin>>choice;
  83.  
  84. if(choice==1)
  85. {
  86. almond al;
  87. cout << al.getType() << endl;
  88. }
  89. else if(choice==2)
  90. {
  91.  
  92. cout<<"This is the type of almond"<<endl;
  93. cout<<" Almond Butter "<<endl;
  94. cout<<"Characteristics: "<<endl;
  95. cout<<"Details----------------------------------------------------------"<<endl;
  96. cout<<"Protein: 30g "<<endl;
  97. cout<<"Carbohydrates:28g "<<endl;
  98. cout<<"Cholesterol: 0 "<<endl;
  99. cout<<"Calories:60cal "<<endl;
  100. cout<<" Almond Milk "<<endl;
  101. cout<<"Characteristics: "<<endl;
  102. cout<<"Details---------------------------------------------------------"<<endl;
  103. cout<<"Protein: 20 "<<endl;
  104. cout<<"Carbohydrates:20 "<<endl;
  105. cout<<"Cholesterol: 0 "<<endl;
  106. cout<<"Calories: 52 cal "<<endl;
  107. }
  108.  
  109.  
  110. else
  111. {
  112. cout<<"Invalid"<<endl;
  113. }
  114. }
  115.  
  116. cout<< al.getType() <<endl;
  117.  
  118. return 0;
  119. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void nut::setType(int, int)’:
prog.cpp:11:17: warning: statement has no effect [-Wunused-value]
          almond ;
                 ^
prog.cpp:12:16: warning: statement has no effect [-Wunused-value]
          walnut;
                ^
prog.cpp: At global scope:
prog.cpp:116:5: error: ‘cout’ does not name a type
     cout<< al.getType() <<endl;
     ^
prog.cpp:118:4: error: expected unqualified-id before ‘return’
    return 0;
    ^
prog.cpp:119:1: error: expected ‘;’ after class definition
 }
 ^
prog.cpp: In member function ‘std::string almond_butter::getNutrient()’:
prog.cpp:25:7: warning: no return statement in function returning non-void [-Wreturn-type]
       }
       ^
prog.cpp: In member function ‘std::string almond_butter::almond::getType()’:
prog.cpp:44:18: error: ‘class almond_butter::almond’ has no member named ‘getNutrient’
         cout<<al.getNutrient()<<endl;
                  ^
prog.cpp:71:7: warning: no return statement in function returning non-void [-Wreturn-type]
       }
       ^
prog.cpp: In member function ‘int almond_butter::main()’:
prog.cpp:77:12: warning: unused variable ‘al’ [-Wunused-variable]
     almond al;
            ^
prog.cpp:114:7: warning: no return statement in function returning non-void [-Wreturn-type]
       }
       ^
stdout
Standard output is empty