Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Exception{
- public:
- Exception(){}
- void pecati(){
- cout << "Ne moze da se vnese dadeniot trud" << endl;
- }
- };
- class Trud{
- char cj;
- int god;
- public:
- Trud(char c='c', int g=2000){
- cj = c;
- god = g;
- }
- friend istream& operator>>(istream &i, Trud &t){
- return i >> t.cj >> t.god;
- }
- int getGodinaIzdavanje(){
- return god;
- }
- char getVid(){
- return cj;
- }
- };
- class Student{
- protected:
- char ime[31];
- int index;
- int upis;
- int oceni[31];
- int brPolozeni;
- public:
- Student(char *i, int in, int u, int *o, int brP){
- strcpy(ime, i);
- index = in;
- upis = u;
- for(int i=0; i<brP; i++)
- oceni[i] = o[i];
- brPolozeni = brP;
- }
- virtual float rang(){
- float vkupno=0.0;
- for(int i=0; i<brPolozeni; i++){
- vkupno+=oceni[i];
- }
- return vkupno/brPolozeni;
- }
- int getIndex(){
- return index;
- }
- friend ostream& operator<<(ostream &o, Student &s){
- return o << s.index << " " << s.ime << " " << s.upis << " " << s.rang() << endl;
- }
- virtual Student &operator+=(Trud &t){return *this;}
- };
- class PhDStudent : public Student{
- Trud *list;
- int brTrudovi;
- static int conf, journal;
- public:
- PhDStudent(char *i, int in, int u, int *o, int brP, Trud *l, int brT) : Student(i, in, u, o, brP){
- brTrudovi = brT;
- list = new Trud[brTrudovi];
- for(int i=0; i<brTrudovi; i++){
- list[i] = l[i];
- }
- }
- PhDStudent &operator+=(Trud &t){
- //cout <<endl<< upis << " " << t.getGodinaIzdavanje()<<endl;
- if(upis>t.getGodinaIzdavanje()){
- throw Exception();
- }
- else{
- Trud *pom;
- pom = new Trud[brTrudovi];
- for(int i=0; i<brTrudovi; i++){
- pom[i] = list[i];
- }
- list = new Trud[brTrudovi+1];
- for(int i=0; i<brTrudovi; i++){
- list[i] = pom[i];
- }
- delete [] pom;
- list[brTrudovi] = t;
- brTrudovi++;
- return *this;
- }
- }
- static void setConf(int c){
- conf = c;
- }
- static void setJournal(int j){
- journal = j;
- }
- float rang(){
- float suma=0.0;
- for(int i=0; i < brTrudovi; i++){
- if(list[i].getVid()=='c' or list[i].getVid()=='C')suma+=conf;
- else if(list[i].getVid()=='j') suma+=journal;
- }
- return Student::rang()+suma;
- }
- };
- int PhDStudent::conf = 1;
- int PhDStudent::journal = 3;
- int main(){
- int testCase;
- cin >> testCase;
- int god, indeks, n, god_tr, m, n_tr;
- int izbor; //0 za Student, 1 za PhDStudent
- char ime[30];
- int oceni[50];
- char tip;
- Trud trud[50];
- if (testCase == 1){
- cout << "===== Testiranje na klasite ======" << endl;
- cin >> ime;
- cin >> indeks;
- cin >> god;
- cin >> n;
- for (int j = 0; j < n; j++)
- cin >> oceni[j];
- Student s(ime, indeks, god, oceni, n);
- cout << s;
- cin >> ime;
- cin >> indeks;
- cin >> god;
- cin >> n;
- for (int j = 0; j < n; j++)
- cin >> oceni[j];
- cin >> n_tr;
- for (int j = 0; j < n_tr; j++){
- cin >> tip;
- cin >> god_tr;
- Trud t(tip, god_tr);
- trud[j] = t;
- }
- PhDStudent phd(ime, indeks, god, oceni, n, trud, n_tr);
- cout << phd;
- }
- if (testCase == 2){
- cout << "===== Testiranje na operatorot += ======" << endl;
- Student **niza;
- cin >> m;
- niza = new Student *[m];
- for (int i = 0; i<m; i++){
- cin >> izbor;
- cin >> ime;
- cin >> indeks;
- cin >> god;
- cin >> n;
- for (int j = 0; j < n; j++)
- cin >> oceni[j];
- if (izbor == 0){
- niza[i] = new Student(ime, indeks, god, oceni, n);
- }
- else{
- cin >> n_tr;
- for (int j = 0; j < n_tr; j++){
- cin >> tip;
- cin >> god_tr;
- Trud t(tip, god_tr);
- trud[j] = t;
- }
- niza[i] = new PhDStudent(ime, indeks, god, oceni, n, trud, n_tr);
- }
- }
- // pecatenje na site studenti
- cout << "\nLista na site studenti:\n";
- for (int i = 0; i < m; i++)
- cout << *niza[i];
- // dodavanje nov trud za PhD student spored indeks
- Trud t;
- cin >> indeks;
- cin >> t;
- //<MyCode>
- for(int i=0; i<m; i++){
- try{
- if(niza[i]->getIndex()==indeks){
- if(dynamic_cast<PhDStudent*>(niza[i])){
- *niza[i]+=t;
- }
- }
- }
- catch(Exception e){
- e.pecati();
- }
- }
- //</MyCode>
- // vmetnete go kodot za dodavanje nov trud so pomos na operatorot +=
- // pecatenje na site studenti
- cout << "\nLista na site studenti:\n";
- for (int i = 0; i < m; i++)
- cout << *niza[i];
- }
- if (testCase == 3){
- cout << "===== Testiranje na operatorot += ======" << endl;
- Student **niza;
- cin >> m;
- niza = new Student *[m];
- for (int i = 0; i<m; i++){
- cin >> izbor;
- cin >> ime;
- cin >> indeks;
- cin >> god;
- cin >> n;
- for (int j = 0; j < n; j++)
- cin >> oceni[j];
- if (izbor == 0){
- niza[i] = new Student(ime, indeks, god, oceni, n);
- }
- else{
- cin >> n_tr;
- for (int j = 0; j < n_tr; j++){
- cin >> tip;
- cin >> god_tr;
- Trud t(tip, god_tr);
- trud[j] = t;
- }
- niza[i] = new PhDStudent(ime, indeks, god, oceni, n, trud, n_tr);
- }
- }
- // pecatenje na site studenti
- cout << "\nLista na site studenti:\n";
- for (int i = 0; i < m; i++)
- cout << *niza[i];
- // dodavanje nov trud za PhD student spored indeks
- Trud t;
- cin >> indeks;
- cin >> t;
- // vmetnete go kodot za dodavanje nov trud so pomos na operatorot += od Testcase 2
- //<MyCode>
- bool flag=false;
- for(int i=0; i<m; i++){
- if(niza[i]->getIndex()==indeks){
- if(dynamic_cast<PhDStudent*>(niza[i])){
- *niza[i]+=t;
- flag=true;
- }
- }
- }
- if(!flag)
- cout << "Ne postoi PhD student so indeks " << indeks << endl;
- //</MyCode>
- // pecatenje na site studenti
- cout << "\nLista na site studenti:\n";
- for (int i = 0; i < m; i++)
- cout << *niza[i];
- }
- if (testCase == 4){
- cout << "===== Testiranje na isklucoci ======" << endl;
- cin >> ime;
- cin >> indeks;
- cin >> god;
- cin >> n;
- for (int j = 0; j < n; j++)
- cin >> oceni[j];
- cin >> n_tr;
- for (int j = 0; j < n_tr; j++){
- cin >> tip;
- cin >> god_tr;
- Trud t(tip, god_tr);
- trud[j] = t;
- }
- cout<<"Ne moze da se vnese dadeniot trud"<<endl;
- PhDStudent phd(ime, indeks, god, oceni, n, trud, n_tr);
- cout << phd;
- }
- if (testCase == 5){
- cout << "===== Testiranje na isklucoci ======" << endl;
- Student **niza;
- cin >> m;
- niza = new Student *[m];
- for (int i = 0; i<m; i++){
- cin >> izbor;
- cin >> ime;
- cin >> indeks;
- cin >> god;
- cin >> n;
- for (int j = 0; j < n; j++)
- cin >> oceni[j];
- if (izbor == 0){
- niza[i] = new Student(ime, indeks, god, oceni, n);
- }
- else{
- cin >> n_tr;
- for (int j = 0; j < n_tr; j++){
- cin >> tip;
- cin >> god_tr;
- Trud t(tip, god_tr);
- trud[j] = t;
- }
- niza[i] = new PhDStudent(ime, indeks, god, oceni, n, trud, n_tr);
- }
- }
- // pecatenje na site studenti
- cout << "\nLista na site studenti:\n";
- for (int i = 0; i < m; i++)
- cout << *niza[i];
- // dodavanje nov trud za PhD student spored indeks
- Trud t;
- cin >> indeks;
- cin >> t;
- // vmetnete go kodot za dodavanje nov trud so pomos na operatorot += i spravete se so isklucokot
- //<MyCode>
- for(int i=0; i<m; i++){
- try{
- if(niza[i]->getIndex()==indeks){
- if(dynamic_cast<PhDStudent*>(niza[i])){
- *niza[i]+=t;
- }
- }
- }
- catch(Exception e){
- e.pecati();
- }
- }
- //</MyCode>
- // pecatenje na site studenti
- cout << "\nLista na site studenti:\n";
- for (int i = 0; i < m; i++)
- cout << *niza[i];
- }
- if (testCase == 6){
- cout << "===== Testiranje na static clenovi ======" << endl;
- Student **niza;
- cin >> m;
- niza = new Student *[m];
- for (int i = 0; i<m; i++){
- cin >> izbor;
- cin >> ime;
- cin >> indeks;
- cin >> god;
- cin >> n;
- for (int j = 0; j < n; j++)
- cin >> oceni[j];
- if (izbor == 0){
- niza[i] = new Student(ime, indeks, god, oceni, n);
- }
- else{
- cin >> n_tr;
- for (int j = 0; j < n_tr; j++){
- cin >> tip;
- cin >> god_tr;
- Trud t(tip, god_tr);
- trud[j] = t;
- }
- niza[i] = new PhDStudent(ime, indeks, god, oceni, n, trud, n_tr);
- }
- }
- // pecatenje na site studenti
- cout << "\nLista na site studenti:\n";
- for (int i = 0; i < m; i++)
- cout << *niza[i];
- int conf, journal;
- cin >> conf;
- cin >> journal;
- //postavete gi soodvetnite vrednosti za statickite promenlivi
- //<MyCode>
- for(int i=0; i < m; i++){
- if(dynamic_cast<PhDStudent*>(niza[i])){
- PhDStudent *pok=dynamic_cast<PhDStudent*>(niza[i]);
- pok->setConf(conf);
- pok->setJournal(journal);
- }
- }
- //</MyCode>
- // pecatenje na site studenti
- cout << "\nLista na site studenti:\n";
- for (int i = 0; i < m; i++)
- cout << *niza[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment