Jump to content



Photo

help with pseudocode

pseudocode

  • Please log in to reply
6 replies to this topic

#1 natta

natta

    Neowinian

  • Joined: 23-October 13

Posted 23 October 2013 - 20:04

I need some help

Can you guys help me write a pseudocode, please?

Here's the problem:

Consider the following description of a problem

 

A company intends to offer a salary increase in accordance with the position of each employee, as the following table

position  --    raise

manager -->         5%
engineer ->        25%
technician ->      40%


develop an algorithm that reads the salary and job code of a employe and calculate the new salary.

if the position of the employee is not in the table, it must receive an increase of 50%. in the end, the algorithm should indicate the old salary, new salary and the difference between them.

present an algorithm using the Structure IF

 

and they ask for another algorytm for the Case Structure

 

any help please :cry:




#2 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 14
  • Joined: 26-October 05

Posted 24 October 2013 - 00:13

What is your question?



#3 OP natta

natta

    Neowinian

  • Joined: 23-October 13

Posted 24 October 2013 - 11:47

What is your question?

I'm trying to write the algorithm for that problem, asik.

 

i'm taking code classes and i still have a lot to learn.

 

can you help me generate a code for that particular problem, using the structure IF? and another algorithm for the same problem, using the structure case?



#4 articuno1au

articuno1au

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 20-March 11
  • Location: Brisbane, Australia

Posted 24 October 2013 - 11:53

IF (Person.Role == Role)
{
Wage.Difference = Wage.Initial * Role.Raise
Wage.Final = Wage.Initial + Wage.Difference
}
ELSE
{
Wage.Difference = Wage.Initial * 0.5
Wage.Final = Wage.Initial + Wage.Difference
}

That's how I'd write it, but depends on how they've taught you to write pseudo code.



#5 Cocoliso

Cocoliso

    Neowinian

  • Joined: 13-July 09

Posted 24 October 2013 - 12:20

It is just a simple conditional algorithm ->

read What's your position?
read What's your current salary?

if (Position = Manager) {
NewSalary = CurrentSalary * (1 + 5/100)
} else if (Position = Engineer) { 
NewSalary = CurrentSalary * (1 + 25/100)
} else if ... {

} else {
NewSalary = CurrentSalary * (1 + 50/100)
}

DiffSalary = NewSalary - CurrentSalary

print CurrentSalary
print NewSalary
print DiffSalary

with "case" it is practically the same  just change the conditional with something like this

case Position of
Manager: NewSalary = CurrentSalary * (1 + 5/100)
Engineer: NewSalary = CurrentSalary * (1 + 25/100)
...
default: NewSalary = CurrentSalary * (1 + 50/100)

endcase

Cheers



#6 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 14
  • Joined: 26-October 05

Posted 24 October 2013 - 16:35

I'm trying to write the algorithm for that problem, asik.

 

i'm taking code classes and i still have a lot to learn.

 

can you help me generate a code for that particular problem, using the structure IF? and another algorithm for the same problem, using the structure case?

I understand you want help with that, but you didn't ask a question, so short of providing you with a complete answer to your assignment I don't know what to say. Do you not understand what is an If structure, i.e.

if [condition] then
     (...)
else if [other condition] then
     (...)
else
     (...)

? Or a switch-case statement? I can only guess at what you don't understand, if you don't point it out.



#7 Hardcore Til I Die

Hardcore Til I Die

    Neowinian Senior

  • Joined: 18-February 07
  • Location: England

Posted 24 October 2013 - 19:15

// raise amounts as decimals
 
var manager_raise = 1.05
var engineer_raise = 1.25
var technician_raise = 1.40
 
foreach (employee in company) {
  if (employee.job == "manager") { employee.wage *= manager_raise }
  elseif (employee.job == "engineer") { employee.wage *= engineer_raise }
  elseif (employee.job == "technician") { employee.wage *= technician_raise }
}