SHARE
TWEET

Untitled

a guest Apr 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Rectangle
  5. {
  6. private:
  7.     double width, length;
  8.  
  9. public:
  10.     void setWidth(double);
  11.     void setlength(double);
  12.  
  13.     double getWidth() const;
  14.     double getLength() const;
  15.     double getArea() const;
  16. };
  17. void Rectangle::setWidth(double w)
  18. {
  19.     width = w;
  20. }
  21. void Rectangle::setlength(double len)
  22. {
  23.     length = len;
  24. }
  25. double Rectangle::getWidth() const
  26. {
  27.     return width;
  28. }
  29. double Rectangle::getLength() const
  30. {
  31.     return length;
  32. }
  33. double Rectangle::getArea() const
  34. {
  35.     return width * length;
  36. }
  37.  
  38.  
  39. //Function main
  40. int main()
  41. {
  42.     Rectangle box;
  43.     double rectWidth; //Local variable for width
  44.     double rectLength; //Local variable for length
  45.  
  46.     cout << "This program will calcuilate the area of a\n";
  47.     cout << "rectangle. What is the width ?";
  48.     cin >> rectWidth;
  49.     cout << "What is the length? ";
  50.     cin >> rectLength;
  51.  
  52.     box.setWidth(rectWidth);
  53.     box.setlength(rectLength);
  54.  
  55.     cout << "Here is the rectangle's data:\n";
  56.     cout << "Width: " << box.getWidth() << endl;
  57.     cout << "Length: " << box.getLength() << endl;
  58.     cout << "Area: " << box.getArea() << endl;
  59.     return 0;
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top