Get a copy of the area.cpp file by: o Entering the cp command: cp Inet/datalftp/
ID: 3732987 • Letter: G
Question
Get a copy of the area.cpp file by: o Entering the cp command: cp Inet/datalftp/pub/class/110/ftp/cpp/area.cpp area.cpp or, using your mouse to copy and paste the program into Pico, or o using the Hercules command-line ftp program to copy this file from the CS Department's anonymous ftp site. The path: pub/class/110/ttp/cpp The file area.cpp The purpose of this program is to practice using user defined functions with reference parameters . Add code to the program to complete it. Compile and run this C++ program. When it is running correctly, show it to your lab instructor. Copyright: Department of Computer Science, University of Regina.Explanation / Answer
Let's start with answer.
I have improvised the code a bit for better viewing and to remove compilations errors.
1. Made all float to double to mainatin uniformity.
2. Added extra endl for better spacing.
Code:(Comments have been added).
#include <iostream>
using namespace std;
void GetValues(double &, double &);
double ComputeArea(double, double);
void PrintArea(double);
int main()
{
double length, width, area;
cout << "This program computes the area of a rectangle." << endl;
cout << "You will be prompted to enter both the length and width.";
cout << endl << "Enter a real number (such as 7.88 or 6.3) for each.";
cout << endl << "The program will then compute and print the area.";
cout << endl << endl;
GetValues(length, width);
area = ComputeArea(length, width);
PrintArea(area);
return 0;
}
void GetValues(double & l, double & w){
// Ask user for length.
cout << "Enter length of rectangle:";
// User input length.
cin >> l;
// Ask user for width.
cout << "Enter width of rectangle:";
// User input width.
cin >> w;
}
double ComputeArea(double l, double w){
// Area of rectangle is multiplication of length and width.
return l*w;
}
void PrintArea(double a){
// Show user area of rectangle.
cout << endl << "The area of rectangle is " << a << endl;
}
This completes my answer, for any extra querries post in comments.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.