Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Course {
- protected:
- char name [50];
- int number;
- int nStudents;
- public:
- Course(char* name="" , int number=0, int nStudents=0) {
- strcpy(this->name,name);
- this->number=number;
- this->nStudents=nStudents;
- }
- Course(const Course &c) {
- strcpy(this->name,c.name);
- this->number=c.number;
- this->nStudents=c.nStudents;
- }
- int getClass() {
- return number;
- }
- int getStudents() {
- return nStudents;
- }
- };
- class TeachingStaff {
- private:
- char Name[50];
- static int value;
- Course course [4];
- int n ;
- public:
- TeachingStaff(char* Name = "" ,Course*course = NULL ,int n =0) {
- strcpy(this->Name,Name);
- this->n=n;
- for(int i = 0 ; i < n ; i++) {
- this->course[i]=course[i];
- }
- }
- TeachingStaff(const TeachingStaff &s) {
- strcpy(this->Name,s.Name);
- this->n=s.n;
- for(int i = 0 ; i < n ; i++) {
- this->course[i]=s.course[i];
- }
- }
- virtual int salary() {
- int sum = 0;
- for (int i=0;i<n;i++) {
- sum+=(course[i].getClass() * course[i].getStudents());
- }
- return sum*value;
- }
- static void setValue(int v) {
- value=v;
- }
- const char * getName() {
- return Name;
- }
- };
- int TeachingStaff::value=50;
- class Professor : public TeachingStaff {
- private:
- const static int plata;
- const static float koeficient;
- public:
- Professor(char *Name="",Course * courses = NULL, int n=0 ): TeachingStaff(Name,courses, n) {}
- int salary() {
- return plata + koeficient * TeachingStaff::salary();
- }
- };
- const int Professor::plata=30000;
- const float Professor::koeficient=1;
- class AssistantProfessor : public TeachingStaff {
- private:
- const static int plata;
- const static float koeficient;
- public:
- AssistantProfessor(char *Name="",Course * courses = NULL, int n=0 ): TeachingStaff(Name,courses, n) {}
- int salary() {
- return plata + koeficient * TeachingStaff::salary();
- }
- };
- const int AssistantProfessor::plata=24000;
- const float AssistantProfessor::koeficient=0.8;
- class Assistant : public TeachingStaff {
- private:
- const static int plata;
- const static float koeficient;
- public:
- Assistant(char *Name="",Course * courses = NULL, int n=0 ): TeachingStaff(Name, courses, n) {}
- int salary() {
- return plata + koeficient * TeachingStaff::salary();
- }
- };
- const int Assistant::plata=18000;
- const float Assistant::koeficient=0.6;
- void highestSalary (TeachingStaff ** teachers, int n) {
- Professor maxProfessor;
- AssistantProfessor maxAssProf;
- Assistant maxAss;
- for (int i=0;i<n;i++) {
- Professor * p = dynamic_cast<Professor *>(teachers[i]);
- if (p!=0 && p->salary()>maxProfessor.salary())
- maxProfessor = *p;
- AssistantProfessor * ap = dynamic_cast<AssistantProfessor *>(teachers[i]);
- if (ap!=0 && ap->salary()>maxAssProf.salary())
- maxAssProf = *ap;
- Assistant * a = dynamic_cast<Assistant *>(teachers[i]);
- if (a!=0 && a->salary()>maxAss.salary())
- maxAss = *a;
- }
- cout<<maxProfessor.getName();
- cout<<maxAssProf.getName();
- cout<<maxAss.getName();
- }
- int main() {
- int test;
- cin >> test;
- if(test == 1) {
- cout << "==== Testing class Course ====" << endl;
- int noClasses;
- int noStudents;
- char course[50];
- cin.getline(course, 50);
- cin >> noClasses >>noStudents;
- Course p(course,noClasses,noStudents);
- cout << "==== class Course OK ====" << endl;
- } else if(test == 2) {
- cout << "==== Testing class Profesor ====" << endl;
- char name[50];
- int n;
- Course courses[4];
- int noClasses;
- int noStudents;
- char course[50];
- cin >> n;
- cin.getline(name, 50);
- for(int i = 0; i < n; i++) {
- cin.getline(course, 50);
- cin.ignore(50,'\n');
- cin >> noClasses >> noStudents;
- Course p(course, noClasses, noStudents);
- courses[i] = p;
- }
- Professor prof(name, courses, n);
- cout << prof.salary();
- } else if(test == 3) {
- cout << "==== Testing class Docent ====" << endl;
- char name[50];
- int n;
- Course courses[4];
- int noClasses;
- int noStudents;
- char course[50];
- cin >> n;
- cin.getline(name, 50);
- for(int i = 0; i < n; i++) {
- cin.getline(course, 50);
- cin.ignore(50,'\n');
- cin >> noClasses >> noStudents;
- Course p(course, noClasses, noStudents);
- courses[i] = p;
- }
- AssistantProfessor d(name, courses, n);
- cout << d.salary();
- } else if(test == 4) {
- cout << "==== Testing class Asistent ====" << endl;
- char name[50];
- int n;
- Course courses[4];
- int noClasses;
- int noStudents;
- char course[50];
- cin >> n;
- cin.getline(name, 50);
- for(int i = 0; i < n; i++) {
- cin.getline(course, 50);
- cin.ignore(50, '\n');
- cin >> noClasses >> noStudents;
- Course p(course, noClasses, noStudents);
- courses[i] = p;
- }
- Assistant a(name, courses, n);
- cout << a.salary();
- } else if(test == 5) {
- cout << "==== Testing static variable and abstract class TeachingStaff ====" << endl;
- TeachingStaff *teachers[3];
- int n, noClasses, noStudents;
- char course[50];
- Course courses[4];
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin.getline(course, 50);
- cin.ignore(50, '\n');
- cin >> noClasses >> noStudents;
- Course p(course, noClasses, noStudents);
- courses[i] = p;
- }
- teachers[0] = new Professor("Dejan Gjorgjevikj", courses, n);
- teachers[1] = new AssistantProfessor("Hristina Mihajloska", courses, n);
- teachers[2] = new Assistant("Aleksandar Tenev", courses, n);
- for(int i = 0; i < 3; i++) {
- cout << teachers[i]->salary() << endl;
- }
- } else if(test == 6) {
- cout << "==== Testing global function ====" << endl;
- TeachingStaff *teachers[5];
- int n, noClasses, noStudents;
- char course[50], name[50];
- Course courses[4];
- for(int j = 0; j < 5; j++) {
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin.getline(course, 50);
- cin.ignore(50,'\n');
- cin >> noClasses >> noStudents;
- Course p(course, noClasses, noStudents);
- courses[i] = p;
- }
- cin.ignore(50,'\n');
- cin.getline(name, 50);
- if(j%3 == 0) {
- teachers[j] = new Professor(name, courses, n);
- } else if(j%3 == 1) {
- teachers[j] = new AssistantProfessor(name, courses, n);
- } else {
- teachers[j] = new Assistant(name, courses, n);
- }
- }
- //for(int i = 0; i < 5; i++)
- // cout << teachers[i]->getName() << endl;
- // highestSalary(teachers, 5);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment