Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 9. Фудбалска екипа
- #include <iostream>
- #include <cstring>
- using namespace std;
- // vashiot kod ovde
- class FudbalskaEkipa{
- protected:
- int golovi[10];
- char imeTrener[100];
- public:
- FudbalskaEkipa(const char *imeTrener,int *golovi)
- {
- strcpy(this->imeTrener,imeTrener);
- for(int i=0;i<10;i++)
- {
- this->golovi[i]=golovi[i];
- }
- }
- FudbalskaEkipa &operator+=(int gol)
- {
- int tmp[10];
- for(int i=1; i<10; i++)
- golovi[i-1]=golovi[i];
- golovi[9]=gol;
- return *this;
- }
- virtual int uspeh()=0;
- virtual ~FudbalskaEkipa(){};
- char *getTrener()
- {
- return imeTrener;
- }
- virtual char *getIme()=0;
- };
- class Klub:public FudbalskaEkipa{
- private:
- char *ime;
- int brTituli;
- public:
- Klub(char *imeTrener,int *golovi,char *ime,int brTituli):FudbalskaEkipa(imeTrener,golovi)
- {
- this->ime=new char(strlen(ime));
- strcpy(this->ime,ime);
- this->brTituli=brTituli;
- }
- ~Klub(){
- delete[]ime;}
- int uspeh()
- {
- int i,sum=0;
- for(i=0;i<10;i++)
- {
- sum+=golovi[i];
- }
- sum*=3;
- sum+=(brTituli*1000);
- return sum;
- }
- char *getIme()
- {
- return ime;
- }
- bool operator>(Klub &k)
- {
- if(uspeh()>k.uspeh())
- return true;
- else return false;
- }
- };
- class Reprezentacija:public FudbalskaEkipa{
- private:
- char *ime;
- int brNastapi;
- public:
- Reprezentacija(char *imeTrener,int *golovi,const char *ime,int brNastapi):FudbalskaEkipa(imeTrener,golovi)
- {
- this->ime=new char(strlen(ime));
- strcpy(this->ime,ime);
- this->brNastapi=brNastapi;
- }
- ~Reprezentacija(){
- delete[]ime;}
- int uspeh()
- {
- int i,sum=0;
- for(i=0;i<10;i++)
- {
- sum+=golovi[i];
- }
- sum*=3;
- sum+=(brNastapi*50);
- return sum;
- }
- char *getIme()
- {
- return ime;
- }
- bool operator>(Reprezentacija &r)
- {
- if(uspeh()>r.uspeh())
- return true;
- else return false;
- }
- };
- ostream &operator<<(ostream &out,FudbalskaEkipa &e)
- {
- FudbalskaEkipa *tmp=&e;
- out<<tmp->getIme()<<"\n"<<tmp->getTrener()<<"\n"<<tmp->uspeh()<<endl;
- return out;
- }
- void najdobarTrener(FudbalskaEkipa **niza,int n){
- int max=0,maxI;
- for(int i=0;i<n;i++){
- if(niza[i]->uspeh()>max){
- max=niza[i]->uspeh();
- maxI=i;
- }
- }
- cout<<*niza[maxI];
- }
- int main() {
- int n;
- cin >> n;
- FudbalskaEkipa **ekipi = new FudbalskaEkipa*[n];
- char coach[100];
- int goals[10];
- char x[100];
- int tg;
- for (int i = 0; i < n; ++i) {
- int type;
- cin >> type;
- cin.getline(coach, 100);
- cin.getline(coach, 100);
- for (int j = 0; j < 10; ++j) {
- cin >> goals[j];
- }
- cin.getline(x, 100);
- cin.getline(x, 100);
- cin >> tg;
- if (type == 0) {
- ekipi[i] = new Klub(coach, goals, x, tg);
- } else if (type == 1) {
- ekipi[i] = new Reprezentacija(coach, goals, x, tg);
- }
- }
- cout << "===== SITE EKIPI =====" << endl;
- for (int i = 0; i < n; ++i) {
- cout << *ekipi[i];
- }
- cout << "===== DODADI GOLOVI =====" << endl;
- for (int i = 0; i < n; ++i) {
- int p;
- cin >> p;
- cout << "dodavam golovi: " << p << endl;
- *ekipi[i] += p;
- }
- cout << "===== SITE EKIPI =====" << endl;
- for (int i = 0; i < n; ++i) {
- cout << *ekipi[i];
- }
- cout << "===== NAJDOBAR TRENER =====" << endl;
- najdobarTrener(ekipi, n);
- for (int i = 0; i < n; ++i) {
- delete ekipi[i];
- }
- delete [] ekipi;
- return 0;
- }
- 10. FINKI-Издавачка куќа
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Book {
- protected:
- char ISBN[20];
- char naslov[50];
- char avtor[30];
- int cena;
- public:
- Book (char * i, char * n, char * a, int c) {
- strcpy(ISBN,i); strcpy(naslov,n); strcpy(avtor,a); cena=c;
- }
- virtual double bookPrice () = 0;
- virtual ~Book () {}
- friend ostream &operator << (ostream &out, Book &b) {
- out<<b.ISBN<<": "<<b.naslov<<", "<<b.avtor<<" "<<b.bookPrice()<<endl;
- return out;
- }
- bool operator > (const Book &b){
- return cena > b.cena;
- }
- void setISBN (const char * i) {strcpy(ISBN,i); }
- };
- class OnlineBook : public Book {
- private:
- char * url;
- int golemina;
- public:
- OnlineBook (char * i, char * n, char * a, int c, char *u, int g) : Book(i,n,a,c) {
- url = new char [strlen(u)+1];
- strcpy(url,u); golemina=g;
- }
- // ~OnlineBook () {delete [] url; }
- double bookPrice () {
- if (golemina>20)
- return 1.2*cena;
- else return cena;
- }
- };
- class PrintBook : public Book {
- private:
- double masa;
- bool zaliha;
- public:
- PrintBook (char * i, char * n, char * a, int c, double m, bool z) : Book (i,n,a,c) {
- masa=m; zaliha=z;
- }
- double bookPrice () {
- if (masa>0.7)
- return 1.15*cena;
- else
- return cena;
- }
- };
- void mostExpensiveBook (Book ** books, int n) { //broj na online, broj na pecateni, najskapa kniga
- int online=0, pecateni=0;
- int maxcena=0,maxi;
- for (int i=0;i<n;i++) {
- Book * tmp = dynamic_cast < OnlineBook *>(books[i]);
- if (tmp)
- ++online;
- else ++pecateni;
- if (books[i]->bookPrice() > maxcena){
- maxi=i;
- maxcena=books[i]->bookPrice();
- }
- }
- cout<<"FINKI-Education"<<endl;
- cout<<"Total number of online books: "<<online<<endl;
- cout<<"Total number of print books: "<<pecateni<<endl;
- cout<<"The most expensive book is: "<<endl;
- cout<<*books[maxi];
- }
- int main(){
- char isbn[20], title[50], author[30], url[100];
- int size, tip;
- float price, weight;
- bool inStock;
- Book **books;
- int n;
- int testCase;
- cin >> testCase;
- if (testCase == 1){
- cout << "====== Testing OnlineBook class ======" << endl;
- cin >> n;
- books = new Book *[n];
- for (int i = 0; i < n; i++){
- cin >> isbn;
- cin.get();
- cin.getline(title, 50);
- cin.getline(author, 30);
- cin >> price;
- cin >> url;
- cin >> size;
- cout << "CONSTRUCTOR" << endl;
- books[i] = new OnlineBook(isbn, title, author, price, url, size);
- cout << "OPERATOR <<" << endl;
- cout << *books[i];
- }
- cout << "OPERATOR >" << endl;
- cout << "Rezultat od sporedbata e: " << endl;
- if (*books[0] > *books[1])
- cout << *books[0];
- else
- cout << *books[1];
- }
- if (testCase == 2){
- cout << "====== Testing OnlineBook CONSTRUCTORS ======" << endl;
- cin >> isbn;
- cin.get();
- cin.getline(title, 50);
- cin.getline(author, 30);
- cin >> price;
- cin >> url;
- cin >> size;
- cout << "CONSTRUCTOR" << endl;
- OnlineBook ob1(isbn, title, author, price, url, size);
- cout << ob1 << endl;
- cout << "COPY CONSTRUCTOR" << endl;
- OnlineBook ob2(ob1);
- cin >> isbn;
- ob2.setISBN(isbn);
- cout << ob1 << endl;
- cout << ob2 << endl;
- cout << "OPERATOR =" << endl;
- ob1 = ob2;
- cin >> isbn;
- ob2.setISBN(isbn);
- cout << ob1 << endl;
- cout << ob2 << endl;
- }
- if (testCase == 3){
- cout << "====== Testing PrintBook class ======" << endl;
- cin >> n;
- books = new Book *[n];
- for (int i = 0; i < n; i++){
- cin >> isbn;
- cin.get();
- cin.getline(title, 50);
- cin.getline(author, 30);
- cin >> price;
- cin >> weight;
- cin >> inStock;
- cout << "CONSTRUCTOR" << endl;
- books[i] = new PrintBook(isbn, title, author, price, weight, inStock);
- cout << "OPERATOR <<" << endl;
- cout << *books[i];
- }
- cout << "OPERATOR >" << endl;
- cout << "Rezultat od sporedbata e: " << endl;
- if (*books[0] > *books[1])
- cout << *books[0];
- else
- cout << *books[1];
- }
- if (testCase == 4){
- cout << "====== Testing method mostExpensiveBook() ======" << endl;
- cin >> n;
- books = new Book *[n];
- for (int i = 0; i<n; i++){
- cin >> tip >> isbn;
- cin.get();
- cin.getline(title, 50);
- cin.getline(author, 30);
- cin >> price;
- if (tip == 1) {
- cin >> url;
- cin >> size;
- books[i] = new OnlineBook(isbn, title, author, price, url, size);
- }
- else {
- cin >> weight;
- cin >> inStock;
- books[i] = new PrintBook(isbn, title, author, price, weight, inStock);
- }
- }
- mostExpensiveBook(books, n);
- }
- for (int i = 0; i<n; i++) delete books[i];
- delete[] books;
- return 0;
- }
- 12. Научни трудови
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Exception {
- public:
- void print() {
- cout<<"Ne moze da se vnese dadeniot trud"<<endl;
- }
- };
- class Trud {
- private:
- char vid;
- int godina;
- static int J;
- static int C;
- public:
- Trud() {
- }
- Trud(char vid, int godina) {
- this->vid = vid;
- this->godina = godina;
- }
- Trud(const Trud &t) {
- this->vid = t.vid;
- this->godina = t.godina;
- }
- ~Trud() {
- }
- void setVid(char vid) {
- this->vid = vid;
- }
- void setGodina(int godina) {
- this->godina = godina;
- }
- char getVid() {
- return vid;
- }
- int getGodina() {
- return godina;
- }
- static void setJ(int j) {
- J = j;
- }
- static void setC(int c) {
- C = c;
- }
- int getC() {
- return C;
- }
- int getJ() {
- return J;
- }
- friend istream &operator>>(istream &in, Trud &t) {
- in>>t.vid;
- in>>t.godina;
- return in;
- }
- };
- int Trud::C = 1;
- int Trud::J = 3;
- class Student {
- protected:
- char ime[30];
- int index;
- int godinaUpis;
- int *oceni;
- int brojOceni;
- public:
- Student(char *ime="", int index =0, int godinaUpis=0, int *oceni=NULL, int brojOceni=0) {
- strcpy(this->ime, ime);
- this->index = index;
- this->godinaUpis = godinaUpis;
- this->oceni = new int[brojOceni];
- for(int i=0; i<brojOceni; i++) {
- this->oceni[i] = oceni[i];
- }
- this->brojOceni = brojOceni;
- }
- ~Student() {
- delete []oceni;
- }
- virtual float rang() {
- int suma=0;
- for(int i=0; i<brojOceni; i++) {
- suma = suma + oceni[i];
- }
- return (float)suma/brojOceni;
- }
- friend ostream &operator<<(ostream &out, Student &s) {
- out<<s.index<<" "<<s.ime<<" "<<s.godinaUpis<<" "<<s.rang()<<endl;
- return out;
- }
- int getGodinaUpis() {
- return godinaUpis;
- }
- int getIndeks() {
- return index;
- }
- };
- class PhDStudent : public Student {
- private:
- Trud *trudovi;
- int brojTrudovi;
- public:
- PhDStudent(char *ime="", int index =0, int godinaUpis=0, int *oceni=NULL, int brojOceni=0, Trud *trudovi=NULL, int brojTrudovi=0)
- :Student(ime, index, godinaUpis, oceni, brojOceni) {
- this->trudovi = new Trud[brojTrudovi];
- int j=0;
- for(int i=0; i<brojTrudovi; i++) {
- try{
- if(this->getGodinaUpis() > trudovi[i].getGodina())
- throw Exception();
- this->trudovi[j] = trudovi[i];
- j++;
- }
- catch (Exception e) { e.print();}
- }
- this->brojTrudovi = j;
- }
- PhDStudent(const PhDStudent &p):Student(p) {
- this->trudovi = new Trud[p.brojTrudovi];
- for(int i=0; i<brojTrudovi; i++) {
- this->trudovi[i] = p.trudovi[i];
- }
- this->brojTrudovi = p.brojTrudovi;
- }
- PhDStudent &operator=(const PhDStudent &p) {
- if(this != &p) {
- delete []trudovi;
- this->trudovi = new Trud[p.brojTrudovi];
- for(int i=0; i<brojTrudovi; i++) {
- this->trudovi[i] = p.trudovi[i];
- }
- this->brojTrudovi = p.brojTrudovi;
- }
- return *this;
- }
- ~PhDStudent() {
- delete []trudovi;
- }
- float rang() {
- float r = Student::rang();
- for(int i=0; i<brojTrudovi; i++) {
- if(trudovi[i].getVid()=='J' || trudovi[i].getVid()=='j')
- r += trudovi[i].getJ();
- else if(trudovi[i].getVid()=='C' || trudovi[i].getVid()=='c')
- r += trudovi[i].getC();
- }
- return r;
- }
- void operator+=(Trud &t) {
- if(getGodinaUpis() > t.getGodina())
- throw Exception();
- this->trudovi[brojTrudovi] = t;
- this->brojTrudovi++;
- }
- };
- 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;
- int flag = 1;
- for (int i = 0; i < m; i++) {
- if ((*niza[i]).getIndeks() == indeks) {
- PhDStudent* nov = dynamic_cast<PhDStudent*>(niza[i]);
- if (nov != 0) {
- (*nov) += t;
- flag = 0;
- break;
- }
- }
- }
- if (flag)
- cout << "Ne postoi PhD student so indeks " << indeks << endl;
- // 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;
- int flag = 1;
- for (int i = 0; i < m; i++) {
- if ((*niza[i]).getIndeks() == indeks) {
- PhDStudent* nov = dynamic_cast<PhDStudent*>(niza[i]);
- if (nov != 0) {
- (*nov) += t;
- flag = 0;
- break;
- }
- }
- }
- if (flag)
- cout << "Ne postoi PhD student so indeks " << indeks << endl;
- // 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;
- }
- PhDStudent phd(ime, indeks, god, oceni, n, trud, n_tr);
- //cout<<"Ne moze da se vnese dadeniot trud"<<endl;
- 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;
- int flag = 1;
- for (int i = 0; i < m; i++) {
- if ((*niza[i]).getIndeks() == indeks) {
- PhDStudent* nov = dynamic_cast<PhDStudent*>(niza[i]);
- if (nov != 0) {
- try {
- flag = 0;
- (*nov) += t;
- break;
- } catch (Exception e) {
- e.print();
- }
- }
- }
- }
- if (flag)
- cout << "Ne postoi PhD student so indeks " << indeks << endl;
- // 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;
- Trud::setC(conf);
- Trud::setJ(journal);
- // 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
Advertisement