d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help With College Practice Code: Iterative > Pseudo Code
Add Reply New Topic New Poll
Member
Posts: 3,013
Joined: Jan 14 2008
Gold: 213.00
Aug 22 2013 11:00pm
So heres the deal,

Classes start Monday and my .net Programming class posted up our 1st weeks practice lesson early.

heres the problem:
The Human Resources Department of Apex Manufacturing Compnay wants a report that shows its employees the benefits of saving for retirement.
Design an algorithm that will produce a report for EACH employee that shows 12 predicted retirement account values for each employee - the values if the employee saves 5, 10, or 15 percent of his or her annual salary for 10, 20, 30, or 40 years.
The algorithm should get employee's name and salary.
The report should include employee's name.
Assume that savings grow at a rate of 8 percent per year.

here is what I came up with for the "pseudo code":
Code
get employee name, employee salary


Do until no more empolyee record
display Employee name
Display Employee salary
 Year count = 1

DO UNTIL year count > 40
 DO UNTIL Year count > 10
  Employee salary = Employee salary
  amount saved = Employee salary * .05
  interest = (amount saved*Year count) * .08
  year count = year count + 1
   
 Loop

Display Employee name
Display (interest+amount saved)
 DO UNTIL Year count > 20
  Employee salary = Employee salary
  amount saved = Employee salary * .05
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

 Do until Year count > 30
  Employee salary = Employee salary
  amount saved = Employee salary * .05
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

 DO UNTIL Year count > 40
  Employee salary = Employee salary
  amount saved = Employee salary * .05
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

Loop

DO UNTIL year count > 40
 DO UNTIL Year count > 10
  Employee salary = Employee salary
  amount saved = Employee salary * .10
  interest = (amount saved*Year count) * .08
  year count = year count + 1
   
 Loop

Display Employee name
Display (interest+amount saved)
 DO UNTIL Year count > 20
  Employee salary = Employee salary
  amount saved = Employee salary * .10
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

 Do until Year count > 30
  Employee salary = Employee salary
  amount saved = Employee salary * .10
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

 DO UNTIL Year count > 40
  Employee salary = Employee salary
  amount saved = Employee salary * .10
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

Loop

DO UNTIL year count > 40
 DO UNTIL Year count > 10
  Employee salary = Employee salary
  amount saved = Employee salary * .15
  interest = (amount saved*Year count) * .08
  year count = year count + 1
   
 Loop

Display Employee name
Display (interest+amount saved)
 DO UNTIL Year count > 20
  Employee salary = Employee salary
  amount saved = Employee salary * .15
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

 Do until Year count > 30
  Employee salary = Employee salary
  amount saved = Employee salary * .15
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

 DO UNTIL Year count > 40
  Employee salary = Employee salary
  amount saved = Employee salary * 15
  interest = (amount saved*Year count) * .08
  year count = year count + 1
 Loop
Display Employee name
Display (interest+amount saved)

Loop
Get next Employee Name, Employee Salary,


I know I Could have done it in a shorter way, I also know it could be totally wrong, but I need some help and guidance.


This post was edited by PumperNickle on Aug 22 2013 11:01pm
Member
Posts: 237
Joined: Aug 6 2011
Gold: 6,026.00
Aug 23 2013 09:13am
you should make a single function that takes the employee, saving % and years worked and returns you the value.

All of these calculations share the same math, this will make your code shorter and much faster to debug, will prevent certain bugs from existing in one formula and not the other. Then call the whole thing from your main

In pseudo code:

Code


mystruct ComputeIntereset(Employee emp, float saved, int years)
{
   /*math goes here*/
   return result; //some sort struct to hold the results
}

void main()
{
  float array saved = {0.05, 0.1, 0.15}
  int array years = {10, 20, 30, 40}

  for(i=0; i<nEmployee; i++)
  {
       for(y=0; y<nyears; y++)
       {
            for(j=0; j<nsaved; j++)
            {
                 mystruct result = ComputeInterest(Employee[i], saved[j], years[y]);
                 
                 /*Display name and results*/
            }
       }
  }
}

Member
Posts: 3,013
Joined: Jan 14 2008
Gold: 213.00
Aug 23 2013 07:43pm
Quote (flyinggoat @ Aug 23 2013 11:13am)
you should make a single function that takes the employee, saving % and years worked and returns you the value.

All of these calculations share the same math, this will make your code shorter and much faster to debug, will prevent certain bugs from existing in one formula and not the other. Then call the whole thing from your main

In pseudo code:

Code
mystruct ComputeIntereset(Employee emp, float saved, int years)
{
   /*math goes here*/
   return result; //some sort struct to hold the results
}

void main()
{
  float array saved = {0.05, 0.1, 0.15}
  int array years = {10, 20, 30, 40}

  for(i=0; i<nEmployee; i++)
  {
       for(y=0; y<nyears; y++)
       {
            for(j=0; j<nsaved; j++)
            {
                 mystruct result = ComputeInterest(Employee[i], saved[j], years[y]);
                 
                 /*Display name and results*/
            }
       }
  }
}


I love you,

now to just put that in to pseudo code.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll