Qs.1: 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 :EmployeeData members:NameSalaryisBossnameOfBossMethods:getSalarygetNamea) Define the class/structureb) 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()

Showing Answers 1 - 4 of 4 Answers

ramakrishnaraju

  • Jun 18th, 2007
 

I have one solution: (if any other
assumptions, according to questions let me know them.. i can solve it.)

Create a table: (the description of table is given)

SQL> desc t_emp;

Name             Null? Type

---------------- ----- ----
ENAME VARCHAR2(30)
ISBOSS VARCHAR2(3)
BOSSNAME VARCHAR2(30)
SALARY NUMBER(5)

and insert few rows.
(example)
SQL> select *from t_emp;

ENAME ISB BOSSNAME SALARY
-------- --- -------- ------
srk   yes basky  5000
basky yes asha   4000
asha  yes       10000

Now Create a function:

Create or replace function getCtc(name in varchar) return number is

ctc number(10);
cursor cur_emp is select *from t_emp;
begin
select salary into ctc from t_emp where ename=name;
for rec in cur_emp
loop
if rec.bossname=name then
ctc:= ctc+rec.salary;
end if;
end loop;
return ctc;
end;
Create a procedure which uses the above function
create or replace procedure ctc is
x number(10);
begin
x:=getctc('basky');
dbms_output.put_line(x);
end;

Execute the function as follows:
SQL> exec ctc

-Regards
Ramakrishnaraju.

Basky
CMC


  Was this answer useful?  Yes

Harsh Maheshwari

  • Sep 19th, 2007
 

Use binary tree concept.
since every node has 2-node(except root node).

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions