Question

In: Computer Science

PROBLEM: c++ code You are to write a program to tell you how many months it...

PROBLEM: c++ code

You are to write a program to tell you how many months it will take to pay off a loan, as well as the total amount of interest paid over the life of the loan.

You have just purchased a stereo system that costs $1000 on the following credit plan: No down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest and whatever is left is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of $1000 in interest. That is $15 in interest. So, the remaining $35 is deducted from your debt which leaves you with a debt of $965.00. The next month you pay interest of 1.5% of $965.00, which is $14.48. Hence, you can deduct $35.52 (which is $50 - $14.48) from the amount you owe.

Write a program that will tell you how many months it will take you to pay off the loan, as well as the total amount of interest paid over the life of the loan. Use a loop to calculate the amount of interest and the size of the debt after each month. Put out the monthly amount of interest paid and remaining debt. Use a variable to count the number of loop iterations and hence the number of months until the debt is zero. You may want to use other variables as well.

You are to hand in:

  • a Title page
  • a Hierarchy Chart
  • a fully commented Program Listing
  • 3 sample runs (one run uses the above example, one run with your data, one run with invalid loan, interest rate and amount paid)
  • a User’s Guide (showing Purpose, Sample Input, Sample Output, Assumptions/Limitations)

A sample session may run as follows:

Enter the amount of the loan                           1000.00

Enter the yearly interest rate                           18.0

Enter the monthly amount paid                      50.00

Month                  Principle              Interest                 Principle              Remaining

Paid                      Paid                      Balance

              

1                            1000.00                15.00                    35.00                    965.00

2                            965.00                 14.48                    35.52                    929.48

3                            929.48                 13.94                    36.06                    893.42

.

.

24                             47.12                   0.71                    49.29                    -2.17

Number of months to pay of the loan:           24

Total interest paid on loan:                             197.83

You have a credit of:                                       -2.17

Solutions

Expert Solution

// main.cpp

#include <iostream>

#include <iomanip> // library for setw() to set width at terminal window

#include"FloatingFilter.h" // library for our own input function defined below

using namespace std;

int main(int argc, const char * argv[]) {

float principle ,yearlyRate ,monthlyPaid , interstPaid;

float sumOfInterstPaid = 0.000;

int months = 1;

float interestPerMonth, balanceLeft;

cout<<setw(60)<<"LOAN Summary\n";

cout<<" enter amount of loan :"<<principle;

principle = inputFloat(); // our own input function that filters the input for floating point

cout<<endl;

cout<<" enter yearly interest rate in %age :"<<yearlyRate;

yearlyRate = inputFloat();

cout<<endl;

cout<<"enter monthly paid :"<<monthlyPaid;

monthlyPaid = inputFloat();

cout<<endl;

cout<<setw(10)<<"Month"<<setw(30)<<"Principle paid"<<setw(30)<<"Interest Paid"

<<setw(30)<<"Principle Balance"<<setw(20)<<"Remaining\n";

while(principle >= 0)

{

interestPerMonth = yearlyRate/12; // calculate interest rate per month

interstPaid = (interestPerMonth/100) * principle; // amount of interst you pay each month

balanceLeft = monthlyPaid - interstPaid; // remaining principle balance which will be deducted from debt.

  

cout<<setw(10)<<months<<setw(30)<<principle<<setw(30)<<interstPaid<<setw(30)<<balanceLeft<<endl;

  

principle = principle - balanceLeft; //this is the principle paid each month after deduction

cout<<setw(120)<<principle<<endl;

months++; // increment month by 1 during each iteration

  

sumOfInterstPaid += interstPaid; //a total of amount of interest paid by you in total months

  

}

cout<<"Number of months to pay of the loan :"<<months - 1<<endl;

cout<<"total interst paid on loan :"<<sumOfInterstPaid<<endl;

  

cout<<"you have a credit of :"<<principle<<endl;

}

// FloatingFilter.h

// this file is used for filtering floating point data in our main file

#ifndef FloatingFilter_h

#define FloatingFilter_h

float inputFloat()

{

float number;

int counter1 = 1;

float temp =0, counter2 = 1.0;

char ch;

Repeat: while(1)

{

ch = fgetc(stdin);

if(ch == '\n')

{

if(counter1 == 1)

{

printf("Input field empty.....Enter again:");

continue;

}

else break;

}

if(ch <= '9' && ch >= '0')

{

temp = temp * 10 + (ch & 15);

counter1++;

}

else

{

if(ch == '.')

{

while(1)

{

ch = fgetc(stdin);

if(ch == '\n')

{

goto End;

}

if(ch <= '9' && ch >= '0')

{

temp = temp * 10 + (ch & 15);

counter2 = counter2 * 10;

}

else

{

printf("INvalid entry..");

while(fgetc(stdin) != '\n');

temp = 0;

counter1 = 1;

counter2 = 1.0;

printf("enter again");

goto Repeat;

}

}

}

else

{

printf("INvalid entry..");

while(fgetc(stdin) != '\n');

temp = 0;

counter1 = 1;

counter2 = 1.0;

printf("enter again");

goto Repeat;

}

}

}

  

End: number = temp / counter2;

return number;

}

#endif /* FloatingFilter_h */

Add these 2 files in same folder then compiler will automatically link them and run as a one file.


Related Solutions

1. Write the C++ code for a program that calculates how many days are left until...
1. Write the C++ code for a program that calculates how many days are left until Halloween, when given as an input how many weeks are left until Halloween. Use variables named weeks and days. ------------ 2. What header file must be included - To perform mathematical functions like sqrt? - To use cin and cout? - To use stream manipulators like setprecision? -------------------- 3. What value will be stored in the variable t after each of the following statements...
Write a program in Python to determine how many months it will take to pay off...
Write a program in Python to determine how many months it will take to pay off a $10,000 car loan with 4% interest. Choose your own monthly payment.
Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
C++ code Write a program to illustrate how to use the temporary class. Your program must...
C++ code Write a program to illustrate how to use the temporary class. Your program must contain statements that would ask the user to enter data of an object and use the setters to initialize the object. Use three header files named main.cpp, temporary.h, and temporaryImp.cpp An example of the program is shown below: Enter object name (rectangle, circle, sphere, or cylinder: circle Enter object's dimensions: rectangle (length and width) circle (radius and 0) sphere (radius and 0) rectangle (base...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking integers until the user enters -100. In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered. Sample Input/Output 1: Input the number: 0 2 3 -9 -6 -4 -100 Number of positive numbers: 2 Number of Negative numbers: 3 Number of Zero: 1
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
C++ Code You will write a program to process the lines in a text file using...
C++ Code You will write a program to process the lines in a text file using a linked list and shared pointers. You will create a class “Node” with the following private data attributes: • Line – line from a file (string) • Next (shared pointer to a Node) Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement:...
Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement: The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output a string that is the concatenation of string str1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT