fork download
  1. //Isabel Tejeda CSC5 Chapter 4, page 220, #4
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * CATERGORIZE AREA OF RECTANGLE
  6.  * _____________________________________________________________________________
  7.  * This program will ask for the input of length and width for two rectangles. It
  8.  * will then calculate the area of both rectangles and determine which of the two
  9.  * rectangeles has the greater area, or if the areas are the same.
  10.  *
  11.  * Computation is based on the formula:
  12.  * area1 = length1 * width1
  13.  * area2 = length2 * width2
  14.  * _____________________________________________________________________________
  15.  * INPUT
  16.  * length1 : The legnth of the first rectangle
  17.  * width1 : The width of the first rectangle
  18.  * length2 : The length of the second rectangle
  19.  * width2 : The width of the second rectangle
  20.  *
  21.  * OUTPUT
  22.  * relationOfAreas : The relation between the two areas of the rectangles
  23.  * (Which one is greater than the other or if they are
  24.  * equal)
  25.  *
  26.  ******************************************************************************/
  27. #include <iostream>
  28. #include <string>
  29. using namespace std;
  30.  
  31. int main()
  32. {
  33. float length1; //The length of the first rectangle
  34. float width1; //The width of the first rectangle
  35. float length2; //The length of the second rectangle
  36. float width2; //The width of the second rectangle
  37. float area1; //The area of the first rectangle
  38. float area2; //The area of the second rectangle
  39. string relationOfAreas; /* The relation between the two areas of the rectangles
  40. (Which one of is greater than the other or if they are equal)*/
  41. //
  42. // Initialize Program Varaibles
  43. cout << "Enter the length of the first rectangle: "<< endl;
  44. cin >> length1;
  45. cout << "Enter the width of the first retangle: " << endl;
  46. cin >> width1;
  47. cout << "Enter the length of the second rectangle: " << endl;
  48. cin >> length2;
  49. cout << "Enter the width of the second rectangle: " << endl;
  50. cin >> width2;
  51. //
  52. // Calculate the Area of the Two Rectangles
  53. area1 = length1 * width1;
  54. area2 = length2 * width2;
  55. //
  56. // Finding the relation between the two area rectangles and Output Result
  57. if (area1 < area2)
  58. {
  59. relationOfAreas = "The second rectangle has the greater area.";
  60. cout << relationOfAreas;
  61. }
  62. else if (area1 == area2)
  63. {
  64. relationOfAreas = "The areas of the rectangles are the same.";
  65. cout << relationOfAreas;
  66. }
  67. else
  68. {
  69. relationOfAreas = "The first rectangle has the greater area.";
  70. cout << relationOfAreas;
  71. }
  72. return 0;
  73. }
Success #stdin #stdout 0.01s 5396KB
stdin
3
4
2
4
stdout
Enter the length of the first rectangle: 
Enter the width of the first retangle:  
Enter the length of the second rectangle: 
Enter the width of the second rectangle: 
The first rectangle has the greater area.