Question
In this lab, you will plan and create an algorithm for the problem specification shown in Figure 8-15. You begin by analyzing the problem, looking
In this lab, you will plan and create an algorithm for the problem specification shown in Figure 8-15. You begin by analyzing the problem, looking first for the output and then for the input. In this case, the program should display a persons total earnings before retirement at age 65, using annual raise rates of 3%, 4%, and 5%. To calculate
the amounts, the program will need to know the persons age and current salary.
Next, you plan the algorithm and then desk-check it. Figure 8-15 shows the completed IPO chart and desk-check table, which (for simplicity) uses an age of 62 and a salary of $25000. The algorithm contains two loops. The outer loop keeps track of the three annual raise rates (3%, 4%, and 5%). The nested loop keeps track of the number of years until retirement.
Problem specification Create a program that allows the user to enter a person's age in years) and current salary. Both input items should be entered as integers. The program should display a person's total earnings before retirement at age 65, using annual raise rates of 3%, 4%, and 5%. Display the total earning amounts as integers. Input age (1-6 years) current salary Processing Output PYOES sing itons: total carvings (ot end of vaise rate (3% 4%.5%) Each of the years until years until retirement retirement) new salary year (counter Algorithme: 1. enter the age 2. if (the age is less than 1 or greater than 4) display reenter Message else enter current salary calculate years until retirement = 65 - age repeat for each raise rate) rassign current salary to new salary Lassign current salary to total earings repeat for year 2 to years until retirement) new salary w salary ( + raise rate) add new salary to total earnings end repeat display raisevate and total earnings end repeat end if at this pont, the current salary is vel's salary Current age voise rate years until retirement current salary 25000 Figure 8-15 Problem specification, IPO chart and deskcheck table for the retirement algorithm (continues) (continued WE SALON totaleannings 9562.5 78812.5 Figure 8-15 Problem specification, IPO chart and desk check table for the retirement algorithm The fourth step in the problem-solving process is to code the algorithm into a program. Figure 8-16 shows the IPO chart information and corresponding C++ instructions. C++ instructions IPO chart information Input age (1-64 years) Ourrent salary int age = 0; int current Salary = 0; Processing vaise rate (5%, 4%,5%) years until retirement wew salary year (counter) this variable is created and initialized in the for clause int years ToRetire = 0; double newSalary = 0.0; this variable is created and initialized in the for clause double total = 0.0; Output total earnings (ot end of each of the years until retirement) Algorithm 1. enter the age cout > age; 2. if (the age is less than 1 or greater than (4) display renter message if (ageStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started