Question

In: Computer Science

Cpp challenge Description The purpose of this challenge is to use various flow control structures. This...

Cpp challenge

Description

The purpose of this challenge is to use various flow control structures. This challenge uses techniques for displaying formatted output, simulating a payment structure for paying off outstanding debt such as a credit card or any kind of interest-bearing loan.

Requirements

  1. Declare double variables called balance, monthly, apr, apr_monthly, start_bal, interest, end_bal
  2. Declare an integer called months
  3. Prompt the user to enter values for balance, monthly, and apr
  4. Use a while loop to display the payment breakdown and how long it will take to pay off the balance. We use a while loop since we don’t know how many months it will take based on the input values. This loop will continue to run as long as there is a balance remaining
  5. Use these formulas to calculate the payment breakdown
    • apr_monthly = (apr / 12) / 100
    • interest = start_bal * apr_monthly
    • end_bal = start_bal + interest – monthly
    • end_bal becomes start_bal the following payment cycle
  6. Include <iomanip> and call cout << fixed << setprecision(2) to format your output
  7. Use the setw(x) call in your cout stream to format your output. x is an integer indicating the width of the displayed column. For example, setw(5) will set a column width of 5. See below on how to display the table data
    cout << setw(5) << months << setw(10) << start_bal ...
    (of course, you can't actually use ellipses in the code. That's just an indicator that you can continue with whatever data and formatting you need)
    
  8. Note that some combination of input values may create an infinite loop, meaning the balance never gets paid off. It can, in fact, increase if the monthly payment cannot cover the interest payment (try balance = 2000, monthly = 25, apr = 24 during your test runs)

Do Not Use

You may not use the break statement to terminate any loops

Sample Interaction / Output

What is the outstanding balance? 2000
What is the APR? 24
How much do you pay every month? 125

The table shows how long it will take to pay:

Month     Start Interest        Monthly     End
    1   2000.00    40.00         125.00 1915.00
    2   1915.00    38.30         125.00 1828.30
    3   1828.30    36.57         125.00 1739.87
    4   1739.87    34.80         125.00 1649.66
    5   1649.66    32.99         125.00 1557.66
    6   1557.66    31.15         125.00 1463.81
    7   1463.81    29.28         125.00 1368.09 
    8   1368.09    27.36         125.00 1270.45
    9   1270.45    25.41         125.00 1170.86
   10   1170.86    23.42         125.00 1069.27
   11   1069.27    21.39         125.00  965.66
   12    965.66    19.31         125.00  859.97
   13    859.97    17.20         125.00  752.17
   14    752.17    15.04         125.00  642.22
   15    642.22    12.84         125.00  530.06
   16    530.06    10.60         125.00  415.66
   17    415.66     8.31         125.00  298.97
   18    298.97     5.98         125.00  179.95
   19    179.95     3.60         125.00   58.55
   20     58.55     1.17         125.00  -65.28

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

    double balance, monthly, apr, apr_monthly, start_bal, interest, end_bal;

    int months;

    cout<<"What is the outstanding balance? ";

    cin>>balance;

    cout<<"What is the APR? ";

    cin>>apr;

    cout<<"How much do you pay every month? ";

    cin>>monthly;

    start_bal = balance;

    months = 1;

    cout<<"\nThe table shows how long it will take to pay:\n"<<endl;

    cout<<setprecision(2)<<fixed;

    cout<<setw(5)<<"Month"<<setw(10)<<"Start"<<setw(10)<<"Interest"<<setw(10)<<"Monthly"<<setw(10)<<"End"<<endl;

    while(start_bal>0){

        apr_monthly = (apr/12.0)/100;

        interest = start_bal * apr_monthly;

        end_bal = start_bal + interest - monthly;

        cout<<setw(5)<<months<<setw(10)<<start_bal<<setw(10) <<interest<<setw(10)<<monthly<<setw(10)<<end_bal<<endl;

        start_bal = end_bal;

        months++;

    }

    return 0;

}


Related Solutions

Cpp challenge Description The purpose of this challenge is to use the WHILE loop to control...
Cpp challenge Description The purpose of this challenge is to use the WHILE loop to control program flow. This challenge will use the WHILE loop in various ways. Requirements Write all your code for the following steps in one file. Ask the user to enter a single string. Ask the user to enter an integer value for a variable called repetitions. Use a while loop to display this string (of your choice) repeated repetitions times, one string per line Use...
Description The purpose of this challenge is to use the IF statement to control program flow...
Description The purpose of this challenge is to use the IF statement to control program flow and to use basic arithmetic expressions. This challenge simulates a rudimentary stock chart. Requirements Take a glance at the Sample Interaction below to get an idea of how the code runs Declare a double variable called previous_price Declare a double variable called current_price Declare a string variable called symbol Declare a string variable called company Ask the user to enter a value for symbol...
Description( IN C++)!! The purpose of this challenge is to implement a stack using a Linked...
Description( IN C++)!! The purpose of this challenge is to implement a stack using a Linked List as a backing data structure Requirements Write the following structs struct Location { string name; string address; }; struct VisitNode { Location loc; VisitNode * next; }; Create a class called Stack. In this class, create a private variable VisitNode * head. This will keep track of the location of the head node. Add the following private function. This function will be used...
Description( IN C++) NO TAIL POINTERS!! The purpose of this challenge is to implement a queue...
Description( IN C++) NO TAIL POINTERS!! The purpose of this challenge is to implement a queue using a linked list as a backing data structure Requirements Write the following struct struct JobNode { string name; JobNode * next; }; Create a class called Queue. In this class, create a private variable JobNode * head. This will keep track of the location of the head node. Add the following private function. This function will be used to dynamically create new nodes...
Description The purpose of this challenge is to implement a circular doubly-linked list using a dummy...
Description The purpose of this challenge is to implement a circular doubly-linked list using a dummy node. This challenge simulates an operating system’s window manager. Requirements Write the following struct struct Window { string appname; Window *next; Window *prev; }; Create a class called WindowManager. In this class, create a private variable Window * head. This will keep track of the location of the head node. Create private variables Window * current, * dummy. current will keep track of the...
The purpose of this assignment is to create a design challenge that highlights various problem-solving techniques....
The purpose of this assignment is to create a design challenge that highlights various problem-solving techniques. Write a paper of approximately 250-500 words utilizing a business writing format to present and frame the design challenge. Reference the example provided in The Field Guide to Human-Centered Design for additional information. Address the following: What problem are you trying to solve? Who will be affected by the problem? To what degree will the group identified be affected? Consider that new technologies are...
java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a...
java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a boolean method that uses recursion to determine whether a string argument is a palindrome. the method should return true if the argument reads the same forward amd backword. Demonstrate the method in a program, use comments in the code for better understanding. there must be a demo class and method class also .. generate javadocs through eclipse compiler. And make a UML diagram with...
Outline the reasons why the various elements of culture (social structures and control systems, language and...
Outline the reasons why the various elements of culture (social structures and control systems, language and aesthetics, religion and other belief systems, educational systems, etc.) might increase the cost of doing business in a country. Be sure you illustrate your ideas with concrete examples of both cultural elements and specific countries. The reader of your essay should gain an understanding of behavioral factors influencing countries’ business practices. write down minimum 350 words with footnote.
Pick the best control plan for the scenario or description provided. You may use a control...
Pick the best control plan for the scenario or description provided. You may use a control plan once, more than once, or not at all. A customer service representative was terminated, to "get even" during the notice period he created several fake sales orders with delivery addresses for his family members. May include financial background check performed on potential candidates for positions that perform cash deposits and execute bank wire transactions and other privileged activities. A snow storms knocks out...
Data Structures Use good style. Make sure that you properly separate code into .h/.cpp files. Make...
Data Structures Use good style. Make sure that you properly separate code into .h/.cpp files. Make sure that you add preprocessor guards to the .h files to allow multiple #includes. Overview You will be writing the classes Grade and GradeCollection. You will be writing testing code for the Grade and GradeCollection classes. Part 1 – Create a Grade Class Write a class named Grade to store grade information. Grade Class Specifications Include member variables for name (string), score (double). Write...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT