Question

A closer look at functions - C++

C option: (The best grade is a 79%) Write a program to calculate the cost and time it takes to fill a swimming pool . Inputs: Length, Width, and Depth of the pool (This is a gross simplification, since pools are not really rectangular cubes.) Fill rate of the pool in Gallons per minute Calculation functions Write a function to calculate the total cubic feet (Length x Width x Depth) and return the cubic feet. Inputs: Write a function to calculate the number of gallons 1 cubic foot- 7.48051948 US gallons (Create a constant to hold the conversion factor.) Input: Cubic Feet Write a function to calculate the cost to fill the pool as follows o Length, Width, and Depth Return cubic feet o Return Gallons o Calculate 1000s of gallons by dividing the total gallons by 1000 and putting the result in an integer variable Use the following table to generate the cost Monthly Usage)Monthly Rate) Input: Gallons Return Cost to 3,000 gallons $15.50 2.90 per thousand .Call your functions from main0 Outputs bove the 3000 If there is an xcess above 3,000 gallons plus $15.50 (ie 15.50 +2.90 * # . allons o Total cubic feet o Total gallons o Cost o Time to fill in minutes f thousand gallons r 3 thousand A option: (The best grade is a 100%) Note: No B option on this one Combine the functions to calculate the cubic feet and number of gallon. . o Inputs to the function: Length, Width, Depth o Outputs (via reference variables): Cubic Feet, Gallons Example Prototype void PoolSize(float Length, float Width, float Depth, float &CubicFeet, float &Gallons); » Write a function that calculate the time to fill as follows o Inputs to the function: Gallons o Outputs (via reference variables): Hours and Minutes Example Prototype void FillTime(float Gallons, float FillRate, ,float &Hours, float &Minutes); Turn in Program listing of your source code, ZIP and screen prints of the following run: Length 25 Width 12 Depth 8 Fill Rate 10 gallons a minute

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

// Declaring gloabal constant
const double FOOT = 7.48051948;

// Function declarations
float CalCubicfeet(float length,float width,float depth);
float calgallons(float cubicFeet);
float costToFillPool(float noOfGallons);
int main()
{
// Declaring variables
float length, width, depth,FillRate;
int fillTime;
// Getting the input entered by the user
cout<<"Enter length:";
cin>>length;

cout<<"Enter width:";
cin>>width;

cout<<"Enter depth:";
cin>>depth;

cout<<"Enter Fill Rate :";
cin>>FillRate;

// calling the functions
float cubicFeet = CalCubicfeet(length, width, depth);
float totalGallons = calgallons(cubicFeet);
float cost = costToFillPool(totalGallons);

fillTime=totalGallons/10;
// Displaying the output
cout<<"Total Cubic Feet :"<< cubicFeet<<endl;
cout<<"Total Gallons :"<<totalGallons<<endl;
cout<<"Cost :%.2f $"<<cost<<endl;
cout<<"Fill Time "<<fillTime<<" minutes"<<endl;


return 0;
}

// This function calculate the cubic feet
float CalCubicfeet(float length,float width,float depth)
{
return length * width * depth;
}

// This function calculate the total gallons
float calgallons(float cubicFeet)
{
return cubicFeet * FOOT;
}

// This function calculate the cost to fill the pool
float costToFillPool(float noOfGallons)
{
int n = noOfGallons / 1000;
if (n >= 0 && n <= 3)
{
return 15.50;
}
else if (n > 3)
{
return 15.50 + (n - 3) * 2.90;
}
}

_________________

Output:

C:Program Files -6o)1Dey- pp MinGW6abetalonsFilfimeinMinutes ee Enter length:25 Enter width:12 nter depth:8 Enter Fill Rate 1

________________

#include <iostream>

using namespace std;

// Declaring gloabal constant

const double FOOT = 7.48051948;

// Function declarations

void PoolSize(float length, float width, float depth,float &cubicfeet,float &gallons);

void FillTime(float gallons,float FillRate,float &Hours,float &Minutes);

int main()

{

// Declaring variables

float length, width, depth;

float cubicfeet,gallons,hours,minutes;

int FillRate;

// Getting the input entered by the user

cout<<"Enter length:";

cin>>length;

cout<<"Enter width:";

cin>>width;

cout<<"Enter depth:";

cin>>depth;

cout<<"Enter Fill Rate :";

cin>>FillRate;

  

// calling the functions

PoolSize(length, width, depth,cubicfeet,gallons);

FillTime(gallons,FillRate,hours,minutes);

// Displaying the output

cout<<"Total Gallons :"<< gallons<<endl;

cout<<"Fill Time :"<<hours<<" hours and "<<minutes<<" minutes"<<endl;

return 0;

}

// This function calculate the cubic feet

void PoolSize(float length, float width, float depth,float &cubicfeet,float &gallons)

{

cubicfeet=length * width * depth;

gallons=cubicfeet * FOOT;

}

//This function will calculate the tank fill time

void FillTime(float gallons,float FillRate,float &Hours,float &Minutes)

{

int Mins=gallons/FillRate;

Hours=Mins/60;

Minutes=Mins-(Hours*60);

}

________________

Output:

CAProgram Files (x86) Dev-Cpp\MinGW64 bin\TankFillTimeInC+ + Language.exe nter length:25 nter width:12 nter depth:8 nter Fill

_____________Could you rate me well.Plz .Thank You

Add a comment
Know the answer?
Add Answer to:
A closer look at functions - C++ C option: (The best grade is a 79%) Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your...

    Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to store the length (in feet), width (in feet), depth (in feet), the rate (in gallons per minute) at which the water is filling the pool. Add appropriate constructors to initialize the instance variables. Also add member functions, to do the following: Determine the amount of water needed to fill an empty pool; the time needed to completely...

  • 2. Write a program with three functions that will be called from the main function The functions will calculate the...

    2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...

  • C Language <stdio.h> (FUNCTIONS) A concrete company wants to estimate what it will cost a customer...

    C Language <stdio.h> (FUNCTIONS) A concrete company wants to estimate what it will cost a customer to have a driveway poured. They can pour a 3 inch deep 200 sq. ft. driveway in 3 hours, and they charge $50.00 per hour as their labor rate. Write a program to ask the user for the length of the driveway (in feet), and the width of the driveway (in feet) to be poured. For both the length and width, make sure the...

  • program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks,...

    program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks, and combining their use to solve a larger problem. Also to practice documenting functions. Degree of Difficulty: Moderate Your task is to compute the cost of renovating the flooring in a rectangular room. This includes replacing the carpet and and the baseboards. Your task is to write a Python program that calculates and the cost of the renovation. To accomplish this, you will need...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • This is in c programming using functions in visual studios Carpet Jolb A carpeting company wants...

    This is in c programming using functions in visual studios Carpet Jolb A carpeting company wants to estimate what it will cost a customer to have a room carpeted. They can carpet 65 sq. ft. of room space in 4 hours, and they charge $25.00 per hour as their labor rate Write a program to ask the user for the length of the room (in inches) to be carpeted, the width of the room (in inches) to be carpeted, and...

  • PLEASE HELP, MATLAB, answers are very appreciated need to study pl 2. Write two m-file functions...

    PLEASE HELP, MATLAB, answers are very appreciated need to study pl 2. Write two m-file functions that will allow you to compare mortgages cakculations for the monthly payment and compare mortgage with different loan values. The monthly payment M, is calculated using 1-2)1 Where Pis the principal loan amount, r is the interest rate (in decimal form not percent form), and y is the number of years of the loan. Create an m-file function called "mortgage_a.m" that will serve as...

  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT