fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // getWidth, getArea, and displayData
  5. double getLength();
  6. double getWidth();
  7. double getArea( double&, double&);
  8. void displayData( double&, double&, double& );
  9.  
  10. int main() {
  11. double length, width, area;
  12.  
  13. // Get the rectangle's length.
  14. length = getLength();
  15.  
  16. // Get the rectangle's width.
  17. width = getWidth();
  18.  
  19. // Get the rectangle's area.
  20. area = getArea( length, width );
  21.  
  22. // Display the rectangle's data.
  23. displayData( length, width, area );
  24.  
  25. return 0;
  26. }
  27.  
  28. // Enter length and return that value as a double.
  29. double getLength() {
  30. double length;
  31. cout << "Enter the rectangle's length: ";
  32. cin >> length;
  33. return length;
  34. }
  35. // enter width and return that value as a double.
  36. double getWidth() {
  37. double width;
  38. cout << "Enter the rectangle's width: ";
  39. cin >> width;
  40. return width;
  41. }
  42.  
  43. // return the rectangle's area. The area is calculated by len
  44. double getArea( double& len, double& wid) {
  45. return len* wid;
  46. }
  47.  
  48. // displayData - This function should accept the rectangle's length, width, and area
  49. void displayData( double& len, double& wid, double& area ) {
  50. cout << "The length is:" << len<< endl;
  51. cout << "The width is:" << wid<< endl;
  52. cout <<"Total area is:" << area <<endl;
  53. }
Success #stdin #stdout 0s 5472KB
stdin
10
30
stdout
Enter the rectangle's length: Enter the rectangle's width: The length is:10
The width is:30
Total area is:300