Informatics3-2024/Practical8

A MathWikiből

Tartalomjegyzék

Exercises

Open a new project for each exercise or a new file if you're in the command line.

From this point onward use .cpp file extensions!

From the lecture

Inheritence:

class Circle : public Shape {
protected:
  ...
}

Initializer list:

Circle(float a, float b, float rad) : Shape(a, b), r(rad) {}

Workers

Write a Workers class that can represent an employee in some workplace.

  • A worker should have a name and salary (integer).

Make a class that inherits from this Worker class called Temporary.

  • Temporary workers should have a year data member that is their last year working at the given workplace (their contract is up).
  • Write a method that can extend their contract by the given amount of years.

Make another class that inherits from Worker called Specialist.

  • It should have a specialization data member that stores their area of expertise.

Worker print

Extend the Worker class with a print method that prints the employee's stored data. Implement this in the Temporary and the Specialist class as well. Those should also print their special data members (contract year and specialization).

Write a main function to test these classes. Create all types of workers and call their print method.

Teams

Make a Teams class that stores Workers (100 max). (The best would be if the Workers are stored in a Worker pointer array. That is an array that stores Worker pointers. This way we could store Temporaries and Specialists in the same array as Workers.)

  • It should have an add method that adds a new worker. (Easiest solution is to have the method take a Worker pointer and then it's possible to add Specialists and such with the same method.)
  • Write a print method that prints all workers and their specialized data members as well.
  • Write a teamSalary method that returns the sum of the salary of all workers in the team. (You might have to write a new method in the Workers class for this to work.)

Make a SupervisedTeam class that inherits from Team. The only additional thing it does is that it has one Specialist, who's the supervisor of the team.

  • The print method of a SupervisedTeam should print the supervisor's data first, then a line "---------" and then the team members.

Write a main function that test the Team and SupervisedTeam classes. Try adding all kinds of workers to both, print them and call their teamSalary method.

Company

Write a Company class that stores Teams (100 max).

  • It should have a print method that printes each Team.
  • It should also have an expenditure method that prints the sum of the salaries of all workers (every worker in every team).