Thread: Recruitment paper question

  1. #16
    Registered User
    Join Date
    May 2006
    Posts
    5
    1 assumption i've realized is that every employee should have a unique name.

    @manofsteel972

    Great logic man! I really think thats a great solution. One thing i need to mention is that your solution should iterate for every non-boss node. Coz it is possible for one boss to have more than one employees.

    for e.g,
    Code:
                                                         A
                                                         |
                                          -----------------------------
                                          |                            |
                                          B                            C
                                          |                            |
                                          D                            E
    If we want to find the costocompany of A, then we have to sum up the salaries of B, D, C, E and A.

    So just going through the path D-B-A, or E-C-A is not enough. We have to include both paths, ie, D-B-A AND E-C-A. So we have to start with every non-boss node, and move up higher to check if we encounter the given name, meanwhile summing up the salaries of every node coming in the path. If we encounter the given name, we add it costToCompany... else we will eventually reach the end, and it that case we will not add the sum to costToCompany, and move on to the next non-boss node to repeat the process. We will do this untill we have done this with every non-boss node. In the end, we will have our cost to the freakin company for that particular employee.

    @Wizza

    Thanks for your support. And your solution is so cool coz its so simple!!

    @anon

    I agree, it would make better sense to make classes they way you have. But the problem is given the way its given.

    One more thing, i know in written tests theres nothing much you can do, but if such a problem is asked in an interview, is it better to give the solution as it is, or to say "it makes better sense to do it this way...". I guess i would answer the question as it it, then offer my suggestions to improve it. what do you all say???


    @jmd15

    Yeah, just need to add a bit and your solution is done.

    And yeah, i was just taken aback that poeple would accuse me of getting my "homework" done, and asking me to shoot myself!! lol...Its ironic because the i dont get homework in the first place, and when way back i used to get homework, i never did it. Im a senior (ie, final year) CS student, and we dont even get assignments in c/c++ anymore. Everything is java now. We periodically get some assignments we have to complete as part of a group, and those are fairly big problems. But c/c++ knowledge is still required coz companies ask for it.

    I have a few more similar thought/logic/design problems, if someone is interested. Dont need to post any code. I beleive programming is 99% thought and 1% syntax and code. I think everyone will benefit from discussing stuff like this.

    If you dont want me post more problems, once again, tell me about it, and i wont. Either way, cheers!

  2. #17
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I designed it that way, because I had forgotten the question I was more like responding to the previous poster.

    Anyway, the class needs all getters. Then you make a vector of Employees.

    Then you have this recursive function.

    Code:
    float cost (string& name)
    {
        find person with that name
        cost = his.salary
        if is boss
            for each person
                 if that's his boss cost += cost(thisperson)
        return cost
    }
    Yes, this assumes all names are unique, but that why you'd normally use a person's ID number.

    By the way, I wouldn't mind other exercises. I'm teaching myself C++ and it's not easy to find interesting and challenging problems.
    Last edited by anon; 06-01-2006 at 12:45 AM.

  3. #18
    Registered User
    Join Date
    May 2006
    Posts
    20
    Quote Originally Posted by anon
    Anyway, the class needs all getters. Then you make a vector of Employees.

    Then you have this recursive function.
    Great solution, I didn't go into ss because bluntly I'm kinda ingnorant about it and it was meant to be a thought code, just the simple concept (i don't believe it!! im making excuses for my ignorance)

    Quote Originally Posted by anon
    By the way, I wouldn't mind other exercises. I'm teaching myself C++ and it's not easy to find interesting and challenging problems.
    I hear you man.
    I do software in school, but its too theory based, I'm up for more!!!
    Last edited by Whizza; 06-02-2006 at 02:22 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with rock paper scissors program
    By Mshock in forum C Programming
    Replies: 3
    Last Post: 04-22-2006, 07:44 AM
  2. PRS Help
    By SpudNuts in forum C Programming
    Replies: 10
    Last Post: 08-07-2005, 01:14 PM
  3. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  4. Beginner's Language Paper
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 01-04-2004, 05:48 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM