Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Rectangle {
  7. string name;
  8. int width, length, area;
  9.  
  10. public:
  11. int getWidth() {return width;}
  12. int getLength() {return length;}
  13. int getArea() {return area;}
  14. string getName() {return name;}
  15.  
  16. void print() {
  17. cout << name << ": " << width << " * " << length << " = " << getArea() << endl;
  18. }
  19.  
  20. void setValues() {
  21. cout << "Enter the name of the rectangle. ";
  22. cin >> name;
  23. cout << "Enter the length of " << name << ". ";
  24. cin >> length;
  25. cout << "Enter the width of " << name << ". ";
  26. cin >> width;
  27. cout << endl;
  28. area = width * length;
  29. }
  30.  
  31. void compare(Rectangle rect) {
  32. string res = area > rect.getArea()
  33. ? " is greater than "
  34. : area < rect.getArea()
  35. ? " is less than "
  36. : " is equal to ";
  37. cout << "\nThe area of " << name << res << rect.getName() << "\n\n";
  38. }
  39. };
  40.  
  41. int main() {
  42. Rectangle rect1, rect2;
  43. rect1.setValues();
  44. rect2.setValues();
  45. rect1.print();
  46. rect2.print();
  47. rect1.compare(rect2);
  48. system("pause");
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement