fork download
  1. #include <iostream>
  2. using namespace std;
  3. class myBase
  4. {
  5. private:
  6. int foodmoney;
  7. int hobbymoney;
  8.  
  9. public:
  10. void setdata();
  11. friend int caldata();
  12. };
  13. void myBase::setdata()
  14. {
  15. cout<<"Enter foodmoney :" ;cin>>foodmoney;
  16. cout<<"enter hoobymoney:";cin>>hobbymoney;
  17. }
  18. int caldata(int sum,int foodmoney,int hobbymoney)
  19. {
  20. cin>>foodmoney;
  21. cin>>hobbymoney;
  22. sum=(foodmoney+hobbymoney)/2;
  23. return sum;
  24.  
  25. }
  26.  
  27.  
  28. class Derivedclass:public myBase
  29. {
  30. int moneyforfood,moneyforhobby;
  31. public:
  32. int setmydrived(int moneyforfood,int moneyforhobby)
  33. {
  34. cout<<"enter money for food(drived class)"<<endl;
  35. cin>>moneyforfood;
  36. cout<<"enter money for hobby(drived class)"<<endl;
  37. cin>>moneyforhobby;
  38. }
  39.  
  40. int calculatedrived()
  41. {
  42.  
  43. int sumd=(moneyforfood+moneyforhobby);
  44. cout<<"avg money on frived class "<<sumd<<endl;
  45. return sumd;
  46. }
  47. };
  48.  
  49. int main()
  50. {
  51. myBase baseobj;
  52. baseobj.setdata();
  53. int caldata();
  54. Derivedclass obj;
  55. int setmydrived();
  56. obj.calculatedrived();
  57. //system("pause");
  58.  
  59. }
Success #stdin #stdout 0s 2900KB
stdin
1550
500
stdout
Enter foodmoney :enter hoobymoney:avg money on frived class -1082271457