fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class rect
  5. {
  6. private:
  7. int len,wid;
  8. public:
  9. rect()
  10. {
  11. len=0;
  12. wid=0;
  13. }
  14.  
  15. ~rect()
  16. {
  17.  
  18. }
  19. void setval(int a, int b)
  20. {
  21. len=a;
  22. wid=b;
  23. }
  24.  
  25. int getlen()
  26. {
  27. return len;
  28. }
  29.  
  30. int getwid()
  31. {
  32. return wid;
  33. }
  34.  
  35. void print()
  36. {
  37.  
  38. cout<< "length: "<<len<< " width: "<<wid<<endl;
  39. }
  40.  
  41. int area()
  42. {
  43. return len*wid;
  44. }
  45. };
  46.  
  47. int main()
  48. {
  49. rect r;
  50. cout<< "initial value"<<endl;
  51. r.print();
  52. int a,b;
  53. cout<< "enter length: ";
  54. cin>>a;
  55.  
  56. cout<< "enter width: ";
  57. cin>>b;
  58. r.setval(a,b);
  59. cout<< "area: "<<r.area()<<endl;
  60. //r.print();
  61. }
  62.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
initial value
length: 0 width: 0
enter length: enter width: area: 1596389504