Code a main program and the functions to do the following: A function to Read in
ID: 3808194 • Letter: C
Question
Code a main program and the functions to do the following: A function to Read in double variables of length and width, using the keyboard A function to Calculate and return a double of the area of a rectangle A function to Print the length and width of the lot, the length and width of the house, area to be cut, and time to cut in minutes The application (main method) wants to know how much time to cut the grass of a rectangle lot with a rectangle house sitting in the middle of the lot. There are multiple sets of data, the last one has -1 -1 for the length and width. The algorithm is: 1, set variables of lengthHouse, widthHouse, lengthYard, widthYard, arealot, areaHouse, areaToCut, timeToCut 2 Set a constant of 2 seconds, called time, which is the time to cut 1 square foot of grass 3 call Read function to read lenth and with of yard 4 while (lengthYard ! = -1) 4.1 call Read function to read lenth and width of house 4.2 call Calculate function to calculate area of yard, returning value to areaLot 4.3 call Calculate function to calculate area of house, returning value to areaHouse 4.4 areaToCut = areaLot - areaHouse 4.5 timeToCut = areaToCut/time/60 4.7 call Print function 4.8 call Read function to read length and width of yard 5. StopExplanation / Answer
Code has been written as per the algortihm mentioned in the question .
Program :
#include<iostream>
using namespace std;
#define HOUSE 0
#define LOT 1
#define time 2
void read_dimensions(double *length , double *width,int type);
long double calculate_area(double length , double width);
void printAll(double lengthHouse,double widthHouse,double lengthYard,double widthYard,long double areaToCut,long double timeToCut);
int main()
{
double lengthHouse , widthHouse , lengthYard , widthYard;
long double areaLot,areaHouse,areaToCut,timeToCut;
read_dimensions(&lengthYard,&widthYard,LOT);
while(lengthYard != -1)
{
read_dimensions(&lengthHouse,&widthHouse,HOUSE);
areaLot = calculate_area(lengthYard,widthYard);
areaHouse = calculate_area(lengthHouse,widthHouse);
areaToCut = areaLot - areaHouse;
timeToCut = areaToCut/time/60;
printAll(lengthHouse,widthHouse,lengthYard,widthYard,areaToCut,timeToCut);
read_dimensions(&lengthYard,&widthYard,LOT);
}
}
void read_dimensions(double *length , double *width,int type)
{
if(type == HOUSE)
cout<<endl<<"Enter the House Length"<<endl;
else
cout<<endl<<"Enter the Lot Length"<<endl;
cin>>*length;
if(type == HOUSE)
cout<<"Enter the House width"<<endl;
else
cout<<"Enter the Lot width"<<endl;
cin>>*width;
}
long double calculate_area(double length , double width)
{
long double area;
area = length * width ;
return area;
}
void printAll(double lengthHouse,double widthHouse,double lengthYard,double widthYard,long double areaToCut,long double timeToCut)
{
cout<<endl<<"Length of house "<<lengthHouse<<endl;
cout<<"Width of house "<<widthHouse<<endl;
cout<<"Length of Lot "<<lengthYard<<endl;
cout<<"Width of Lot "<<widthYard<<endl;
cout<<"Area to be cut "<<areaToCut<<endl;
cout<<"Time to cut "<<timeToCut<<" minutes"<<endl;
}