fork download
  1. //Angel Lugo CSC5 Chapter 4, P. 220, #4
  2. //
  3. /**************************************************************
  4. *
  5. * COMPUTE THE AREA OF TWO RECTANGLES AND COMPARE THEM
  6. * ____________________________________________________________
  7. * This program computes the area of two rectangles
  8. * and compares which rectangle has the greater area
  9. * or if the areas are the same.
  10. *
  11. * Computation is based on:
  12. * The user's input on the length and width
  13. * entered for each rectangle.
  14. * ____________________________________________________________
  15. * INPUT
  16. * lengthOne: Length inputed by user for rectangle one
  17. * widthOne : width inputed by user for rectangle one
  18. * lengthTwo: Length inputed by user for rectangle two
  19. * widthTwo : width inputed by user for rectangle two
  20. *
  21. * OUTPUT
  22. * areaOne : Area of rectangle one
  23. * areaTwo : Area of rectangle two
  24. *
  25. **************************************************************/
  26. #include <iostream>
  27. #include <iomanip>
  28. using namespace std;
  29.  
  30. int main ()
  31. {
  32. //
  33. // Declare variables to store inputs
  34. float lengthOne;
  35. float widthOne;
  36. float lengthTwo;
  37. float widthTwo;
  38. float areaOne;
  39. float areaTwo;
  40. //
  41. // Display information in "cout"
  42. cout << "Area comparison of two rectangles" << endl;
  43. //
  44. // Display information in "cout" and store user's input in "cin" for variable
  45. cout << "What is the length of the first rectangle? ";
  46. cin >> lengthOne;
  47. cout << "\nWhat is the width of the first rectangle? ";
  48. cin >> widthOne;
  49. //
  50. // Calculate area for rectangle one
  51. areaOne = lengthOne * widthOne;
  52. cout << "\nArea one: " << areaOne;
  53. //
  54. // Display information in "cout" and store user's input in "cin" for variable
  55. cout << "\n\nWhat is the length of the second rectangle? ";
  56. cin >> lengthTwo;
  57. cout << "\nWhat is the width of the second rectangle? ";
  58. cin >> widthTwo;
  59. //
  60. // Calculate area for rectangle two
  61. areaTwo = lengthTwo * widthTwo;
  62. cout << "\nArea two: " << areaTwo;
  63. //
  64. // Check is are one is greater then area two
  65. if (areaOne > areaTwo)
  66. {
  67. cout << "\n\nThe first reactangle has a greater area then the second reactangle.";
  68. }
  69. //
  70. // Check is are two is greater then area one
  71. if (areaOne < areaTwo)
  72. {
  73. cout << "\n\nThe second reactangle has a greater area then the first reactangle.";
  74. }
  75. //
  76. // Check if both areas are equal
  77. if (areaOne == areaTwo)
  78. {
  79. cout << "\n\nThe two rectangles have equal areas.";
  80. }
  81. return 0;
  82. }
Success #stdin #stdout 0.01s 5436KB
stdin
15
30
25
20
stdout
Area comparison of two rectangles
What is the length of the first rectangle? 
What is the width of the first rectangle? 
Area one: 450

What is the length of the second rectangle? 
What is the width of the second rectangle? 
Area two: 500

The second reactangle has a greater area then the first reactangle.