Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. // Function prototypes:
  6.  
  7.  
  8. void GetValues(double&, double&);
  9.  
  10. double ComputeArea(double, double);
  11.  
  12. void PrintArea(double);
  13.  
  14.  
  15. int main()
  16. {
  17. double length, width, area;
  18.  
  19. cout << "This program computes the area of a rectangle." << endl;
  20. cout << "You will be prompted to enter both the length and width.";
  21. cout << endl << "Enter a real number (such as 7.88 or 6.3) for each.";
  22. cout << endl << "The program will then compute and print the area.";
  23. cout << endl;
  24.  
  25. // call function GetValues(length, width) here
  26. GetValues(length, width);
  27. // call function ComputeArea(length, width) here
  28. area = ComputeArea(length, width);
  29. // call function PrintArea(area) here
  30. PrintArea(area);
  31. return 0;
  32. }
  33.  
  34.  
  35. /*
  36. Purpose: To ask the user for the length and width of a rectangle and
  37. to return these values via the two parameters.
  38. Return: Length The length entered by the user.
  39. Width The width entered by the user.
  40. */
  41.  
  42. void GetValues(double & l, double & w)
  43. {
  44. // add code to get Length and Width
  45.  
  46. cout << "Please enter length and width values" << endl;
  47. cin >> l >> w;
  48. }
  49.  
  50.  
  51. /* Given: Length The length of the rectangle.
  52. Width The width of the rectangle.
  53. Purpose: To compute the area of this rectangle.
  54. Return: The area in the function name.
  55. */
  56.  
  57. double ComputeArea(double l, double w)
  58. {
  59. double a = l * w;
  60.  
  61. return a;
  62. }
  63.  
  64.  
  65.  
  66. /* Given: Area The area of a rectangle.
  67. Purpose: To print Area.
  68. Return: Nothing.
  69. */
  70. void PrintArea(double a)
  71. {
  72. cout << a << endl;
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement