The template shown below must be incorporated into the code showed after the template Template: // -- brief statement as to the file’s purpose //XXX XXX- ADD YOUR SECTION NUMBER //Include statements #include #include using namespace std; //Global declarations: Constants and type definitions only -- no variables //Function prototypes int main() { //In cout statement below SUBSTITUTE your name and lab number cout << "Your name -- Lab Number" << endl << endl; //Variable declarations //Program logic //Closing program statements system("pause"); return 0; } //Function definitions
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
The template shown below must be incorporated into the code showed after the template
Template:
// -- brief statement as to the file’s purpose
//XXX XXX- ADD YOUR SECTION NUMBER
//Include statements
#include
#include
using namespace std;
//Global declarations: Constants and type definitions only -- no variables
//Function prototypes
int main()
{
//In cout statement below SUBSTITUTE your name and lab number
cout << "Your name -- Lab Number" << endl << endl;
//Variable declarations
//
//Closing program statements
system("pause");
return 0;
}
//Function definitions
Code:
#include<iostream>
#include <iomanip>
using namespace std;
//function prototypes
float convToFeet(float, float, float);
//main function
int main()
{
// variable declaration
char woodType;
float totalCharge = 0.0, eachCost = 0.0, woodWidth, woodHeight, woodLength;;
int noOfpc;
cout << setprecision(2) << fixed;
//infinite loop until it obtains the character 'T'
do
{
cout << "\nEnter item: ";
cin >> woodType;// get the input(char type) from the user
if (woodType != 'T')
{
//read all required values
cin >> noOfpc >> woodWidth >> woodHeight >> woodLength;
//compute the charge
switch (woodType)
{
case 'P':
eachCost = (0.89 * noOfpc * convToFeet(woodWidth, woodHeight, woodLength));
cout << noOfpc << " " << woodWidth << "x" << woodHeight << "x" << woodLength
<< " " << "Pine," << " cost: " << "$" << eachCost << " ";
break;
case 'F':
eachCost = (1.09 * noOfpc * convToFeet(woodWidth, woodHeight, woodLength));
cout << noOfpc << " " << woodWidth << "x" << woodHeight << "x" << woodLength
<< " " << "Fir," << " cost: " << "$" << eachCost << " ";
break;
case 'C':
eachCost = (2.26 * noOfpc * convToFeet(woodWidth, woodHeight, woodLength));
cout << noOfpc << " " << woodWidth << "x" << woodHeight << "x" << woodLength
<< " " << "Cedar," << " cost: " << "$" << eachCost << " ";
break;
case 'M':
eachCost = (4.50 * noOfpc * convToFeet(woodWidth, woodHeight, woodLength));
cout << noOfpc << " " << woodWidth << "x" << woodHeight << "x" << woodLength
<< " " << "Maple," << " cost: " << "$" << eachCost << " ";
break;
case 'O':
eachCost = (3.10 * noOfpc * convToFeet(woodWidth, woodHeight, woodLength));
cout << noOfpc << " " << woodWidth << "x" << woodHeight << "x" << woodLength
<< " " << "Oak," << " cost: " << "$" << eachCost << " ";
break;
}
//add the running total
totalCharge += eachCost;
}
//exit getting the character 'T'
else
{
//print required values
cout << "Total cost: $" << totalCharge << " ";
break;
}
} while (woodType != 'T');
///main returns 0 after successful completion of the program.
return 0;
}
//describe 'convToFeet'
float convToFeet(float width, float height, float length)
{
float ft = ((width*height*length) / 12.0);
return ft;
}
The code incorporated with the template given above is as follows:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images