fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class rectangle {
  5. private:
  6. float Width;
  7. float Length;
  8.  
  9. public:
  10. //Contstructor
  11. rectangle(float w=1, float l=1);
  12.  
  13. float GetWidth();
  14. void SetWidth(float w);
  15.  
  16. float GetLength();
  17. void SetLength(float l);
  18.  
  19. float Area();
  20. float Perimeter();
  21. float draw();
  22. };
  23.  
  24.  
  25. rectangle::rectangle(float w, float l):Width(w), Length (l) {}
  26.  
  27.  
  28. //width
  29. float rectangle::GetWidth()
  30. {
  31. return Width;
  32. };
  33.  
  34. void rectangle::SetWidth(float w)
  35. {
  36. Width = w;
  37. float userWidth;
  38. cout << "Enter a width between 0 and 20.0: "; cin >> userWidth;
  39. while (userWidth >= 20 || userWidth < 0)
  40. {
  41. cout << "Enter a width between 0 and 20.0: ";
  42. cin >> userWidth;
  43. }
  44. };
  45.  
  46.  
  47. //Length
  48. float rectangle::GetLength()
  49. {
  50. return Length;
  51. };
  52.  
  53. void rectangle::SetLength(float l)
  54. {
  55. Length = l;
  56. float userLength;
  57. cout << "Enter a width between 0 and 20.0: "; cin >> userLength;
  58. while (userLength >= 20 || userLength < 0)
  59. {
  60. cout << "Enter a width between 0 and 20.0: ";
  61. cin >> userLength;
  62. }
  63. };
  64.  
  65.  
  66. //calculations
  67. float rectangle::Area()
  68. {
  69. return Width*Length;
  70. };
  71. float rectangle::Perimeter()
  72. {
  73. return 2*(Width+Length);
  74. };
  75.  
  76.  
  77. int draw() {
  78. float Length = (float) 3.11, Width = (float) 5.99;
  79. int Length_int, Width_int;
  80. Length_int = (int) Length;
  81. Width_int = (int) Width;
  82. for(int i = 0; i < Length_int; i++)
  83. {
  84. for (int i = 0; i < Width_int; i++)
  85. cout << '+';
  86. cout << endl;
  87. }
  88. return 0;
  89. };
  90.  
  91.  
  92. int main(){
  93.  
  94. rectangle r1(2,3);
  95. cout << "Width: " << r1.GetWidth() << " \nHeight: " << r1.GetLength() << "\nArea: " << r1.Area() << "\nPerimeter: " << r1.Perimeter() << endl;
  96.  
  97. system("pause");
  98. return 0;
  99. };
Success #stdin #stdout #stderr 0s 3296KB
stdin
Standard input is empty
stdout
Width: 2 
Height: 3
Area: 6
Perimeter: 10
stderr
sh: pause: not found