StefiIOE

Untitled

Jul 18th, 2020
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. class Course {
  5. protected:
  6. char name [50];
  7. int number;
  8. int nStudents;
  9. public:
  10. Course(char* name="" , int number=0, int nStudents=0) {
  11. strcpy(this->name,name);
  12. this->number=number;
  13. this->nStudents=nStudents;
  14. }
  15. Course(const Course &c) {
  16. strcpy(this->name,c.name);
  17. this->number=c.number;
  18. this->nStudents=c.nStudents;
  19. }
  20. int getClass() {
  21. return number;
  22. }
  23. int getStudents() {
  24. return nStudents;
  25. }
  26. };
  27. class TeachingStaff {
  28. private:
  29. char Name[50];
  30. static int value;
  31. Course course [4];
  32. int n ;
  33. public:
  34.  
  35. TeachingStaff(char* Name = "" ,Course*course = NULL ,int n =0) {
  36. strcpy(this->Name,Name);
  37. this->n=n;
  38. for(int i = 0 ; i < n ; i++) {
  39. this->course[i]=course[i];
  40. }
  41. }
  42. TeachingStaff(const TeachingStaff &s) {
  43. strcpy(this->Name,s.Name);
  44. this->n=s.n;
  45. for(int i = 0 ; i < n ; i++) {
  46. this->course[i]=s.course[i];
  47. }
  48. }
  49. virtual int salary() {
  50. int sum = 0;
  51. for (int i=0;i<n;i++) {
  52. sum+=(course[i].getClass() * course[i].getStudents());
  53. }
  54. return sum*value;
  55. }
  56. static void setValue(int v) {
  57. value=v;
  58. }
  59. const char * getName() {
  60. return Name;
  61. }
  62.  
  63. };
  64. int TeachingStaff::value=50;
  65. class Professor : public TeachingStaff {
  66. private:
  67. const static int plata;
  68. const static float koeficient;
  69. public:
  70. Professor(char *Name="",Course * courses = NULL, int n=0 ): TeachingStaff(Name,courses, n) {}
  71. int salary() {
  72. return plata + koeficient * TeachingStaff::salary();
  73. }
  74. };
  75. const int Professor::plata=30000;
  76. const float Professor::koeficient=1;
  77.  
  78. class AssistantProfessor : public TeachingStaff {
  79. private:
  80. const static int plata;
  81. const static float koeficient;
  82. public:
  83. AssistantProfessor(char *Name="",Course * courses = NULL, int n=0 ): TeachingStaff(Name,courses, n) {}
  84. int salary() {
  85. return plata + koeficient * TeachingStaff::salary();
  86. }
  87. };
  88. const int AssistantProfessor::plata=24000;
  89. const float AssistantProfessor::koeficient=0.8;
  90. class Assistant : public TeachingStaff {
  91. private:
  92. const static int plata;
  93. const static float koeficient;
  94. public:
  95. Assistant(char *Name="",Course * courses = NULL, int n=0 ): TeachingStaff(Name, courses, n) {}
  96. int salary() {
  97. return plata + koeficient * TeachingStaff::salary();
  98. }
  99. };
  100. const int Assistant::plata=18000;
  101. const float Assistant::koeficient=0.6;
  102. void highestSalary (TeachingStaff ** teachers, int n) {
  103. Professor maxProfessor;
  104. AssistantProfessor maxAssProf;
  105. Assistant maxAss;
  106. for (int i=0;i<n;i++) {
  107. Professor * p = dynamic_cast<Professor *>(teachers[i]);
  108. if (p!=0 && p->salary()>maxProfessor.salary())
  109. maxProfessor = *p;
  110. AssistantProfessor * ap = dynamic_cast<AssistantProfessor *>(teachers[i]);
  111. if (ap!=0 && ap->salary()>maxAssProf.salary())
  112. maxAssProf = *ap;
  113. Assistant * a = dynamic_cast<Assistant *>(teachers[i]);
  114. if (a!=0 && a->salary()>maxAss.salary())
  115. maxAss = *a;
  116. }
  117. cout<<maxProfessor.getName();
  118. cout<<maxAssProf.getName();
  119. cout<<maxAss.getName();
  120. }
  121.  
  122.  
  123. int main() {
  124.  
  125. int test;
  126. cin >> test;
  127. if(test == 1) {
  128. cout << "==== Testing class Course ====" << endl;
  129. int noClasses;
  130. int noStudents;
  131. char course[50];
  132. cin.getline(course, 50);
  133. cin >> noClasses >>noStudents;
  134. Course p(course,noClasses,noStudents);
  135. cout << "==== class Course OK ====" << endl;
  136. } else if(test == 2) {
  137. cout << "==== Testing class Profesor ====" << endl;
  138. char name[50];
  139. int n;
  140. Course courses[4];
  141. int noClasses;
  142. int noStudents;
  143. char course[50];
  144. cin >> n;
  145. cin.getline(name, 50);
  146. for(int i = 0; i < n; i++) {
  147. cin.getline(course, 50);
  148. cin.ignore(50,'\n');
  149. cin >> noClasses >> noStudents;
  150. Course p(course, noClasses, noStudents);
  151. courses[i] = p;
  152. }
  153. Professor prof(name, courses, n);
  154. cout << prof.salary();
  155. } else if(test == 3) {
  156. cout << "==== Testing class Docent ====" << endl;
  157. char name[50];
  158. int n;
  159. Course courses[4];
  160. int noClasses;
  161. int noStudents;
  162. char course[50];
  163. cin >> n;
  164. cin.getline(name, 50);
  165. for(int i = 0; i < n; i++) {
  166. cin.getline(course, 50);
  167. cin.ignore(50,'\n');
  168. cin >> noClasses >> noStudents;
  169. Course p(course, noClasses, noStudents);
  170. courses[i] = p;
  171. }
  172. AssistantProfessor d(name, courses, n);
  173. cout << d.salary();
  174. } else if(test == 4) {
  175. cout << "==== Testing class Asistent ====" << endl;
  176. char name[50];
  177. int n;
  178. Course courses[4];
  179. int noClasses;
  180. int noStudents;
  181. char course[50];
  182. cin >> n;
  183. cin.getline(name, 50);
  184. for(int i = 0; i < n; i++) {
  185. cin.getline(course, 50);
  186. cin.ignore(50, '\n');
  187. cin >> noClasses >> noStudents;
  188. Course p(course, noClasses, noStudents);
  189. courses[i] = p;
  190. }
  191. Assistant a(name, courses, n);
  192. cout << a.salary();
  193. } else if(test == 5) {
  194. cout << "==== Testing static variable and abstract class TeachingStaff ====" << endl;
  195. TeachingStaff *teachers[3];
  196. int n, noClasses, noStudents;
  197. char course[50];
  198. Course courses[4];
  199. cin >> n;
  200. for(int i = 0; i < n; i++) {
  201. cin.getline(course, 50);
  202. cin.ignore(50, '\n');
  203. cin >> noClasses >> noStudents;
  204. Course p(course, noClasses, noStudents);
  205. courses[i] = p;
  206. }
  207. teachers[0] = new Professor("Dejan Gjorgjevikj", courses, n);
  208. teachers[1] = new AssistantProfessor("Hristina Mihajloska", courses, n);
  209. teachers[2] = new Assistant("Aleksandar Tenev", courses, n);
  210. for(int i = 0; i < 3; i++) {
  211. cout << teachers[i]->salary() << endl;
  212. }
  213. } else if(test == 6) {
  214. cout << "==== Testing global function ====" << endl;
  215. TeachingStaff *teachers[5];
  216. int n, noClasses, noStudents;
  217. char course[50], name[50];
  218. Course courses[4];
  219. for(int j = 0; j < 5; j++) {
  220. cin >> n;
  221. for(int i = 0; i < n; i++) {
  222. cin.getline(course, 50);
  223. cin.ignore(50,'\n');
  224. cin >> noClasses >> noStudents;
  225. Course p(course, noClasses, noStudents);
  226. courses[i] = p;
  227. }
  228. cin.ignore(50,'\n');
  229. cin.getline(name, 50);
  230. if(j%3 == 0) {
  231. teachers[j] = new Professor(name, courses, n);
  232. } else if(j%3 == 1) {
  233. teachers[j] = new AssistantProfessor(name, courses, n);
  234. } else {
  235. teachers[j] = new Assistant(name, courses, n);
  236. }
  237. }
  238. //for(int i = 0; i < 5; i++)
  239. // cout << teachers[i]->getName() << endl;
  240. // highestSalary(teachers, 5);
  241. }
  242. return 0;
  243. }
RAW Paste Data