Program #1

Terms in an arithmetic series are found by adding a constant value (known as the common difference) to each prior term, starting with an initial value (known as the initial term).

Example 1: Initial term = 1
                   Common difference = 3
             Series:   1, 4, 7, 10, 13, 16, …

Example 2: Initial term = 100
                   Common difference = -5
            Series:   100, 95, 90, 85, 80, 75, …

Note that the common difference is the difference between each term, and it can be positive or negative.

Given an initial term and the common difference, a specific term (i.e. the nth term) can be computed.   

You will be writing a program to compute a specific term using three different methods for computation. Each method of computation will be implemented within a function.

Given: termᵢ = the initial term, termₙ = the nth term, d = the common difference

The first function (CalcFormulaTerm) will use the formula: termₙ = termᵢ + (n - 1)d to compute and return the nth term.   

The second function (CalcLoopTerm) will compute and return the nth term, using iteration to compute the term (i.e. a loop).

The third function (CalcRecursiveTerm) will compute and return the same nth term using recursion.

All three functions should take the initial term, common difference and term number to compute as input arguments and return the nth term in the arithmetic series.

The main function should first explain to the user what the program will do.   

Then main should first read the term number to compute from the user, indicating that if the user enters 0, the program will exit. The code should error check the number entered is positive, and loop until the user enters a positive integer.

Unless the user enters 0 for the term number to compute:
• The main function should then read the initial term to start the series, and the common difference to use in the series.   

• After reading all three inputs, the CalcFormulaTerm, CalcLoopTerm and CalcRecursiveTerm functions should all be called, passing the user inputs as input parameters to each.

• The results of all three function calls should be printed out by main, with descriptive text. Note that the results should all be the same!

The program should loop and continue to compute results, until the user enters 0 for the value of the term number.   

The only way the user may exit the program is to enter 0 for the value of the term number – the program should not ask the user whether to run the program again.   

Program #2

For program 2, you will modify program 2 from assignment 5, to incorporate re-use of code. Program 2 from assignment 5 output accumulated savings for each month, until the accumulated amount reached a set goal amount.

A banking firm purchased the code from another company. The new company would like you to rewrite the original program, to modify and enhance it.   

Overview of Charges

• The new company offers information about loans, as well as savings.
• For loans, the program will determine the monthly loan payment for a given loan amount to be borrowed, and calculate total interest paid.

The following formula will determine the loan payment:
MonthlyPayment = (factor * monthlyInterestRate * loanAmount) / (factor - 1);

o The factor is computed the same way for a loan, as it is for savings.   
o The number of months in the factor calculation will be the number of months in the term of the loan.
o After computation, the monthly payment should be rounded to 2 decimal places internally, using the same method that you used to round the total savings accumulation in program 2 from assignment 5. This will insure that the calculation of the total loan payments will be correct.
• The savings display will be expanded to include a specific month and year, for each month displayed, and to include the total amount of interest earned.
Input Overview

The user will now get to choose whether to calculate:
when a savings goal will be reached or what a loan payment will be (new)

A menu of choices will be displayed, including an Exit option. The program will repeat until the user chooses the Exit option from the menu.

The user must enter the numeric month and year that the first loan payment or savings deposit will be made. The user will also still input an annual interest rate, and a dollar amount (saved per month or loan total).   

For savings, the user will also enter a savings goal. For loans, the user will also enter the length of the loan in years. But the upper and lower limits on each have changed:

Saved per month:    10 to 6000
Interest rate:    1% to 20%
Savings goal/loan amount:   100 to 900,000
Years loaned:    1 to 30

Ensure that you define constants for all fixed numeric values. After defining the constants: - Use only the constant name in your code (no hardcoded constant values).   

Output Overview

For a savings time of several years, the values may scroll by too quickly for the user to read them. Therefore your program will also implement a pause after displaying each screen of monthly accumulation totals, as follows:
a) Keep a count of the monthly accumulation lines displayed.   
b) Before displaying each line, check to see if the screen is full ("full" means approximately 20 lines have been displayed on the screen).   
c) Pause after each screen full of data has been displayed, so the user can read the information without it scrolling.
d) After each pause, the column headers should be re-displayed, before displaying the next monthly accumulation line.

Dollar amounts will still be displayed to 2 decimal places, with the decimals lining up. The interest rate will still be displayed to 3 decimal places. The percent sign and “months” labels will still line up.

Sample Savings Output
Month    Accumulated
------    -----------
2015 March             500.00
2015 April            1001.13            
2015 May             1503.38
2015 June             2006.76   
2015 July             2511.28

To reach your savings goal of      2222.00
With a monthly savings of          500.00
At an annual interest rate of       2.700 %
It will take                            5 months
Total savings deposits             2500.00
Interest earned          11.28
Total accumulated                  2511.28

The loan output will include a summary of the inputs, along with the computed monthly payments. It will also display the start and end dates of the loan, along with the total loan payments, and total interest paid. The data will be formatted the same way savings data is.

Sample Loan Output
For a loan amount of                  9000.00
At an annual interest rate of          5.550 %
And a loan period of                        4 years
Monthly payment will be                209.51

Loan will begin                November 2015
Loan will end                   October 2019

Total loan payments                  10056.48
Original loan amount                  9000.00
Total Interest paid will be          1056.48

Required User-defined Functions

1. A new function to read, validate, and return the menu choice.

2. A new generic function called GetNum that will prompt for, read, and validate a value. The function will have 3 parameters: a string prompt, a lower limit for valid values, and an upper limit for valid values. An error message should be displayed each time an invalid value is entered. Once a valid value has been entered, the function will return the validated value (a value between the lower limit and upper limit, inclusive).

3. A revised function to read and validate the annual interest rate. It will now pass back both the yearly interest rate and the monthly interest rate, using reference parameters.

4. A new generic function called GetStartDate that will read and validate the month and year that the loan payments or savings will begin. The function will have one input parameter:   a string description of whether the start date is for a loan or savings.

The function will first prompt for, read, and validate a 4-digit start year, between the current year (defined in a constant) and 5 years in the future. An error message should be displayed each time an invalid year is entered, until a valid year is entered.

After a valid year is entered, the function will prompt for, read, and validate a numeric start month (1 – 12), in a similar fashion.

Both the start year and start month will be passed back, using reference parameters.

NOTE: This function can call other functions.

5. The existing function to calculate and return the factor (from assignment 5, program 2)
6. A new function that takes a month number as an input parameter, and returns the string name of the month for display.   

7. A new function to determine the end date for a loan (month and year), given the start date (month and year), and number of years for loan repayment. The loan end month will be the month prior to the loan start month.   

Example:    Start month:       May 2014
Length of Loan: 5 years
End month:         April 2019

The end date values (month and year) should be passed back via reference parameters. Remember to account for the special case of loans that begin in January, and modify the month and year accordingly.

8. A new void function to process one loan request. This function will read all inputs, do the loan calculations, and display the loan results. It will call other functions to help do these tasks.

9. A new void function to process one savings request. This function will read all inputs, do the savings calculations, and display the savings results. It will call other functions to help do these tasks.

Program Execution

First display a program header and then display a menu to the user. Choices should include loan calculations, savings calculations, and exit the program.

Call a function to perform the action selected.

Read the start date for the loan or savings, and the interest rate that will be used.

Then read the rest of the input needed for calculation requested.
For loans, call the generic function to read integers twice to:
Read the amount to be borrowed
Read the number of years for loan payback.
For savings, call the generic function to read integers twice to:
Read the amount to be saved
Read the total savings goal amount

After reading all of the input for one computation, perform the necessary computations and display the results.

After a pause, so the user can read the results, return to main and re-display the calculations menu.   

Loop, until the user chooses Exit from the calculations menu.


You must write a test plan for this program (program 2). First list the rationale for creating your test cases. Then create each test case.

Your test plan must include both rationale for testing all conditions within the program and a list of the specific test cases. Each test case must include the exact user input used for the test and what the exact output expected.

Submit your test plan as an MS Word document or an MS Excel spreadsheet.

Program and Function Documentation (both programs)

1) Include top of program comments
2) Include prototypes for all of your user-defined functions. The prototypes should be placed above main, and the function definitions should be placed below main.
3) Comment any constants/variables whose names are not completely descriptive.
4) Provide a comment above each user-defined function definition that includes:
o What the function does
o A description of the input parameters, used to pass values into the function
o A description of the output parameters, used to pass values back from the function
o A description of what is returned from the function via the return statement (if anything)

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <cstdlib>
#include <iostream>
using namespace std;

// --------------------------------------------------------
// Description: using formular
// Input parameters: termI, d n
// Returns: termN
// --------------------------------------------------------
int CalcFormulaTerm(int termI, int d, int n){
    return termI + (n - 1) * d;

// --------------------------------------------------------
// Description: using iteration
// Input parameters: termI, d n
// Returns: termN
// --------------------------------------------------------
int CalcLoopTerm(int termI, int d, int n){
    int termN = termI;
    for (int i = 1; i < n; i++) {
       termN += d;
    return termN;

// --------------------------------------------------------
// Description: using recursion
// Input parameters: termI, d n
// Returns: termN
// --------------------------------------------------------
int CalcRecursiveTerm(int termI, int d, int n){
    if (n <= 1)
       return termI;
    return d + CalcRecursiveTerm(termI, d, n - 1);

// --------------------------------------------------------...
$105.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats