In: Computer Science
needs to be done in C++
Q3. Just just have to code the function and the function call statement.
This program is for a Carpet Store. Create a function, named CarpetCost, that will have 3 parameters that are float values of length and width and price. The function will return the Total Cost of a piece of Carpet. The values for the Length and the Width is in Feet. The price of the carpet is in Dollars per Square Yard.
The equation for the Area of the Carpet in Square Feet is: Area_sq_ft = length * width;
The equation for the Area in Carpet in Sqaure Yards is : Area_sq_yd = Area_sq_ft / 9.0;
The equation for the Price of the Carpet in Square Yards is : Price = Area_sq_yd * price;
Example RUN:
Enter the length and width of the Carpet > 5.5 9.5
Enter the price of the carpet in dollar.cents format ($##.##) > = 44.40
FUNCTION TO COMPUTE THE COST OF CARPET
float CarpetCost(float length,float width,float price)
{
    //declare the variables
    float Area_sq_ft,Area_sq_yd,Price;
    //compute the area in square feet
    Area_sq_ft = length * width;
    //compute the area in square yards
    Area_sq_yd = Area_sq_ft/9.0;
    //compute the price of Carpet
    Price = Area_sq_yd * price;
    //return the price
    return(Price);
}
PROGRAMMING IMPLEMENTATION IN C++
#include<iostream>
#include<iomanip>
using namespace std;
float CarpetCost(float length,float width,float price)
{
    //declare the variables
    float Area_sq_ft,Area_sq_yd,Price;
    //compute the area in square feet
    Area_sq_ft = length * width;
    //compute the area in square yards
    Area_sq_yd = Area_sq_ft/9.0;
    //compute the price of Carpet
    Price = Area_sq_yd * price;
    //return the price
    return(Price);
}
//driver program
int main()
{
   //variable declaration
   float length,width,price,cost;
   cout<<endl<<"Enter the length and width of
the Carpet > ";
   cin>>length>>width; //read the length and
width
   cout<<endl<<"Enter the price of the carpet
in dollar,cents format ($##.##) > ";
   cin>>price; //read the price
   //call to CarpetCost()
   cost = CarpetCost(length,width,price);
   cout<<fixed<<setprecision(2);
   //print the carpet cost
   cout<<endl<<"Cost of Carpet :
$"<<cost;
}
OUTPUT