cost 2 company problem ....

  • Thread starter cool_lover_boy007
  • Start date
C

cool_lover_boy007

pls send me the sol'n of this question in c/c++.(
(e-mail address removed))


A company has many employees & each employee is led by only 1 person
except for the CEO (who has no boss). The cost to the company of an
employee is the sum of his salary plus the cost to the company of all
the people led by him. Given is the following structure :

Employee

Data members:
Name
Salary
isBoss
nameOfBoss

Methods:
getSalary
getName


a) Define the class/structure
b) Write a function getCostToCompany() to calculate the cost to the
company of an employee whose name is passed as a parameter to the
function getCostToCompany()

public float getCostToCompany(String name)
 
M

Markus Moll

Hello

pls send me the sol'n of this question in c/c++.(
(e-mail address removed))

What's the email address of your teacher so that we can send the solution
directly to him?

[homework assignment snipped]

Markus
 
F

Frederick Gotham

(e-mail address removed) posted:
pls send me the sol'n of this question in c/c++.(
(e-mail address removed))


Had this assignment myself just a while ago... got an A! I think it's taken
from a programming tutorial book. I post the solution below.

A company has many employees & each employee is led by only 1 person
except for the CEO (who has no boss). The cost to the company of an
employee is the sum of his salary plus the cost to the company of all
the people led by him. Given is the following structure :

Employee

Data members:
Name
Salary
isBoss
nameOfBoss

Methods:
getSalary
getName


a) Define the class/structure


class Employee() {
private string Name;
private uint Salary;
private boolean isBoss;
private string nameOfBoss;

getSalary(uint) void { return Salary; } const

getName(string) void { return Name; } const
};

b) Write a function getCostToCompany() to calculate the cost to the
company of an employee whose name is passed as a parameter to the
function getCostToCompany()


public float getCostToCompany(String const name)
{
float total = 0;

for(Employee const *p = Employee::first_instance();
*p;
++p)
{
if(p->nameOfBoss == name || p->Name == name)
total += p->Salary;
}
}

Hope that helps! Always like to help out a fellow student :)
 
S

shadowman615

pls send me the sol'n of this question in c/c++.(
(e-mail address removed))

Hmmmm. Future offshore contractor for a US software company, I
presume?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top