tags:

views:

196

answers:

5

In a company, there are three categories: A,B,C.

They want to give an increment. So if category C gets N% as increment. category B gets 2N% as increment and category A gets 3N% as increment. But the increment should be atleast 1% and The total updated salary should not exceed $50,000.

Print the increment and the total updated salary for a particular employee.

Assume all the required variables.

How do I solve the above, there seem to be many unknown parameters like SALARY A, SALARY B, SALARY C, and increment N. looking for the maximum possible value of N within the restriction

+4  A: 

If you're looking to implement a simple procedural update of employees, you haven't specified a language (which is good since I only provide pseudo-code for homework anyway), but here it is:

def update (N,MAX)
    if N < 1:
        return
    for every employee E:
        select E.catagory:
            if 'C':
                E.salary = E.salary * (1 +     N / 100)
            endif
            if 'B':
                E.salary = E.salary * (1 + 2 * N / 100)
            endif
            if 'A':
                E.salary = E.salary * (1 + 3 * N / 100)
            endif
        endselect
        if E.salary > MAX:
            E.salary = MAX
        endif
        print E.name " is now on a wage of $" E.salary
     endfor
enddef

Now your task is to translate that into whatever language you have to implement this in :-)


If you're wanting to solve all the unknowns in an equation, you have a problem (conflicting requirements). It appears you may be after the value of N which will make the largest wage $50K.

You just need to go through every employee and figure the maximum percentage out:

def update (MAX) returns N:
    N = Infinity
    for every employee E:
        select E.catagory:
            if 'C':
                ThisN = MAX / E.salary - 1
            endif
            if 'B':
                ThisN = (MAX / E.salary - 1) / 2
            endif
            if 'A':
                ThisN = (MAX / E.salary - 1) / 3
            endif
        endselect
        if ThisN < N:
            N = ThisN
        endif
     endfor
     if N < 1:
         # Conflicting requirement
     endif
enddef

It's possible to come up with a value of N that's less than 1 if, for example, a category C employee is already on $50K. You need to decide what you want to do in that case, either:

  • give no-one a payrise (violates the >=1% rule).
  • give everyone 1% (violates the $50K cap rule).
  • give everyone 1% but cap at $50K (violates the 1,2,3 multiplier rule).

Once you have the percent increase from that code (with your decision on what to do for the conflicting requirements), you can pass it into the first piece of code above to actually do and print the update.

paxdiablo
+1  A: 

To just work out maximum N for any set of salaries:

If N is a percentage, let n be N/100 (to make the math easier). Let the salary for each category be a, b, and c respectively.

Since n >= 0.01, and the salary plus the increment <= 50000, and we can assume a salary is greater than 0, then

0 < a <= 50000 * (1 - n)
0 < b <= 50000 * (1 - 2 * n)
0 < c <= 50000 * (1 - 3 * n)

The last line puts the strongest restriction on n - i.e. 0.01 <= n < 0.333...

You might need to know the minimum wage :)

If you actually have data for employees, then the maximum N will depend on the maximum salary for employees in each category.

max(a) <= 50000 * (1 - n)
max(b) <= 50000 * (1 - 2 * n)
max(c) <= 50000 * (1 - 3 * n)

So we have several requirements for n:

n <= 1 - max(a)/50000
n <= 1/2 - max(b)/100000
n <= 1/3 - max(c)/150000

So you just need the minimum of the values on the right.

sje397
You haven't encoded the "A gets 3N, B gets 2N, C gets N" part, among other things.
Mark E
Sorry Mark - it was a work in progress :)
sje397
@sje397: Nice discussion with you and thanks for your comments
Waleed A.K.
A: 

Given three Lists of Employees' Salaries, A, B, C,

Set Increment=0%
Set TempNewSalaries{A,B,C} = {A+3*Increment%, B+2*Increment%, C+Increment%}
Set NewSalaries{A,B,C} = TempNewSalaries{A,B,C}
While MaximumSalaryOfAll TempNewSalaries{A,B,C} <= 50000
    Set NewSalaries{A,B,C} = TempNewSalaries{A,B,C}
    Increment = (Increment+1)%
    Set TempNewSalaries{A,B,C} = {A+3*Increment%, B+2*Increment%, C+Increment%}
End While
Return NewSalaries{A,B,C}

The pattern here is:

  1. Establish what a higher increment would give
  2. Validate that these values would still be valid given your constraints
  3. Repeat
  4. Return the maximum valid result, discarding the first invalid result
maxwellb
Which could also be implemented using practically any loop and validation choice.
maxwellb
Although, this is updating all salary records of all employees, the flow can be adapted to a single employee.
maxwellb
A: 

Calculate increment between current salary and $50,000. ratio=(50000-current)/current. Then convert to percent above 100. N=100*ratio-100. If Employee is in category C, return N. If Employee is in category B, let N=N/2. Return N. If Employee is in category A, let N=N/3. Return N.

maxwellb
This works best given one employee, and category, find the N to satisfy the conditions.
maxwellb
A: 

The missing variable are the number of employee in each category, and of course not all of them have the same salary, that's why we need the average salary and the number of employee in each category.

Assume the average salary for Category A is SA, B is SB and C is SC

Assume the Employ Number for Category A is NA, B is NB and C is NC

then

 50,000 = ((3N*SA*NA) +(2N*SB*NB)+(N*SC*NC))/100 + ((SA*NA) +(SB*NB)+(SC*NC))

N= ((50,000 -((SA*NA) +(SB*NB)+(SC*NC))) *100)/((3*SA*NA)+(2*SB*NB)+(SC*NC))

let we assume the constant K =100/ ((3*SA*NA)+(2*SB*NB)+(SC*NC))

 M=((SA*NA) +(SB*NB)+(SC*NC))

the amount 0<X<50000 and Y=N then Y=(X-M)*K linear equation

Waleed A.K.
Using the average won't meet the requirement that no increment pushes any employee's salary over the 50k limit.
sje397
@sje397: the requirement is "The total updated salary should not exceed $50,000." and 5*10^6 come from 50,000 *100 see the previous equation.
Waleed A.K.
@Downvoter: please be an adult and tell everyone what's wrong with my answer. Prove it is wrong
Waleed A.K.
@Waleed - I read 'total updated salary' as the total for the given employee, i.e. original salary plus increment. Read that way, using an average is incorrect.
sje397
@sje397: thanks I'll update mu answer
Waleed A.K.
@sje397:the average is necessary because each category could have many employee with different salary. and "Assume all the required variables."
Waleed A.K.
I think you need the maximum in each category to ensure the increment does not take *any* employee over the 50k limit. Since in each case you are multiplying average by number, all you really need there is the total.
sje397
And I think you're still assuming that the 50k limit is for all employees taken together, not each employee individually. 50k is a very small number for the total salaries of all employees of a whole company, even a very small one. We are talking dollars :)
sje397
The total number of employee = NA+NB+NC , go again over my equations please.
Waleed A.K.
if you have 3 employee only one in each category then NA=1 , NB=1 and NC=1 and the average will be the current salary for each employee. in addition nobody mention if the salary weekly, daily, monthly ...
Waleed A.K.
If you never use SA or NA by themselves, but always use SA*NA as per your equations, then why not just use TA (=SA*NA) as an assumed variable as input? I take your point that the 50k limit could be interpreted as a monthly total limit for all employees - but that's an odd thing for a company to do, and a strange way of reading it given the alternative.
sje397
you are right, i put it in this way just to simplify the form, but both should always come together TA (=SA*NA)
Waleed A.K.