fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Number {
  5. private:
  6. int num;
  7.  
  8. public:
  9. void getNumber(void)
  10. {
  11. cout << "Enter an integer number: ";
  12. cin >> num;
  13. }
  14.  
  15. int returnNumber(void)
  16. {
  17. return num;
  18. }
  19. };
  20.  
  21. class Square : public Number {
  22. public:
  23. int getSquare(void)
  24. {
  25. int num, sqr;
  26. num = returnNumber();
  27. sqr = num * num;
  28. return sqr;
  29. }
  30. };
  31.  
  32. class Cube : public Number {
  33. private:
  34. public:
  35. int getCube(void)
  36. {
  37. int num, cube;
  38. num = returnNumber();
  39. cube = num * num * num;
  40. return cube;
  41. }
  42. };
  43.  
  44. int main()
  45. {
  46. Square objS;
  47. Cube objC;
  48. int sqr, cube;
  49.  
  50. objS.getNumber();
  51. sqr = objS.getSquare();
  52. cout << "Square of " << objS.returnNumber() << " is: " << sqr << endl;
  53.  
  54. objC.getNumber();
  55. cube = objC.getCube();
  56. cout << "Cube of " << objS.returnNumber() << " is: " << cube << endl;
  57.  
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Enter an integer number: Square of 1340719888 is: -2017369856
Enter an integer number: Cube   of 1340719888 is: 750141567