Homework !!!

I am new at C++ and I am having a lot of trouble understanding it. The following is a homework assignment due this week and I have not

idea how to even start it much less finish coding it. Can anyone out there help?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
You are to design a class called Employee data members:
char name[]
long int ID
double salary , 
and two constructors 
Default construtor Person ()
Copy constructor  Person ( char n[30],long int id,double s)
setPerson (char n[30],long int id,double s)
that allows user to set information for each person
  
You have to define two classes that derived from class
Employee, called Manager and Secretary correspondingly.
Each class should inherit all members from the base class and has its own data members and  member  function as well.  
For example the Manager should have a data member called degree for his/her undergraduated degree (e.g. diploma, bachelor, master, doctor), the Secretary should have her contract (permanent, temporary).  
All member functions of derived class should be overiided from their base class.  
Each derived class should have an operator << which allows user to output a person’s information to the screen. 
Write the following main() to test your classes

int main() {
Person p
(
“Vinh Nguyen”,1234567,500.0);
Manager p1(“An Nguyen Vinh”, 0234567, 1000, Dr.);
Secretary p2;
p2.setPerson(“Lan Vu”, 0341256, 400, permanent);
cout << “Manager p1 is “ << p1;
cout << “Secretary p2 is “ << p2;
return 0;
}
Last edited on
closed account (S6k9GNh0)
Well at least your honest:

Start by making the class. The syntax is something that's easy to look up and learn.
The members are all described to you but you simply need to place them inside the class.

Then you need to derive from the main class using class Manager : public Employee and etc. for the next.

As for the members of these inherited classes, simply place a variable in there you think represents the items needed.
Last edited on
My solution :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Employee {
  public:
    Employee(const char* aName, const Manager* aManager);
    const char* name(void) const;
    const Manager* manager(void) const;
  private:
    const char* theName;
    const Manager* theManager;
  };

class Manager : public Employee {
  public:
    Manager(const char* aName,
                   const Manager* aManager,
                   Secretary* aSecretary = 0);
    void setSecretary(Secretary* aSecretary);
    Secretary* secretary(void);
  private:
    Secretary* theSecretary;
  };

class Secretary : public Employee
  {
  public:
    Secretary(const char* aName,
              const Manager* aManager);
  };




Please help me complete classes !
Last edited on
#include<iostream>
#include<string>
using namespace std;

class Employee
{
protected:
char *name;
double salary;
int birthDate;
public:


Employee() //default constructor
{
name="";
salary=0.0;
birthDate=0;
}

Employee(char *n, double s, int b) //constructor with arguments
{
name=n;
salary=s;
birthDate=b;
}

void getdetail()
{
cout<<"Name: "<<name<<endl;
cout<<"Nalary: "<<salary<<endl;
cout<<"BirthDate: "<<birthDate<<endl;
}
};
class Manager:public Employee
{
private:
char *department; //add data member
public:

Manager():Employee() //base class default constructor
{
department=""; //override the constructor with new data member
}
Manager(char *d, char *n, double s, int b):Employee(n,s,b) //constructor with arguments
{
department=d;
}

void getdetail()
{
Employee::getdetail(); //function overriding
cout<<"department: "<<department<<endl;
}
};
int main()
{
char name[20];
double salary;
int b_date;

cout <<"Enter employee name: ";
cin>>name;
cout <<"Enter employee salary: ";
cin>>salary;
cout <<"Enter employee birthdate: ";
cin>>b_date;
cout <<"\n";
Employee emp(name, salary, b_date);

Manager mg("Department C","Dr. John", 3000, 1984);

emp.getdetail();
cout << "\n\n***********************************\n\n";
mg.getdetail();
system("pause");
return 0;
}
Topic archived. No new replies allowed.