# I have to rewrite a program I have already completed using functions. First I will copy and paste my

### FIRST GRADER essay writing company is the ideal place for homework help. If you are looking for affordable, custom-written, high-quality and non-plagiarized papers, your student life just became easier with us. Click the button below to place your order.

Order a Similar Paper Order a Different Paper

I have to rewrite a program I have already completed using functions. First I will copy and paste my previous program, then I will copy and paste the directionsfor my assignment that is due tomorrow. Thank you for your help!

PREVIOUS ASSIGNMENT I WROTE:

#include

#include

using namespace std;

int main()

{

float userInput = 0;

float exactSum = 0;

float roundedSum = 0;

float squaredExactSum = 0;

float squaredRoundedSum = 0;

int numEntries = 0;

cout

cin >> userInput;

while(userInput != 0){

if(userInput > 0){

numEntries++;

exactSum += userInput;

roundedSum += 10*(int)((userInput+5)/10);

squaredExactSum += (float) pow(userInput,2);

squaredRoundedSum += (float) pow((float)((10*(int)((userInput+5)/10))),2);

cout

cin >> userInput;

}

else{

cout

cin >> userInput;

}

}

float stdDevExact = sqrt((squaredExactSum – pow(exactSum,2)/numEntries)/(numEntries-1));

float stdDevRounded = sqrt((squaredRoundedSum – pow(roundedSum,2)/numEntries)/(numEntries-1));

cout

cout

cout

cout

cout

if(exactSum == 0){

cout

cout

cout

}

else{

cout

cout

cout

cout

cout

}

system(“PAUSE”);

return 0;

}

DIRECTIONS FOR NEXT ASSIGNMENT I NEED HELP WITH:

Overview

For this assignment, re-write program 4 so that it uses functions.

As before, the program should accept dollar amounts from the user until 0 is entered. Each exact dollar amount should be rounded to the nearest $10 value. Theexact and rounded amounts should then be used to keep track of:

the sum of the exact dollar amounts

the sum of the rounded dollar amounts

the sum of the squares of the exact dollar amounts

the sum of the squares of the rounded dollar amounts

the number of dollar amounts entered

After the user has entered an exact amount of 0, display the sum, average, and standard deviation for both the exact and rounded amounts. Calculate the percentdifference between the sums of the exact and rounded amounts and make a determination as to whether or not it's cost effective to round the dollar values.

When testing your program, keep in mind that $10 is a greater percent of a small value, than of a large value. If you test with only very small numbers (like$1.35, $2.99), common sense should tell you that the results will be radically different.

Functions that you must write:

double getAmount()

The getAmount funtion takes no arguments and returns a “valid” amount. Its purpose is to “get” an exact dollar amount from the user and verify that it is either 0or positive. If the value entered is valid, it should be returned to the calling function. If the value entered is invalid, display an error message and prompt theuser for a new value. This should be done until a valid value is entered.

double roundAmount( double exactAmt )

The roundAmount function takes one double argument: a dollar amount to be rounded to the nearest $10 value. To round an amount to the nearest $10 value:

add 5 to the exact amount

divide by 10

multiply the integer result by 10.

double calcAverage( double sum, int count )

The calcAverage function takes two arguments: a double value that represents a sum of dollar amounts, and an integer value that represents a count of dollaramounts. Its purpose is to calculate and return an average if the count is greater than 0. If the count is less than or equal to 0, return -1.

double calcStdDev( double sum, double sumOfSquares, int count )

The calcStdDev function takes three arguments: a double value that represents a sum of dollar amounts, a double value that represents the sum of the squared dollaramounts, and an integer value that represents a count of dollar amounts. The purpose of this function is to calculate and return the standard deviation if thecount is greater than 1. If the count is less than 1, return -1. The formula for standard deviation is:

where n is the number of entries (count).

double calcDiff( double exactSum, double roundedSum )

The calcDiff function takes two arguments: a double value that represents a sum of the exact dollar amounts, and a double value that represents the sum of therounded dollar amounts. The purpose of this function is to calculate and return the percent difference between the sum of the exact values and the sum of therounded values. To calculate percent difference:

Think about using the function fabs() to find the absolute value.

Programming Requirements:

Make and use meaningful variable names in the functions.

The functions should be added to the end of the program (ie. after the closing curly brace for main()).

At the top of your C++ source code, include a documentation box that resembles the one from previous programs. Your program must be fully documented. Linedocumentation should be used wherever needed, but need not be on every line of code. White space and indentation should be used to make your code easilyreadable.

Again, your program must be fully documented. There must be a documentation box for every function in the program. Line documentation should be used whereverneeded, but need not be on every line of code. White space and indentation should be used to make your code easily readable.

Check your program with sample numbers and verify, by hand, that they are correct. You are responsible for the correctness of your calculations.

All of the dollar amounts should be displayed with exactly 2 digits after the decimal point.

The values read in from the user should all be float or double values.

Hand in a copy of your source code using Blackboard.

Output

The output from your program should consist of the prompts to the user to enter dollar amounts, a neatly formatted table that displays the results from thecalculations, and a message indicating whether the percent difference is acceptable or unacceptable.

The basic format for the table is:

Calculation Exact Rounded

——————————————

Sum:

Average:

Std Dev:

If the average (and standard deviation) cannot be calculated, display a message that the average (and standard deviation) could not be calculated.

Run 1

Enter a positive dollar amount or 0 to quit: 12.56

Enter a positive dollar amount or 0 to quit: 94.20

Enter a positive dollar amount or 0 to quit: -9.87

Error: amount must be greater than or equal to 0. Try again: -9.87

Error: amount must be greater than or equal to 0. Try again: 9.87

Enter a positive dollar amount or 0 to quit: 56.32

Enter a positive dollar amount or 0 to quit: 61.47

Enter a positive dollar amount or 0 to quit: 0

Calculation Exact Rounded

——————————————

Sum: 234.42 230.00

Average: 46.88 46.00

Std Dev: 35.67 35.07

The difference 1.89 is acceptable

Run 2

Enter a positive dollar amount or 0 to quit: 0

Calculation Exact Rounded

——————————————

Sum: 0.00 0.00

Average: *** cannot be calculated ***

Std Dev: *** cannot be calculated ***

The difference cannot be calculated.

### Got stuck with another paper? We can help! Use our paper writing service to score better grades and meet your deadlines.

Get 15% discount for your first order

Order a Similar Paper Order a Different Paper