Question

This C++ Program should be written in visual studio 2017 You are to write a program...

This C++ Program should be written in visual studio 2017

You are to write a program that can do two things: it will help users see how long it will take to achieve a certain investment goal given an annual investment amount and an annual rate of return; also, it will help them see how long it will take to pay off a loan given a principal amount, an annual payment amount and an annual interest rate. When the user runs the program, they will be asked to choose what to do. At the end, the user should be given the chance to repeat the program.

Investing – for the future!

For this set of calculations, the user will enter an amount indicating how much is to be invested annually, an annual rate of return and the goal amount for the investment. For example, the user might be able to invest $1000 each year into an account returning 15% annually. The user might then ask how long it would take to have $10000 total in the investment. At the start of the first year, the account balance would be $1000. At the end of the year, the balance would be $1150 (the balance plus the year’s interest). At the beginning of year two, the account would hold $2150 (the balance plus the new investment). As the years go by, the balance increases, and eventually the balance will equal (or exceed) the requested investment total.

The program should prompt the user for the necessary information, and then generate a table with each row showing the year, the balance at the beginning of the year and the balance at the end of the year. At the end of the table, your program should print out a summary indicating how many years were needed to achieve the goal, how much money was invested, how much the total interest was, and by how much the investment total exceeded the goal. When done, the program should prompt the user to do another calculation. Here’s an example of how the program might look when executed (user input highlighted):

Welcome to the Moodle Credit Union!

Do you want to invest (i) with us or borrow (b) from us? i

Enter the amount to invest annually: 1000

Enter the yearly percentage rate of return: 15

Enter the investment goal: 10000

Year    Balance (Jan 1)     Balance (Dec 31)

1           1000.00            1150.00

2           2150.00            2472.50

3           3472.50            3993.38

4           4993.38            5742.38

5           6742.38            7753.74

6           8753.74            10066.80

Number of years needed to achieve investment goal: 6

Total investment:                                     6000.00

Total accumulated return on investment:              4066.80

Final balance exceeds goal by:                       66.80

Do another investment/loan calculation? n

Borrowing for the present… or maybe just a present?

For this set of calculations, the user will enter the amount of a loan, the annual interest rate payable on the loan and the annual payment to be made against the loan balance. For example, the user may want to analyze the cost of borrowing $5000 at a 10% interest rate, with annual payments of $1000. Each year, interest is charged on the balance at the beginning of the year and the amount is added to the balance. At year’s end, the payment is made and the balance is reduced by that amount.

The program should prompt the user for the necessary information, and then display a table with each row showing the year, the balance at the beginning of the year and the balance at the end of the year. At the end of the table, your program should print out a summary indicating how many years were needed to pay off the loan, the total amount paid on the loan, how much interest was charged over the lifetime of the loan and by how much the final payment exceeded the balance of the loan. Here’s an example of how the program might look when run with this data (user input highlighted):

Welcome to the Moodle Credit Union!

Do you want to invest (i) with us or borrow (b) from us? b

Enter the amount of the loan: 5000.00

Enter the annual interest rate: 10.0

Enter the annual payment amount: 1000

Year               Balance            Balance

                   (Jan. 1)           (Dec. 31)

1                  5000.00            4500.00

2                  4500.00            3950.00

3                  3950.00            3345.00

4                  3345.00            2679.50

5                  2679.50            1947.45

6                  1947.45            1142.20

7                  1142.20            256.42

8                  256.42            -717.94

Number of years needed to pay back loan:      8

Total of payments:                             8000.00

Total of interest charged:                     2282.06

Balance at end of period:                      -717.94

Do another investment/loan calculation? n

OUTPUT FORMATTING

The program should use C++ features like setw and setprecision to format the output neatly. All money values should be written with two decimal places.

USE OF FUNCTIONS FOR THE ASSIGNMENT

You are to use the following functions (you may add more if you wish, but these are the minimum requirements):

• a void function, intro(), to introduce the program

• a string-valued function, getChoice(), to retrieve the validated user’s choice of calculation (invest or borrow)

• a void function, doInvest(), to perform the investment option, and another void function, doBorrow(), to perform the borrowing option

• a void function, showInvestSummary(), to display the summary for the investment option, and another void function, showBorrowSummary(), to do the same for the borrowing option; each will need four parameters to receive the data from the main program that is to be shown in the summaries

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

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================


#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <ctime>


using namespace std;


void intro();
string getChoice();
void doInvest(double &annualInvestment,double &rate,double &goalAmt);
void showInvestSummary(double annualInvestment,double rate,double goalAmt);
void doBorrow(double &loan,double &rate,double &payment);
void showBorrowSummary(double loan,double rate,double payment);
int main() {
   //Declaring variables
string choice;
char ch;
double annualInvestment,rate,goalAmt,balance;
double loan,payment;
int count=0;
  
intro();
  
while(true)
{
cout<<"\nDo you want to invest (i) with us or borrow (b) from us? ";
choice=getChoice();
if(choice.compare("i")==0)
{
   doInvest(annualInvestment,rate,goalAmt);
   showInvestSummary(annualInvestment,rate,goalAmt);
   }
   else if(choice.compare("b")==0)
{
doBorrow(loan,rate,payment);
showBorrowSummary(loan,rate,payment);
   }
   cout<<"\nDo another investment/loan calculation ?";
cin>>ch;

if(ch=='y'||ch=='Y')
{

   continue;

}else
{
break;
}
   }
  
  
   return 0;
}
string getChoice()
{
   string choice;
   while(true)
   {
   cin>>choice;
   if(choice.compare("i")==0)
{
   return choice;
   }
   else if(choice.compare("b")==0)
   {
       return choice;
   }      
   else
   {
       cout<<"Invalid.Must be either 'i' or 'b'.Re-enter :";
   }
   }
}
void intro()
{
   cout<<"Welcome to the Moodle Credit Union!"<<endl;  
}
void doInvest(double &annualInvestment,double &rate,double &goalAmt)
{
   cout<<"Enter the amount to invest annually :";
   cin>>annualInvestment;
   cout<<"Enter the yearly percentage rate of return :";
   cin>>rate;
   cout<<"Enter the investment goal : ";
   cin>>goalAmt;
}
void showInvestSummary(double annualInvestment,double rate,double goalAmt)
{
   //setting the precision to two decimal places
   std::cout << std::setprecision(2) << std::fixed;

   int year=0;
   double balance=0.0,newbal=0.0,totReturn=0.0;
   cout<<setw(20)<<left<<"Year"<<setw(20)<<right<<"Balance (Jan 1)"<<setw(20)<<right<<"Balance (Dec 31)"<<endl;  
  
   while(balance<=goalAmt)
   {
       balance+=annualInvestment;
       totReturn+=balance*(rate/100);
       newbal=balance+balance*(rate/100);
       cout<<setw(20)<<left<<(year+1)<<setw(20)<<right<<balance<<setw(20)<<right<<newbal<<endl;
       year++;
       balance=newbal;
   }
   cout<<setw(50)<<left<<"Number of years needed to achieve investment goals:"<<setw(8)<<left<<year<<endl;
   cout<<setw(50)<<left<<"Total investment :"<<setw(8)<<left<<year*annualInvestment<<endl;
   cout<<setw(50)<<left<<"Total accumulated return on investment :"<<setw(8)<<left<<totReturn<<endl;
   cout<<setw(50)<<left<<"Final balance exceeds goal by :"<<setw(8)<<left<<balance-goalAmt<<endl;
  
}
void doBorrow(double &loan,double &rate,double &payment)
{
   cout<<"Enter the amount of loan :";
   cin>>loan;
   cout<<"Enter the amount interest rate :";
   cin>>rate;
   cout<<"Enter the annual payment amount :";
   cin>>payment;
}
void showBorrowSummary(double loan,double rate,double payment)
{
       //setting the precision to two decimal places
   std::cout << std::setprecision(2) << std::fixed;
   int year=0;
   double newLoan=0.0,totInterest=0;
   cout<<setw(20)<<left<<"Year"<<setw(20)<<right<<"Balance (Jan 1)"<<setw(20)<<right<<"Balance (Dec 31)"<<endl;  
   while(loan>0)
   {
       totInterest+=(loan*(rate/100));
       newLoan=loan+(loan*(rate/100))-1000;
       cout<<setw(20)<<left<<(year+1)<<setw(20)<<right<<loan<<setw(20)<<right<<newLoan<<endl;
       year++;

       loan=newLoan;
   }
  
   cout<<setw(50)<<left<<"Number of years needed to pay back loan :"<<setw(8)<<left<<year<<endl;
   cout<<setw(50)<<left<<"Total of payments :"<<setw(8)<<left<<year*payment<<endl;
   cout<<setw(50)<<left<<"Total of interest charged :"<<setw(8)<<left<<totInterest<<endl;
   cout<<setw(50)<<left<<"Balance at end of period :"<<setw(8)<<left<<loan<<endl;
}

========================================

Output:

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\InvestmentOrBorrow.exe Welcome to the Moodle Credit Union! 2 Do you want to invest


=====================Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
This C++ Program should be written in visual studio 2017 You are to write a program...
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
  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • Your program will ask the user to enter the amount of money they want to borrow,...

    Your program will ask the user to enter the amount of money they want to borrow, the interest rate, and the monthly payment amount. Your program will then determine how many months it will take to pay off that loan, what the final payment amount will be, and how much interest was paid over that time. If the monthly payment amount isn't high enough to pay off more than one month's interest, your program should notify the user what the...

  • Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variable...

    Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variables - firstN - lastN - idNum -wage: holds how much the person makes per hour -weekHrsWkd: holds how many total hours the person worked each week. - regHrsAmt: initialize to a fixed amount of 40 using constructor. - regPay - otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: -...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • Please I wish you use Python 3.7 for this problems. Q1. Write a program that receives...

    Please I wish you use Python 3.7 for this problems. Q1. Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing inputs. After the user presses the enter key, the program should print the sum of the numbers and their average. Q2. The credit plan at TidBit Computer Store specifies a 10% down payment and an annual interest rate of...

  • Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....

    Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate. ·         The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user. ·         The application prompts the user to continue. ·         The program stops prompting the user for values after taking 3 loan amounts. ·         The application calculates and displays the total loan and interest amount and ends the program Example Output Welcome to...

  • Write a program that prints the accumulated value of an initial investment invested at a specified...

    Write a program that prints the accumulated value of an initial investment invested at a specified annual interest and compounded annually for a specified number of years. Annual compounding means that the entire annual interest is added at the end of a year to the invested amount. The new accumulated amount then earns interest, and so forth. If the accumulated amount at the start of a year is acc_amount, then at the end of one year the accumulated amount is:...

  • In C. Thank you! Bank Write a program to calculate the monthly payment on a loan...

    In C. Thank you! Bank Write a program to calculate the monthly payment on a loan given the loan amount, interest rate and the number of years to pay off the loan. Then add a function to print an amortization schedule for that loan. Create a class to save the current balance and the rest of the data as private data. Add member functions to make a payment and to print the amortization report. Use the following class header. Class...

  • C++ Program - Loan Payment Report Please write a C++ program to generate a detail loan payment report from the first month until the loan balance becomes zero or less than ten cents. You may use a whi...

    C++ Program - Loan Payment Report Please write a C++ program to generate a detail loan payment report from the first month until the loan balance becomes zero or less than ten cents. You may use a while loop such as: while (loanBalance >= monthPayment) { … }. When the loanBalance is less than the monthPayment, you need to compute the final payment amount, which should be the loanBalance plus its interest of one month. For example, if your last-month’s...

  • Write a program that calculates the amount of money that you must invest In a savings...

    Write a program that calculates the amount of money that you must invest In a savings account at a given interest rate for a given number of years to have a certain dollar amount at me end of the period Y our program will ask the user for the amount the user wants to have at the end of the term (future value). the number of years the user plans to let the money stay in the account, and the...

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