Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I was wondering if you could help me come up with the code for this particular assignment? I am completely lost in the class and

I was wondering if you could help me come up with the code for this particular assignment? I am completely lost in the class and I have the assignment due at midnight.

For the assignment, write a program that an investor can use to compute future bank balances. The program asks the user for two pieces of information: The amount of an initial deposit (entered as a double number in dollars, such as 42.31 for 42 dollars and 31 cents), and an interest rate (entered as a double number, such at 0.05 for 5% interest).

The program prints the results of three computations, each of which assumes that interest is paid once per year on the amount in the account at the year's start:

The balance in the account after one year of interest;

The balance in the account after ten years of compounding interest;

The number of years required for the balance to reach at least one million dollars.

The account balances should be printed with a dollar sign in front and rounded to two decimal places (such as $42.31).

In order to get numbers to print with two decimals, include both and and place these lines in your main function (just after you declare any local variables that the main function uses):

cout.precision(DIGITS);

cout.setf(ios::fixed, ios::floatfield);

Your program must include functions with these exact prototypes:

double newBalance(double initialBalance, double interestRate);

// This first version of the new balance function computes the

// final account balance that will be reached by starting with

// an initial balance and adding one year's interest at a given

// interest rate (such as 0.05 for 5%). The function works

// correctly for any non-negative arguments.

double newBalance(double initialBalance, double interestRate, int n);

// This second version of the new balance function computes the

// final account balance that will be reached by starting with

// an initial balance and adding some n number of years of interest

// at a given interest rate (such as 0.05 for 5%). The interest is added

// once per year and it is applied to the entire balance.

// For example, new_balance(100.00, 0.10, 2) is 121.00 since

// the first year received 10.00 interest (10% of 100) and the

// second year received 11.00 interest (10% of the 110, which

// was the second year's starting balance). The function works

// correctly for any non-negative arguments.

// Notice n is not an appropriate variable name, but will not be

// deducted for this program.

int yearsNeeded(double initialBalance, double interestRate, double goal);

// The years needed function computes the number of years needed for

// a given starting balance to reach a given goal at a certain rate

// of compound interest. The function works correctly for any

// positive arguments.

Important Note: Your program must include the three functions show above in this exact format. Validate all input. Do not use using namespace std;. We will actually test your program by throwing away your main program and using our own main program that calls the functions with lots of different numbers.

Hints:

In the second version of newBalance, the balance after n years should be computed with the following formula:

initialBalance * ((1 + interestRate) raised to the n power)

Use the pow(x, b) function from to compute the value of a number x raised to the b power.

The yearsNeeded function can be implemented by using logarithms. But if you are unfamiliar with logarithms, another approach is to repeatedly call newBalance with higher and higher years, until you get an answer that is at least equal to the goal. If you use this second approach, then start by calling newBalance with n=0, then n=1, then n=2, and so on. When you get a return value that is at least equal to the goal, then your answer is the current value of n.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions