169k views
0 votes
Copy the main given below. Write the methods needed to produce the output given. YOU SHOULD NOT CHANGE MAIN

main to Copy
#include
using namespace std;
// prototypes go here
int main()
{
double length;
double width;
double perimeter;
double area;

getInput(length, width);
while (length >= 0)
{
area = calculations(length, width, perimeter);
printResults(length, width, perimeter, area);
getInput(length, width);
}

}

User Tudoricc
by
3.1k points

1 Answer

2 votes

Answer:

C++ code explained below

Step-by-step explanation:

CODE

#include <iostream>

using namespace std;

// prototypes go here

void getInput(double *l, double *w) {

cout << "Enter Length: ";

cin >> *l;

if(*l < 0) {

return;

}

cout << "Enter Width: ";

cin >> *w;

while(*w < 0) {

cout << "Width must be positive! Try Again" << endl;

cout << "Enter Width: ";

cin >> *w;

}

}

double calculations(double l, double w, double *perimeter) {

*perimeter = 2 * (l + w);

return l*w;

}

void printResults(double l, double w, double perimeter, double area) {

cout << "Rectangle Dimensions: " << l << " X " << w << endl;

cout << "perimeter: " << perimeter << endl;

cout << "Area: " << area << endl;

return;

}

int main()

{

double t;

// test(&t);

double length;

double width;

double perimeter;

double area;

//below line has to change if you need to work this example

//reason is length and width are local variable to main so other function can only change if address is passed so i have plase & sign before the variables while passing

//same has to be done for perimeter

getInput(&length, &width);

while (length >= 0)

{

area = calculations(length, width, &perimeter);

printResults(length, width, perimeter, area);

getInput(&length, &width);

}

}

User Djpeinado
by
3.4k points