Can someone tell me if this program matches this assignment EXACTLY. It needs to be perfect for full credit. Thanks.
Instructions:
Write a function with 4 arguments so that the first 2 arguments will accept the length & width of a rectangle, the 3rd argument will be set to the perimeter, the 4th argument set to the area. The main program should call the required function twice: 1st call with input arguments of 1.5 and 5.0; second call with input arguments of 123.45 and 5.0. After each call to the function, the main program should print out the results - the function should not do any printing.
Here's what I have:
Code:
#include <iostream>
#include <cmath>
using namespace std;
//Functions used ...
void instructions();
float length;
float width;
void all(float length, float width, float& area, float& perim);
float areaf(float length, float width, float& area);
float perimf(float length, float width, float& perim);
//---------------------------------------------------------------------------------
int main ()
{
float area ;
float perim ;
instructions();
all( 1.5, 5.0, area, perim);
cout << "A rectangle with a length of 1.5 "
<< "and a width of 5.0 has an area of "
<< area << endl;
cout << "and a perimeter of "
<< perim << endl;
cout << endl;
all(123.45, 5.0, area, perim);
cout << "A rectangle with a length of 123.45 "
<< "and a width of 5.0 has an area of "
<< area << endl;
cout << "and a perimeter of "
<< perim << endl;
cout << endl;
return 0;
}
void all(float length, float width, float& area, float& perim)
{
area = areaf(length, width, area);
perim = perimf(length, width, perim);
}
float areaf(float length, float width, float& area)
{
area = 0;
area = length * width;
return area;
}
float perimf(float length, float width, float& perim)
{
perim = 0;
cout << length << " " << width << endl;
perim = (length * 2) + (width * 2);
cout << perim << endl;
return perim;
}
//---------------------------------------------------------------------------
// User instructions
void instructions ()
{
cout << "This program takes the length and width "
<< "of a rectangle and calculates" << endl;
cout << "the area and perimeter for two "
<< "sets of variables." << endl;
cout << endl;
} // End instructions function
Do you think my program matches the instructions exactly?