Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. Транспорт
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Transport
- {
- protected:
- char destinacija [50];
- int osnovnaCena;
- int rastojanie;
- public:
- Transport(){}
- Transport(const char *dest, int oc, int ras)
- {
- strcpy(destinacija, dest);
- osnovnaCena=oc;
- rastojanie=ras;
- }
- virtual double cenaTransport()=0;
- virtual char* getDestinacija()
- {
- return destinacija;
- }
- int getRastojanie()
- {
- return rastojanie;
- }
- virtual ~Transport(){}
- };
- bool operator < (Transport &t1, Transport *t2)
- {
- return t1.getRastojanie()>t2->getRastojanie();
- }
- class AvtomobilTransport: public Transport
- {
- private:
- bool shofer;
- public:
- AvtomobilTransport():Transport(){}
- AvtomobilTransport(const char *dest, int oc, int ras, bool s):Transport(dest, oc, ras)
- {
- shofer=s;
- }
- char* getDestinacija()
- {
- return destinacija;
- }
- double cenaTransport()
- {
- if(shofer)
- {
- //osnovnaCena*=1.2;
- return osnovnaCena*1.2;
- }
- else return osnovnaCena;
- }
- };
- class KombeTransport: public Transport
- {
- private:
- int patnici;
- public:
- KombeTransport():Transport(){}
- KombeTransport(const char *dest, int oc, int ras, int pat):Transport(dest, oc, ras)
- {
- patnici=pat;
- }
- char* getDestinacija()
- {
- return destinacija;
- }
- double cenaTransport()
- {
- return osnovnaCena-patnici*200.0;
- }
- };
- void pecatiPoloshiPonudi(Transport **t, int n, AvtomobilTransport &pon)
- {
- Transport *pom;
- for(int i=0; i<n-1; i++)
- {
- for(int j=i+1; j<n; j++)
- {
- if(*t[i]<t[j])
- {
- pom=t[j];
- t[j]=t[i];
- t[i]=pom;
- }
- }
- }
- for(int i=0; i<n; i++)
- {
- if(t[i]->cenaTransport()>=pon.cenaTransport())
- cout<<t[i]->getDestinacija()<<" "<<t[i]->getRastojanie()<<" "<<t[i]->cenaTransport()<<endl;
- }
- }
- int main(){
- char destinacija[20];
- int tip,cena,rastojanie,lugje;
- bool shofer;
- int n;
- cin>>n;
- Transport **ponudi;
- ponudi=new Transport *[n];
- for (int i=0;i<n;i++){
- cin>>tip>>destinacija>>cena>>rastojanie;
- if (tip==1) {
- cin>>shofer;
- ponudi[i]=new AvtomobilTransport(destinacija,cena,rastojanie,shofer);
- }
- else {
- cin>>lugje;
- ponudi[i]=new KombeTransport(destinacija,cena,rastojanie,lugje);
- }
- }
- AvtomobilTransport nov("Ohrid",2000,600,false);
- pecatiPoloshiPonudi(ponudi,n,nov);
- for (int i=0;i<n;i++) delete ponudi[i];
- delete [] ponudi;
- return 0;
- }
- //2. Демонстратор 1
- #include<iostream>
- #include<string.h>
- using namespace std;
- class NoCourseException {
- private:
- int index;
- public:
- NoCourseException(int i) {
- index=i;
- }
- void message() {
- cout<<"Demonstratorot so indeks "<< index <<" ne drzi laboratoriski vezbi"<<endl;
- }
- };
- class Kurs {
- private:
- char ime[20];
- int krediti;
- public:
- Kurs (char *ime, int krediti) {
- strcpy(this->ime,ime);
- this->krediti=krediti;
- }
- Kurs(const Kurs &k) {
- strcpy(ime, k.ime);
- krediti=k.krediti;
- }
- Kurs () {
- strcpy(this->ime,"");
- krediti=0;
- }
- bool operator==(const char *ime) const {
- return strcmp(this->ime,ime)==0;
- }
- char const * getIme()const {
- return ime;
- }
- void pecati ()const {
- cout<<ime<<" "<<krediti<<"ECTS";
- }
- };
- class Student {
- private:
- int *ocenki;
- int brojOcenki;
- protected:
- int indeks;
- public:
- Student() {
- ocenki=new int[0];
- brojOcenki=0;
- }
- Student(int indeks,int *ocenki, int brojOcenki) {
- this->indeks=indeks;
- this->brojOcenki=brojOcenki;
- this->ocenki=new int[brojOcenki];
- for (int i=0; i<brojOcenki; i++) this->ocenki[i]=ocenki[i];
- }
- Student(const Student &k) {
- this->indeks=k.indeks;
- this->brojOcenki=k.brojOcenki;
- this->ocenki=new int[k.brojOcenki];
- for (int i=0; i<k.brojOcenki; i++) this->ocenki[i]=k.ocenki[i];
- }
- Student& operator=(const Student &k) {
- if (&k==this) return *this;
- this->indeks=k.indeks;
- this->brojOcenki=k.brojOcenki;
- delete [] ocenki;
- this->ocenki=new int[k.brojOcenki];
- for (int i=0; i<k.brojOcenki; i++) this->ocenki[i]=k.ocenki[i];
- return *this;
- }
- virtual ~Student() {
- delete [] ocenki;
- }
- virtual int getBodovi() {
- int brojac=0;
- for(int i=0; i<brojOcenki; i++) {
- if(ocenki[i]>5)
- brojac++;
- }
- return brojac*100/brojOcenki;
- }
- virtual void pecati() {
- cout<<indeks;
- }
- };
- class Predavach {
- private:
- Kurs kursevi[10];
- int brojKursevi;
- protected:
- char *imeIPrezime;
- public:
- Predavach() {
- imeIPrezime=new char[0];
- brojKursevi=0;
- }
- Predavach(char *imeIPrezime, Kurs *kursevi, int brojKursevi) {
- this->brojKursevi=brojKursevi;
- for (int i=0; i<brojKursevi; i++) this->kursevi[i]=kursevi[i];
- this->imeIPrezime=new char[strlen(imeIPrezime)+1];
- strcpy(this->imeIPrezime,imeIPrezime);
- }
- Predavach(const Predavach &p) {
- this->brojKursevi=p.brojKursevi;
- for (int i=0; i<p.brojKursevi; i++) this->kursevi[i]=p.kursevi[i];
- this->imeIPrezime=new char[strlen(p.imeIPrezime)+1];
- strcpy(this->imeIPrezime,p.imeIPrezime);
- }
- Predavach &operator=(const Predavach &p) {
- if (this==&p) return *this;
- this->brojKursevi=p.brojKursevi;
- for (int i=0; i<p.brojKursevi; i++) this->kursevi[i]=p.kursevi[i];
- this->imeIPrezime=new char[strlen(p.imeIPrezime)+1];
- delete [] imeIPrezime;
- strcpy(this->imeIPrezime,p.imeIPrezime);
- return *this;
- }
- virtual ~Predavach() {
- delete [] imeIPrezime;
- }
- int getBrojKursevi()const {
- return brojKursevi;
- }
- char * const getImeIPrezime()const {
- return imeIPrezime;
- }
- Kurs operator[](int i) const {
- if (i<brojKursevi&&i>=0)
- return kursevi[i];
- else return Kurs();
- }
- Kurs* getKurs() {
- return kursevi;
- }
- virtual void pecati() const {
- cout<<imeIPrezime<<" (";
- for (int i=0; i<brojKursevi; i++) {
- kursevi[i].pecati();
- if (i<brojKursevi-1) cout<<", ";
- else cout<<")";
- }
- }
- };
- class Demonstrator: public Student, public Predavach {
- private:
- int brojChasovi;
- public:
- Demonstrator() {}
- Demonstrator(int indeks,int *ocenki, int brojOcenki, char *imeIPrezime, Kurs *kursevi, int brojKursevi, int brojCasovi): Student(indeks, ocenki, brojOcenki),
- Predavach(imeIPrezime, kursevi, brojKursevi) {
- this->brojChasovi=brojCasovi;
- }
- Demonstrator& operator = (const Demonstrator &d) {
- (Student&)(*this)=d;
- (Predavach&)(*this)=d;
- brojChasovi=d.brojChasovi;
- return *this;
- }
- virtual int getBodovi() {
- return Student::getBodovi()+20.0*brojChasovi/getBrojKursevi();
- }
- virtual void pecati() {
- int i;
- Student::pecati();
- cout<<": "<<imeIPrezime<<" (";
- for(i=0; i<Predavach::getBrojKursevi()-1; i++) {
- getKurs()[i].pecati();
- cout<<", ";
- }
- getKurs()[i].pecati();
- cout<<")";
- }
- int getBrojChasovi() {
- return brojChasovi;
- }
- virtual ~Demonstrator() {}
- };
- //mesto za vashiot kod
- Student& vratiNajdobroRangiran(Student ** studenti, int n ) {
- int maxbodovi=0;
- Student *temp1;
- for(int i=0; i<n; i++) {
- if(maxbodovi<studenti[i]->getBodovi()) {
- maxbodovi=studenti[i]->getBodovi();
- temp1=studenti[i];
- }
- }
- return *temp1;
- }
- void pecatiDemonstratoriKurs (char* kurs, Student** studenti, int n) {
- for(int i=0; i<n; i++) {
- Predavach *temp=dynamic_cast<Predavach*>(studenti[i]);
- for(int j=0; j<10; j++)
- {
- if(temp->getKurs()[j]==kurs)
- {
- Demonstrator *temp1=dynamic_cast<Demonstrator*>(studenti[i]);
- temp1->pecati();
- cout<<endl;
- }
- }
- }
- }
- int main() {
- Kurs kursevi[10];
- int indeks,brojKursevi, ocenki[20],ocenka,brojOcenki,tip,brojCasovi,krediti;
- char ime[20],imeIPrezime[50];
- cin>>tip;
- if (tip==1) { //test class Demonstrator
- cout<<"-----TEST Demonstrator-----"<<endl;
- cin>>indeks>>brojOcenki;
- for (int i=0; i<brojOcenki; i++) {
- cin>>ocenka;
- ocenki[i]=ocenka;
- }
- cin>>imeIPrezime>>brojKursevi;
- for (int i=0; i<brojKursevi; i++) {
- cin>>ime>>krediti;
- kursevi[i]=Kurs(ime,krediti);
- }
- cin>>brojCasovi;
- try {
- Demonstrator d(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
- } catch (NoCourseException n) {
- n.message();
- }
- cout<<"Objekt od klasata Demonstrator e kreiran";
- } else if (tip==2) { //funkcija pecati vo Student
- cout<<"-----TEST pecati-----"<<endl;
- cin>>indeks>>brojOcenki;
- for (int i=0; i<brojOcenki; i++) {
- cin>>ocenka;
- ocenki[i]=ocenka;
- }
- Student s(indeks,ocenki,brojOcenki);
- s.pecati();
- } else if (tip==3) { //funkcija getVkupnaOcenka vo Student
- cout<<"-----TEST getVkupnaOcenka-----"<<endl;
- cin>>indeks>>brojOcenki;
- for (int i=0; i<brojOcenki; i++) {
- cin>>ocenka;
- ocenki[i]=ocenka;
- }
- Student s(indeks,ocenki,brojOcenki);
- cout<<"Broj na bodovi: "<<s.getBodovi()<<endl;
- } else if (tip==4) { //funkcija getVkupnaOcenka vo Demonstrator
- cout<<"-----TEST getVkupnaOcenka-----"<<endl;
- cin>>indeks>>brojOcenki;
- for (int i=0; i<brojOcenki; i++) {
- cin>>ocenka;
- ocenki[i]=ocenka;
- }
- cin>>imeIPrezime>>brojKursevi;
- for (int i=0; i<brojKursevi; i++) {
- cin>>ime>>krediti;
- kursevi[i]=Kurs(ime,krediti);
- }
- cin>>brojCasovi;
- Demonstrator d(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
- try {
- cout<<"Broj na bodovi: "<<d.getBodovi()<<endl;
- } catch(NoCourseException n) {
- n.message();
- }
- } else if (tip==5) { //funkcija pecati vo Demonstrator
- cout<<"-----TEST pecati -----"<<endl;
- cin>>indeks>>brojOcenki;
- for (int i=0; i<brojOcenki; i++) {
- cin>>ocenka;
- ocenki[i]=ocenka;
- }
- cin>>imeIPrezime>>brojKursevi;
- for (int i=0; i<brojKursevi; i++) {
- cin>>ime>>krediti;
- kursevi[i]=Kurs(ime,krediti);
- }
- cin>>brojCasovi;
- Demonstrator d(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
- d.pecati();
- } else if (tip==6) { //site klasi
- cout<<"-----TEST Student i Demonstrator-----"<<endl;
- cin>>indeks>>brojOcenki;
- for (int i=0; i<brojOcenki; i++) {
- cin>>ocenka;
- ocenki[i]=ocenka;
- }
- cin>>imeIPrezime>>brojKursevi;
- for (int i=0; i<brojKursevi; i++) {
- cin>>ime>>krediti;
- kursevi[i]=Kurs(ime,krediti);
- }
- cin>>brojCasovi;
- Student *s=new Demonstrator(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
- s->pecati();
- try {
- cout<<"\nBroj na bodovi: "<<s->getBodovi()<<endl;
- } catch(NoCourseException n) {
- n.message();
- }
- delete s;
- } else if (tip==7) { //funkcija vratiNajdobroRangiran
- cout<<"-----TEST vratiNajdobroRangiran-----"<<endl;
- int k, opt;
- cin>>k;
- Student **studenti=new Student*[k];
- for (int j=0; j<k; j++) {
- cin>>opt; //1 Student 2 Demonstrator
- cin>>indeks>>brojOcenki;
- for (int i=0; i<brojOcenki; i++) {
- cin>>ocenka;
- ocenki[i]=ocenka;
- }
- if (opt==1) {
- studenti[j]=new Student(indeks,ocenki,brojOcenki);
- } else {
- cin>>imeIPrezime>>brojKursevi;
- for (int i=0; i<brojKursevi; i++) {
- cin>>ime>>krediti;
- kursevi[i]=Kurs(ime,krediti);
- }
- try {
- cin>>brojCasovi;
- if(brojCasovi==0)
- throw NoCourseException(indeks);
- } catch(NoCourseException n) {
- n.message();
- }
- studenti[j]=new Demonstrator(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
- }
- }
- Student& najdobar=vratiNajdobroRangiran(studenti,k);
- try {
- cout<<"Maksimalniot broj na bodovi e:"<<najdobar.getBodovi();
- } catch (NoCourseException n) {
- n.message();
- }
- cout<<"\nNajdobro rangiran:";
- najdobar.pecati();
- for (int j=0; j<k; j++) delete studenti[j];
- delete [] studenti;
- } else if (tip==8) { //funkcija pecatiDemonstratoriKurs
- cout<<"-----TEST pecatiDemonstratoriKurs-----"<<endl;
- int k, opt;
- cin>>k;
- Student **studenti=new Student*[k];
- for (int j=0; j<k; j++) {
- cin>>opt; //1 Student 2 Demonstrator
- cin>>indeks>>brojOcenki;
- for (int i=0; i<brojOcenki; i++) {
- cin>>ocenka;
- ocenki[i]=ocenka;
- }
- if (opt==1) {
- studenti[j]=new Student(indeks,ocenki,brojOcenki);
- } else {
- cin>>imeIPrezime>>brojKursevi;
- for (int i=0; i<brojKursevi; i++) {
- cin>>ime>>krediti;
- kursevi[i]=Kurs(ime,krediti);
- }
- cin>>brojCasovi;
- studenti[j]=new Demonstrator(indeks,ocenki,brojOcenki,imeIPrezime,kursevi,brojKursevi,brojCasovi);
- }
- }
- char kurs[20];
- cin>>kurs;
- cout<<"Demonstratori na "<<kurs<<" se:"<<endl;
- pecatiDemonstratoriKurs (kurs,studenti,k);
- for (int j=0; j<k; j++) delete studenti[j];
- delete [] studenti;
- }
- return 0;
- }
- //3. Возач
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Vozac
- {
- protected:
- char ime[100];
- int vozrast;
- int brojTrki;
- bool veteran;
- public:
- Vozac() {}
- Vozac(char *i, int v, int br, bool vet)
- {
- strcpy(ime, i);
- vozrast=v;
- brojTrki=br;
- veteran=vet;
- }
- friend ostream &operator << (ostream &os, Vozac &v)
- {
- os<<v.ime<<endl<<v.vozrast<<endl<<v.brojTrki<<endl;
- if(v.veteran)
- os<<"VETERAN"<<endl;
- return os;
- }
- virtual double zarabotuvachka()=0;
- virtual double danok()=0;
- virtual ~Vozac(){}
- };
- bool operator == (Vozac &v1, Vozac *v2)
- {
- return v1.zarabotuvachka()==v2->zarabotuvachka();
- }
- class Avtomobilist: public Vozac
- {
- private:
- double cenaAvto;
- public:
- Avtomobilist():Vozac(){}
- Avtomobilist(char *i, int v, int br, bool vet, double c):Vozac(i, v, br, vet)
- {
- cenaAvto=c;
- }
- double zarabotuvachka()
- {
- return cenaAvto/5.0;
- }
- double danok()
- {
- if(brojTrki>10)
- return zarabotuvachka()*0.15;
- else
- return zarabotuvachka()*0.1;
- }
- };
- class Motociklist: public Vozac
- {
- private:
- int mokjnost;
- public:
- Motociklist():Vozac(){}
- Motociklist(char *i, int v, int br, bool vet, int m):Vozac(i, v, br, vet)
- {
- mokjnost=m;
- }
- double zarabotuvachka()
- {
- return mokjnost*20.0;
- }
- double danok()
- {
- if(veteran)
- return zarabotuvachka()*0.25;
- else
- return zarabotuvachka()*0.2;
- }
- };
- int soIstaZarabotuvachka(Vozac **v, int n, Vozac *voz)
- {
- int brojac=0;
- for(int i=0; i<n; i++)
- {
- if(*v[i]==voz)
- brojac++;
- }
- return brojac;
- }
- int main()
- {
- int n, x;
- cin >> n >> x;
- Vozac **v = new Vozac*[n];
- char ime[100];
- int vozrast;
- int trki;
- bool vet;
- for(int i = 0; i < n; ++i)
- {
- cin >> ime >> vozrast >> trki >> vet;
- if(i < x)
- {
- float cena_avto;
- cin >> cena_avto;
- v[i] = new Avtomobilist(ime, vozrast, trki, vet, cena_avto);
- }
- else
- {
- int mokjnost;
- cin >> mokjnost;
- v[i] = new Motociklist(ime, vozrast, trki, vet, mokjnost);
- }
- }
- cout << "=== DANOK ===" << endl;
- for(int i = 0; i < n; ++i)
- {
- cout << *v[i];
- cout << v[i]->danok() << endl;
- }
- cin >> ime >> vozrast >> trki >> vet;
- int mokjnost;
- cin >> mokjnost;
- Vozac *vx = new Motociklist(ime, vozrast, trki, vet, mokjnost);
- cout << "=== VOZAC X ===" << endl;
- cout << *vx;
- cout << "=== SO ISTA ZARABOTUVACKA KAKO VOZAC X ===" << endl;
- cout << soIstaZarabotuvachka(v, n, vx);
- for(int i = 0; i < n; ++i)
- {
- delete v[i];
- }
- delete [] v;
- delete vx;
- return 0;
- }
- //4. Картичка
- #include<iostream>
- #include<string.h>
- using namespace std;
- class OutOfBoundException {
- private:
- char text[100];
- public:
- OutOfBoundException(const char *t) {
- strcpy(text, t);
- }
- void message() {
- cout<<text<<endl;
- }
- };
- class Karticka {
- protected:
- char smetka[16];
- int pin;
- bool povekjePin;
- public:
- Karticka(){
- povekjePin=false;
- }
- Karticka(const char* smetka,int pin) {
- strcpy(this->smetka,smetka);
- this->pin=pin;
- this->povekjePin=false;
- }
- Karticka(const Karticka &k) {
- strcpy(this->smetka,k.smetka);
- this->pin=k.pin;
- this->povekjePin=k.povekjePin;
- }
- char *getSmetka() {
- return smetka;
- }
- virtual bool getDopolnitelenPin() {
- return false;
- }
- virtual int tezhinaProbivanje() {
- int brojac=0;
- int a=pin;
- while(a>0) {
- a/=10;
- brojac++;
- }
- return brojac;
- }
- virtual ~Karticka() {}
- };
- ostream &operator << (ostream &os, Karticka *k) {
- os<<k->getSmetka()<<": "<<k->tezhinaProbivanje();
- return os;
- }
- class SpecijalnaKarticka: public Karticka {
- private:
- int *pinovi;
- int broj;
- const int P;
- public:
- SpecijalnaKarticka():P(4)
- {
- broj=0;
- pinovi=new int[0];
- povekjePin=true;
- }
- SpecijalnaKarticka(const char* smetka, int pin):Karticka(smetka,pin), P(4) {
- broj=0;
- pinovi=new int[0];
- povekjePin=true;
- }
- SpecijalnaKarticka(const SpecijalnaKarticka &k):Karticka(k), P(4) {
- broj=k.broj;
- pinovi=new int[broj];
- for(int i=0; i<broj; i++)
- pinovi[i]=k.pinovi[i];
- }
- bool getDopolnitelenPin() {
- return true;
- }
- int tezhinaProbivanje() {
- return Karticka::tezhinaProbivanje()+broj;
- }
- SpecijalnaKarticka &operator += (int n) {
- try {
- if(broj+1>P)
- throw OutOfBoundException("Brojot na pin kodovi ne moze da go nadmine dozvolenoto");
- int *temp = new int [broj];
- for(int i=0; i<broj; i++)
- temp[i]=pinovi[i];
- delete [] pinovi;
- pinovi=new int[broj+1];
- for(int i=0; i<broj; i++)
- pinovi[i]=temp[i];
- pinovi[broj]=n;
- broj++;
- delete [] temp;
- } catch(OutOfBoundException n) {
- n.message();
- return *this;
- }
- return *this;
- }
- ~SpecijalnaKarticka() {
- delete [] pinovi;
- }
- };
- class Banka {
- private:
- char naziv[30];
- Karticka *karticki[20];
- int broj;
- static int LIMIT;
- public:
- Banka(const char *naziv, Karticka** karticki,int broj ) {
- strcpy(this->naziv,naziv);
- for (int i=0; i<broj; i++) {
- //ako kartickata ima dopolnitelni pin kodovi
- if (karticki[i]->getDopolnitelenPin()) {
- this->karticki[i]=new SpecijalnaKarticka(*dynamic_cast<SpecijalnaKarticka*>(karticki[i]));
- } else this->karticki[i]=new Karticka(*karticki[i]);
- }
- this->broj=broj;
- }
- static void setLIMIT(int n) {
- LIMIT=n;
- }
- void pecatiKarticki() {
- cout<<"Vo bankata "<<naziv<<" moze da se probijat kartickite:"<<endl;
- for(int i=0; i<broj; i++) {
- if(karticki[i]->tezhinaProbivanje()<=LIMIT)
- cout<<karticki[i]<<endl;
- }
- }
- void dodadiDopolnitelenPin(char * smetka, int novPin) {
- for(int i=0; i<broj; i++) {
- if(karticki[i]->getDopolnitelenPin()&&strcmp(karticki[i]->getSmetka(), smetka)==0)
- {
- SpecijalnaKarticka *temp=dynamic_cast<SpecijalnaKarticka*>(karticki[i]);
- *temp+=novPin;
- }
- }
- }
- ~Banka() {
- for (int i=0; i<broj; i++) delete karticki[i];
- }
- //да се дополни класата
- };
- int Banka::LIMIT=7;
- int main() {
- Karticka **niza;
- int n,m,pin;
- char smetka[16];
- bool daliDopolnitelniPin;
- cin>>n;
- niza=new Karticka*[n];
- for (int i=0; i<n; i++) {
- cin>>smetka;
- cin>>pin;
- cin>>daliDopolnitelniPin;
- if (!daliDopolnitelniPin)
- niza[i]=new Karticka(smetka,pin);
- else
- niza[i]=new SpecijalnaKarticka(smetka,pin);
- }
- Banka komercijalna("Komercijalna",niza,n);
- for (int i=0; i<n; i++) delete niza[i];
- delete [] niza;
- cin>>m;
- for (int i=0; i<m; i++) {
- cin>>smetka>>pin;
- komercijalna.dodadiDopolnitelenPin(smetka,pin);
- }
- Banka::setLIMIT(5);
- komercijalna.pecatiKarticki();
- }
- //5. Опера и балет
- #include<iostream>
- #include<string.h>
- using namespace std;
- class Delo
- {
- private:
- char ime[50];
- int godina;
- char zemjaPoteklo[50];
- public:
- Delo(){}
- Delo(char *i,int god,char *zemja)
- {
- strcpy(ime,i);
- godina=god;
- strcpy(zemjaPoteklo,zemja);
- }
- Delo(const Delo &d)
- {
- strcpy(ime,d.ime);
- godina=d.godina;
- strcpy(zemjaPoteklo,d.zemjaPoteklo);
- }
- Delo &operator=(const Delo &d)
- {
- strcpy(ime,d.ime);
- godina=d.godina;
- strcpy(zemjaPoteklo,d.zemjaPoteklo);
- return *this;
- }
- bool operator==(Delo &d)
- {
- if(strcmp(ime,d.ime)==0)
- {
- return true;
- }else
- {
- return false;
- }
- }
- int getGodina()
- {
- return godina;
- }
- char *getIme()
- {
- return ime;
- }
- char *getZemjaP()
- {
- return zemjaPoteklo;
- }
- };
- class Pretstava
- {
- protected:
- Delo d;
- int brojProdadeni;
- char dataPrikaz[15];
- public:
- Pretstava(Delo d1,int broj,char *dataP)
- {
- d=d1;
- brojProdadeni=broj;
- strcpy(dataPrikaz,dataP);
- }
- virtual double cena()
- {
- int M;
- int N;
- if(d.getGodina()>=1900)
- {
- M=50;
- }
- else if(d.getGodina()<1800)
- {
- M=100;
- }else
- {
- M=75;
- }
- if(strcmp(d.getZemjaP(),"Italija")==0)
- {
- N=100;
- }
- else if(strcmp(d.getZemjaP(),"Rusija")==0)
- {
- N=150;
- }
- else
- {
- N=80;
- }
- return N+M;
- }
- Delo getDelo()
- {
- return d;
- }
- int getProdadeni()
- {
- return brojProdadeni;
- }
- };
- class Balet: public Pretstava
- {
- private:
- static int cenaBalet;
- public:
- Balet(Delo d1,int broj,char *dataP):Pretstava(d1,broj,dataP){}
- static void setCenaBalet(int cena)
- {
- cenaBalet=cena;
- }
- double cena()
- {
- return cenaBalet+Pretstava::cena();
- }
- };
- int Balet::cenaBalet=150;
- class Opera:public Pretstava
- {
- public:
- Opera(Delo d1,int broj,char *dataP):Pretstava(d1,broj,dataP){}
- double cena()
- {
- return Pretstava::cena();
- }
- };
- double prihod(Pretstava **pretstavi,int broj)
- {
- double vkupenPrihod=0.0;
- for(int i=0;i<broj;i++)
- {
- vkupenPrihod=vkupenPrihod+pretstavi[i]->cena()*pretstavi[i]->getProdadeni();
- }
- return vkupenPrihod;
- }
- int brojPretstaviNaDelo(Pretstava **pretstavi,int broj,Delo &d2)
- {
- int brojac=0;
- for(int i=0;i<broj;i++)
- {
- if(pretstavi[i]->getDelo()==d2)
- {
- brojac++;
- }
- }
- return brojac;
- }
- //????? ?? ?????? ???
- //citanje na delo
- Delo readDelo(){
- char ime[50];
- int godina;
- char zemja[50];
- cin>>ime>>godina>>zemja;
- return Delo(ime,godina,zemja);
- }
- //citanje na pretstava
- Pretstava* readPretstava(){
- int tip; //0 za Balet , 1 za Opera
- cin>>tip;
- Delo d=readDelo();
- int brojProdadeni;
- char data[15];
- cin>>brojProdadeni>>data;
- if (tip==0) return new Balet(d,brojProdadeni,data);
- else return new Opera(d,brojProdadeni,data);
- }
- int main(){
- int test_case;
- cin>>test_case;
- switch(test_case){
- case 1:
- //Testiranje na klasite Opera i Balet
- {
- cout<<"======TEST CASE 1======="<<endl;
- Pretstava* p1=readPretstava();
- cout<<p1->getDelo().getIme()<<endl;
- Pretstava* p2=readPretstava();
- cout<<p2->getDelo().getIme()<<endl;
- }break;
- case 2:
- //Testiranje na klasite Opera i Balet so cena
- {
- cout<<"======TEST CASE 2======="<<endl;
- Pretstava* p1=readPretstava();
- cout<<p1->cena()<<endl;
- Pretstava* p2=readPretstava();
- cout<<p2->cena()<<endl;
- }break;
- case 3:
- //Testiranje na operator ==
- {
- cout<<"======TEST CASE 3======="<<endl;
- Delo f1=readDelo();
- Delo f2=readDelo();
- Delo f3=readDelo();
- if (f1==f2) cout<<"Isti se"<<endl; else cout<<"Ne se isti"<<endl;
- if (f1==f3) cout<<"Isti se"<<endl; else cout<<"Ne se isti"<<endl;
- }break;
- case 4:
- //testiranje na funkcijata prihod
- {
- cout<<"======TEST CASE 4======="<<endl;
- int n;
- cin>>n;
- Pretstava **pole=new Pretstava*[n];
- for (int i=0;i<n;i++){
- pole[i]=readPretstava();
- }
- cout<<prihod(pole,n);
- }break;
- case 5:
- //testiranje na prihod so izmena na cena za 3d proekcii
- {
- cout<<"======TEST CASE 5======="<<endl;
- int cenaBalet;
- cin>>cenaBalet;
- Balet::setCenaBalet(cenaBalet);
- int n;
- cin>>n;
- Pretstava **pole=new Pretstava*[n];
- for (int i=0;i<n;i++){
- pole[i]=readPretstava();
- }
- cout<<prihod(pole,n);
- }break;
- case 6:
- //testiranje na brojPretstaviNaDelo
- {
- cout<<"======TEST CASE 6======="<<endl;
- int n;
- cin>>n;
- Pretstava **pole=new Pretstava*[n];
- for (int i=0;i<n;i++){
- pole[i]=readPretstava();
- }
- Delo f=readDelo();
- cout<<brojPretstaviNaDelo(pole,n,f);
- }break;
- };
- return 0;
- }
- //6. Студент
- #include<iostream>
- #include<string.h>
- using namespace std;
- class BadInputException {
- private:
- char text[100];
- public:
- BadInputException(const char *t) {
- strcpy(text, t);
- }
- void message() {
- cout<<text<<endl;
- }
- };
- class StudentKurs {
- protected:
- char ime[30];
- int ocenka;
- bool daliUsno;
- static int MAX;
- const int MINOCENKA;
- public:
- StudentKurs(char* ime,int finalenIspit):MINOCENKA(6) {
- strcpy(this->ime,ime);
- this->ocenka=finalenIspit;
- this->daliUsno=false;
- }
- const int getMIN() const {
- return MINOCENKA;
- }
- static void setMAX(int m) {
- MAX=m;
- }
- virtual bool getDaliUsno() {
- return daliUsno;
- }
- int fOcenka() {
- return ocenka;
- }
- char *getIme() {
- return ime;
- }
- virtual ~StudentKurs() {}
- };
- int StudentKurs::MAX=10;
- ostream &operator << (ostream &os, StudentKurs *s) {
- os<<s->getIme()<<" --- "<<s->fOcenka();
- return os;
- }
- class StudentKursUsno: public StudentKurs {
- private:
- char *opisnaOcenka;
- public:
- StudentKursUsno(char *ime, int finalenIspit):StudentKurs(ime, finalenIspit) {
- daliUsno=true;
- }
- bool getDaliUsno() {
- return daliUsno;
- }
- StudentKursUsno& operator +=(char *oC) {
- try {
- for(int i=0; i<(int)strlen(oC); i++) {
- if(!isalpha(oC[i]))
- throw BadInputException("Greshna opisna ocenka");
- }
- } catch(BadInputException n) {
- n.message();
- char temp[100];
- int j=0;
- for(int i=0; i<(int)strlen(oC); i++) {
- if(isalpha(oC[i]))
- temp[j++]=oC[i];
- }
- temp[j]=0;
- if(strcmp(temp, "odlicen")==0&&ocenka<8) {
- ocenka+=2;
- } else if(strcmp(temp, "dobro")==0&&ocenka<9) {
- ocenka+=1;
- } else if(strcmp(temp, "losho")==0&&ocenka>1) {
- ocenka-=1;
- }
- opisnaOcenka=new char[strlen(temp)+1];
- strcpy(opisnaOcenka, temp);
- return *this;
- }
- opisnaOcenka=new char[strlen(oC)+1];
- strcpy(opisnaOcenka, oC);
- if(strcmp(oC, "odlicen")==0&&ocenka<8) {
- ocenka+=2;
- } else if(strcmp(oC, "dobro")==0&&ocenka<9) {
- ocenka+=1;
- } else if(strcmp(oC, "losho")==0&&ocenka>1) {
- ocenka-=1;
- }
- return *this;
- }
- ~StudentKursUsno() {}
- };
- class KursFakultet {
- private:
- char naziv[30];
- StudentKurs *studenti[20];
- int broj;
- public:
- KursFakultet(const char *naziv, StudentKurs** studenti,int broj ) {
- strcpy(this->naziv,naziv);
- for (int i=0; i<broj; i++) {
- //ako studentot ima usno isprashuvanje
- if (studenti[i]->getDaliUsno()) {
- this->studenti[i]=new StudentKursUsno(*dynamic_cast<StudentKursUsno*>(studenti[i]));
- } else
- this->studenti[i]=new StudentKurs(*studenti[i]);
- }
- this->broj=broj;
- }
- void pecatiStudenti() {
- cout<<"Kursot "<<naziv<<" go polozile:"<<endl;
- for(int i=0; i<broj; i++) {
- if(studenti[i]->fOcenka()>=studenti[i]->getMIN())
- cout<<studenti[i]<<endl;
- }
- }
- void postaviOpisnaOcenka(char * ime, char* opisnaOcenka) {
- for(int i=0; i<broj; i++) {
- StudentKursUsno *temp=dynamic_cast<StudentKursUsno*>(studenti[i]);
- if(temp!=0) {
- if(strcmp(temp->getIme(),ime)==0) {
- *temp+=opisnaOcenka;
- }
- }
- }
- }
- ~KursFakultet() {
- for (int i=0; i<broj; i++)
- delete studenti[i];
- }
- };
- int main() {
- StudentKurs **niza;
- int n,m,ocenka;
- char ime[30],opisna[10];
- bool daliUsno;
- cin>>n;
- niza=new StudentKurs*[n];
- for (int i=0; i<n; i++) {
- cin>>ime;
- cin>>ocenka;
- cin>>daliUsno;
- if (!daliUsno)
- niza[i]=new StudentKurs(ime,ocenka);
- else
- niza[i]=new StudentKursUsno(ime,ocenka);
- }
- KursFakultet programiranje("OOP",niza,n);
- for (int i=0; i<n; i++)
- delete niza[i];
- delete [] niza;
- cin>>m;
- for (int i=0; i<m; i++) {
- cin>>ime>>opisna;
- programiranje.postaviOpisnaOcenka(ime,opisna);
- }
- StudentKurs::setMAX(9);
- programiranje.pecatiStudenti();
- }
- //7. Паркинг
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Avtomobil
- {
- private:
- char color[50];
- char model[50];
- char brand [50];
- public:
- Avtomobil(){}
- Avtomobil(const char *boja, const char *brend, const char *m)
- {
- strcpy(color, boja);
- strcpy(brand, brend);
- strcpy(model, m);
- }
- Avtomobil(const Avtomobil &a)
- {
- strcpy(color, a.color);
- strcpy(brand, a.brand);
- strcpy(model, a.model);
- }
- Avtomobil &operator = (const Avtomobil &a)
- {
- strcpy(color, a.color);
- strcpy(brand, a.brand);
- strcpy(model, a.model);
- return *this;
- }
- void print()
- {
- cout<<color<<" "<<brand<<" "<<model<<endl;
- }
- };
- class ParkingPlac
- {
- private:
- char adresa[20];
- char *ID;
- int cena;
- int zarabotka;
- int brojVozila;
- Avtomobil *avtomobili;
- public:
- ParkingPlac()
- {
- ID=new char[0];
- cena=0;
- avtomobili=new Avtomobil[0];
- brojVozila=0;
- zarabotka=0;
- }
- ParkingPlac(const char *addr, const char *id, int c)
- {
- ID=new char[strlen(id)+1];
- strcpy(ID, id);
- strcpy(adresa, addr);
- cena=c;
- avtomobili=new Avtomobil[0];
- brojVozila=0;
- zarabotka=0;
- }
- ParkingPlac (const ParkingPlac &p)
- {
- ID=new char[strlen(p.ID)+1];
- strcpy(ID, p.ID);
- strcpy(adresa, p.adresa);
- cena=p.cena;
- avtomobili=new Avtomobil[p.brojVozila];
- brojVozila=p.brojVozila;
- for(int i=0; i<brojVozila; i++)
- {
- avtomobili[i]=p.avtomobili[i];
- }
- zarabotka=p.zarabotka;
- }
- ParkingPlac &operator = (const ParkingPlac &p)
- {
- delete [] ID;
- ID=new char[strlen(p.ID)+1];
- strcpy(ID, p.ID);
- strcpy(adresa, p.adresa);
- cena=p.cena;
- delete [] avtomobili;
- avtomobili=new Avtomobil[p.brojVozila];
- brojVozila=p.brojVozila;
- for(int i=0; i<brojVozila; i++)
- {
- avtomobili[i]=p.avtomobili[i];
- }
- zarabotka=p.zarabotka;
- return *this;
- }
- void parkirajVozilo(Avtomobil novoVozilo)
- {
- Avtomobil *temp=new Avtomobil[brojVozila];
- for(int i=0; i<brojVozila; i++)
- {
- temp[i]=avtomobili[i];
- }
- delete [] avtomobili;
- avtomobili=new Avtomobil[brojVozila+1];
- for(int i=0; i<brojVozila; i++)
- {
- avtomobili[i]=temp[i];
- }
- avtomobili[brojVozila++]=novoVozilo;
- delete [] temp;
- }
- char* getId()
- {
- return ID;
- }
- void pecati()
- {
- if(zarabotka!=0)
- cout<<ID<<" "<<adresa<<" - "<<zarabotka<<" denari"<<endl;
- else
- cout<<ID<<" "<<adresa<<" "<<endl;
- }
- void pecatiParkiraniVozila()
- {
- cout<<"Vo parkingot se parkirani slednite vozila: "<<endl;
- for(int i=0; i<brojVozila; i++)
- {
- cout<<i+1<<".";
- avtomobili[i].print();
- }
- }
- void platiCasovi(int casovi)
- {
- zarabotka+=casovi*cena;
- }
- bool daliIstaAdresa(ParkingPlac p)
- {
- return(strcmp(adresa, p.adresa)==0);
- }
- ~ParkingPlac()
- {
- delete [] ID;
- delete [] avtomobili;
- }
- };
- int main(){
- ParkingPlac p[100];
- int n,m;
- char adresa[50],id[50];
- int brojcasovi,cenacas;
- cin>>n;
- if(n > 0){
- for (int i=0;i<n;i++){
- cin.get();
- cin.getline(adresa,50);
- cin>>id>>cenacas;
- ParkingPlac edna(adresa,id,cenacas);
- //povik na operatorot =
- p[i]=edna;
- }
- //plakjanje
- cin>>m;
- for (int i=0;i<m;i++){
- cin>>id>>brojcasovi;
- int findId=false;
- for (int j=0;j<m;j++){
- if (strcmp(p[j].getId(),id)==0){
- p[j].platiCasovi(brojcasovi);
- findId=true;
- }
- }
- if (!findId)
- cout<<"Ne e platen parking. Greshen ID."<<endl;
- }
- cout<<"========="<<endl;
- ParkingPlac pCentar("Cvetan Dimov","C10",80);
- for (int i=0;i<n;i++)
- if (p[i].daliIstaAdresa(pCentar))
- p[i].pecati();
- } else {
- ParkingPlac najdobarPlac("Mars", "1337", 1);
- int brVozila;
- cin >> brVozila;
- for(int i = 0; i < brVozila; ++i){
- char boja[20];
- char brend[20];
- char model[20];
- cin >> boja >> brend >> model;
- Avtomobil novAvtomobil(boja, brend, model);
- najdobarPlac.parkirajVozilo(novAvtomobil);
- }
- if(brVozila != 0)
- najdobarPlac.pecatiParkiraniVozila();
- }
- }
- //8. DVD
- #include<iostream>
- #include<cstring>
- using namespace std;
- enum zanr {
- akcija, komedija, drama
- };
- class Film {
- private:
- char * ime;
- int memorija;
- zanr zanrFilm;
- void copy(const Film &f){
- this->ime = new char [strlen(f.ime)+1];
- strcpy(this->ime,f.ime);
- this->memorija=f.memorija;
- this->zanrFilm=f.zanrFilm;
- }
- public:
- Film(char * ime = "", int memorija=0, zanr zanrFilm = akcija){
- this->ime = new char [strlen(ime)+1];
- strcpy(this->ime,ime);
- this->memorija=memorija;
- this->zanrFilm=zanrFilm;
- }
- Film(const Film &f){
- copy(f);
- }
- ~Film() {
- delete ime;
- }
- Film &operator = (const Film &f){
- if (this!=&f){
- delete ime;
- copy(f);
- }
- return *this;
- }
- void pecati() {
- cout<<memorija<<"MB-"<<"\""<<ime<<"\""<<endl;
- }
- int getMemorija() {
- return memorija;
- }
- zanr getZhanr() {
- return zanrFilm;
- }
- };
- class DVD {
- private:
- Film filmovi[5];
- int broj;
- int kapacitet;
- int momentalno;
- public:
- DVD(int kapacitet){
- this->kapacitet=kapacitet;
- broj=0;
- momentalno=0;
- }
- void dodadiFilm(Film f) {
- if (momentalno+f.getMemorija()<=kapacitet&&broj<5){
- filmovi[broj++]=f;
- momentalno+=f.getMemorija();
- }
- }
- void pecatiFilmoviDrugZanr(const zanr r){
- for (int i=0;i<broj;i++){
- // cout<<filmovi[i].pecati()<<" "<<r<<" "<<
- if (filmovi[i].getZhanr()!=r)
- filmovi[i].pecati();
- }
- }
- int getBroj() {
- return broj;
- }
- Film getFilm (int i){
- return filmovi[i];
- }
- float procentNaMemorijaOdZanr(zanr r){
- float sum = 0.0;
- for (int i=0;i<broj;i++)
- if (filmovi[i].getZhanr()==r)
- sum+=filmovi[i].getMemorija();
- return sum / momentalno * 100.0;
- }
- };
- int main() {
- // se testira zadacata modularno
- int testCase;
- cin >> testCase;
- int n, memorija, kojzanr;
- char ime[50];
- if (testCase == 1) {
- cout << "===== Testiranje na klasata Film ======" << endl;
- cin >> ime;
- cin >> memorija;
- cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
- Film f(ime, memorija, (zanr) kojzanr);
- f.pecati();
- } else if (testCase == 2) {
- cout << "===== Testiranje na klasata DVD ======" << endl;
- DVD omileno(50);
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> ime;
- cin >> memorija;
- cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
- Film f(ime, memorija, (zanr) kojzanr);
- omileno.dodadiFilm(f);
- }
- for (int i = 0; i < n; i++)
- (omileno.getFilm(i)).pecati();
- } else if (testCase == 3) {
- cout << "===== Testiranje na metodot dodadiFilm() od klasata DVD ======" << endl;
- DVD omileno(50);
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> ime;
- cin >> memorija;
- cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
- Film f(ime, memorija, (zanr) kojzanr);
- omileno.dodadiFilm(f);
- }
- for (int i = 0; i < omileno.getBroj(); i++)
- (omileno.getFilm(i)).pecati();
- } else if (testCase == 4) {
- cout << "===== Testiranje na metodot pecatiFilmoviDrugZanr() od klasata DVD ======" << endl;
- DVD omileno(50);
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> ime;
- cin >> memorija;
- cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
- Film f(ime, memorija, (zanr) kojzanr);
- omileno.dodadiFilm(f);
- }
- cin >> kojzanr;
- omileno.pecatiFilmoviDrugZanr((zanr) kojzanr);
- } else if (testCase == 5) {
- cout << "===== Testiranje na metodot pecatiFilmoviDrugZanr() od klasata DVD ======" << endl;
- DVD omileno(50);
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> ime;
- cin >> memorija;
- cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
- Film f(ime, memorija, (zanr) kojzanr);
- omileno.dodadiFilm(f);
- }
- cin >> kojzanr;
- omileno.pecatiFilmoviDrugZanr((zanr) kojzanr);
- } else if (testCase == 6){
- cout<<"===== Testirawe na metodot procentNaMemorijaOdZanr() od klasata DVD =====" <<endl;
- DVD omileno(40);
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> ime;
- cin >> memorija;
- cin >> kojzanr; //se vnesuva 0 za AKCIJA,1 za KOMEDIJA i 2 za DRAMA
- Film f(ime, memorija, (zanr) kojzanr);
- omileno.dodadiFilm(f);
- }
- cin >> kojzanr;
- cout<<"Procent na filmovi od dadeniot zanr iznesuva: "<<omileno.procentNaMemorijaOdZanr((zanr) kojzanr)<<"%\n";
- }
- return 0;
- }
- //9. Репозиториум на оперативни системи
- #include <iostream>
- #include <cstring>
- using namespace std;
- enum tip{LINUX, UNIX, WINDOWS};
- class OperativenSistem
- {
- char *ime;
- float verzija;
- tip t;
- float golemina;
- public:
- OperativenSistem()
- {
- ime=new char[0];
- }
- OperativenSistem(char *i, float v, tip t1, float g)
- {
- ime=new char[strlen(i)+1];
- strcpy(ime,i);
- verzija=v;
- t=t1;
- golemina=g;
- }
- OperativenSistem(const OperativenSistem &o)
- {
- ime=new char[strlen(o.ime)+1];
- strcpy(ime,o.ime);
- verzija=o.verzija;
- t=o.t;
- golemina=o.golemina;
- }
- OperativenSistem& operator = (const OperativenSistem &o)
- {
- delete [] ime;
- ime=new char[strlen(o.ime)+1];
- strcpy(ime,o.ime);
- verzija=o.verzija;
- t=o.t;
- golemina=o.golemina;
- return *this;
- }
- void pecati()
- {
- cout<<"Ime: "<<ime<< " Verzija: "<<verzija<< " Tip: "<<t<< " Golemina:"<<golemina<<"GB"<<endl;
- }
- bool ednakviSe (const OperativenSistem &os)
- {
- return (strcmp(ime, os.ime)==0&&verzija==os.verzija&&t==os.t && golemina==os.golemina);
- }
- int sporediVerzija(const OperativenSistem &os)
- {
- if(verzija==os.verzija)
- return 0;
- else if(verzija<os.verzija)
- return -1;
- else return 1;
- }
- bool istaFamilija(const OperativenSistem &sporedba)
- {
- return (strcmp(ime, sporedba.ime)==0 && t==sporedba.t);
- }
- ~OperativenSistem()
- {
- delete[]ime;
- }
- };
- class Repozitorium
- {
- char ime[20];
- OperativenSistem *os;
- int broj;
- public:
- Repozitorium(const char *ime)
- {
- strcpy(this->ime, ime);
- os=new OperativenSistem[0];
- broj=0;
- }
- Repozitorium(const Repozitorium &r)
- {
- strcpy(ime, r.ime);
- os=new OperativenSistem[r.broj];
- for(int i=0; i<r.broj; i++)
- {
- os[i]=r.os[i];
- }
- broj=r.broj;
- }
- void pecatiOperativniSistemi()
- {
- cout<<"Repozitorium: "<<ime<<endl;
- for(int i=0; i<broj; i++)
- {
- os[i].pecati();
- }
- }
- void izbrishi(const OperativenSistem &operativenSistem)
- {
- OperativenSistem *temp=new OperativenSistem[broj];
- int j=0;
- for(int i=0; i<broj; i++)
- {
- if(!os[i].ednakviSe(operativenSistem))
- {
- temp[j]=os[i];
- j++;
- }
- }
- delete [] os;
- os=new OperativenSistem[j];
- for(int i=0; i<j; i++)
- {
- os[i]=temp[i];
- }
- broj=j;
- delete [] temp;
- }
- void dodadi(const OperativenSistem &nov)
- {
- bool flag = true;
- for(int i=0; i<broj; i++)
- {
- if(os[i].istaFamilija(nov) && os[i].sporediVerzija(nov)==-1)
- {
- os[i]=nov;
- flag=false;
- }
- }
- if(flag)
- {
- OperativenSistem *temp=new OperativenSistem[broj];
- for(int i=0; i<broj; i++)
- {
- temp[i]=os[i];
- }
- delete [] os;
- os=new OperativenSistem[broj+1];
- for(int i=0; i<broj; i++)
- {
- os[i]=temp[i];
- }
- os[broj]=nov;
- broj++;
- delete [] temp;
- }
- }
- ~Repozitorium()
- {
- delete [] os;
- }
- };
- int main() {
- char repoName[20];
- cin>>repoName;
- Repozitorium repozitorium=Repozitorium(repoName);
- int brojOperativniSistemi = 0;
- cin>>brojOperativniSistemi;
- char ime[20];
- float verzija;
- int t;
- float golemina;
- for (int i = 0; i<brojOperativniSistemi; i++){
- cin>>ime;
- cin>>verzija;
- cin>>t;
- cin>>golemina;
- OperativenSistem os = OperativenSistem(ime, verzija, (tip)t, golemina);
- repozitorium.dodadi(os);
- }
- repozitorium.pecatiOperativniSistemi();
- cin>>ime;
- cin>>verzija;
- cin>>t;
- cin>>golemina;
- OperativenSistem os = OperativenSistem(ime, verzija, (tip)t, golemina);
- cout<<"=====Brishenje na operativen sistem====="<<endl;
- repozitorium.izbrishi(os);
- repozitorium.pecatiOperativniSistemi();
- return 0;
- }
- //10. ListContainer
- #include<iostream>
- using namespace std;
- class List {
- private:
- int * numbers;
- int numNumbers;
- void copy(const List& l) {
- numNumbers = l.numNumbers;
- numbers = new int[numNumbers];
- for (int i = 0; i < numNumbers; ++i) {
- numbers[i] = l.numbers[i];
- }
- }
- public:
- List() {
- numbers = new int[0];
- numNumbers = 0;
- }
- List(int * lista, int broj) {
- numNumbers = broj;
- numbers = new int[numNumbers];
- for (int i = 0; i < numNumbers; ++i) {
- numbers[i] = lista[i];
- }
- }
- ~List() {
- delete [] numbers;
- }
- List(const List& l) {
- copy(l);
- }
- List & operator = (const List& l) {
- if (this != &l) {
- delete [] numbers;
- copy(l);
- }
- return *this;
- }
- int sum() {
- int suma = 0;
- for (int i=0; i < numNumbers; ++i) {
- suma += numbers[i];
- }
- return suma;
- }
- double average() {
- return sum() * 1.0 / numNumbers;
- }
- void pecati() {
- cout << numNumbers << ": ";
- for (int i=0; i < numNumbers; ++i) {
- cout << numbers[i] << " ";
- }
- cout << "sum: " << sum();
- cout << " average: " << average();
- }
- int getNumber() {
- return numNumbers;
- }
- };
- class ListContainer {
- private:
- List * listi;
- int numListi;
- int attempts;
- void copy(const ListContainer &lc) {
- numListi = lc.numListi;
- attempts = lc.attempts;
- listi = new List[numListi];
- for (int i=0; i < numListi; ++i) {
- listi[i] = lc.listi[i];
- }
- }
- public:
- ListContainer() {
- listi = new List[0];
- numListi = 0;
- attempts = 0;
- }
- ~ListContainer() {
- delete [] listi;
- }
- ListContainer(const ListContainer &lc) {
- copy(lc);
- }
- ListContainer & operator =(const ListContainer &lc) {
- if (this != &lc) {
- delete [] listi;
- copy(lc);
- }
- return *this;
- }
- int sum() {
- int suma = 0;
- for (int i=0; i < numListi; ++i){
- suma += listi[i].sum();
- }
- return suma;
- }
- double average() {
- int suma = sum();
- int numElements = 0;
- for (int i=0; i < numListi; ++i) {
- numElements += listi[i].getNumber();
- }
- return suma / (numElements * 1.0);
- }
- void addNewList(List l){
- ++attempts;
- for (int i=0; i < numListi; ++i) {
- if (l.sum() == listi[i].sum()){
- return;
- }
- }
- List * tmp = new List[numListi + 1];
- for (int i=0; i < numListi; ++i) {
- tmp[i] = listi[i];
- }
- tmp[numListi++] = l;
- delete [] listi;
- listi = tmp;
- }
- void print() {
- if (!numListi) {
- cout << "The list is empty\n";
- return;
- }
- else {
- for (int i = 0; i < numListi; ++i) {
- cout << "List number: " << i + 1 << " List info: ";
- listi[i].pecati();
- cout << endl;
- }
- }
- cout << "Sum: " << sum();
- cout << " Average: " << average() << endl;
- cout << "Successful attempts: " << numListi << " Failed attempts: " << attempts - numListi<< endl;
- }
- };
- int main() {
- ListContainer lc;
- int N;
- cin>>N;
- for (int i=0;i<N;i++) {
- int n;
- int niza[100];
- cin>>n;
- for (int j=0;j<n;j++){
- cin>>niza[j];
- }
- List l=List(niza,n);
- lc.addNewList(l);
- }
- int testCase;
- cin>>testCase;
- if (testCase==1) {
- cout<<"Test case for operator ="<<endl;
- ListContainer lc1;
- lc1.print();
- cout<<lc1.sum()<<" "<<lc.sum()<<endl;
- lc1=lc;
- lc1.print();
- cout<<lc1.sum()<<" "<<lc.sum()<<endl;
- }
- else {
- lc.print();
- }
- }
- //11. Жичани инструменти
- #include<iostream>
- #include<cstring>
- using namespace std;
- class ZicanInstrument
- {
- protected:
- char ime[20];
- int zhici;
- int price;
- public:
- ZicanInstrument(){}
- ZicanInstrument(char *i, int z, int c)
- {
- strcpy(ime, i);
- zhici=z;
- price=c;
- }
- ZicanInstrument(ZicanInstrument *z)
- {
- strcpy(ime, z->ime);
- zhici=z->zhici;
- price=z->price;
- }
- int getZhici()
- {
- return zhici;
- }
- virtual double cena() = 0;
- virtual ~ZicanInstrument(){}
- };
- bool operator == (ZicanInstrument &z1, ZicanInstrument *z2)
- {
- return z1.getZhici()==z2->getZhici();
- }
- ostream &operator << (ostream &os, ZicanInstrument *z)
- {
- os<<z->cena();
- return os;
- }
- class Mandolina: public ZicanInstrument
- {
- private:
- char forma[20];
- public:
- Mandolina():ZicanInstrument(){}
- Mandolina(char *i, int z, int c, char *f):ZicanInstrument(i, z, c)
- {
- strcpy(forma, f);
- }
- Mandolina(Mandolina *p):ZicanInstrument(p)
- {
- strcpy(forma,p->forma);
- }
- double cena()
- {
- if(strcmp(forma,"Neapolitan")==0)
- return price+15*price/100.00;
- else return price;
- }
- };
- class Violina: public ZicanInstrument
- {
- private:
- double golemina;
- public:
- Violina():ZicanInstrument(){}
- Violina(char *i, int z, int c, double g):ZicanInstrument(i, z, c)
- {
- golemina=g;
- }
- Violina(Violina *v):ZicanInstrument(v)
- {
- golemina=v->golemina;
- }
- double cena()
- {
- if(golemina==0.25)
- return price+10*price/100.00;
- else if(golemina==1.00)
- return price+20*price/100.00;
- else
- return price;
- }
- };
- void pecatiInstrumenti(ZicanInstrument &zi, ZicanInstrument **i, int n)
- {
- for(int j=0; j<n; j++)
- {
- if(zi==i[j])
- {
- cout<<i[j]<<endl;
- }
- }
- }
- int main() {
- char ime[20];
- int brojZici;
- float cena;
- char forma[20];
- cin >> ime >> brojZici >> cena >> forma;
- Mandolina m(ime, brojZici, cena, forma);
- int n;
- cin >> n;
- ZicanInstrument **zi = new ZicanInstrument*[2 * n];
- for(int i = 0; i < n; ++i) {
- cin >> ime >> brojZici >> cena >> forma;
- zi[i] = new Mandolina(ime, brojZici, cena, forma);
- }
- for(int i = 0; i < n; ++i) {
- float golemina;
- cin >> ime >> brojZici >> cena >> golemina;
- zi[n + i] = new Violina(ime, brojZici, cena, golemina);
- }
- pecatiInstrumenti(m, zi, 2 * n);
- for(int i = 0; i < 2 * n; ++i) {
- delete zi[i];
- }
- delete [] zi;
- return 0;
- }
- //12. Игротека
- #include <iostream>
- #include<cstring>
- #include<cmath>
- using namespace std;
- class Igrachka
- {
- protected:
- char *boja;
- int gustina;
- public:
- Igrachka()
- {
- boja=new char[0];
- }
- Igrachka(char *b, int g)
- {
- boja=new char[strlen(b)+1];
- strcpy(boja, b);
- gustina=g;
- }
- virtual double getMasa()=0;
- virtual double getVolumen()=0;
- virtual double getPlostina()=0;
- virtual ~Igrachka()
- {
- delete [] boja;
- }
- };
- class Forma
- {
- public:
- virtual double getMasa()=0;
- virtual double getVolumen()=0;
- };
- class Topka: public Igrachka, public Forma
- {
- private:
- int radius;
- public:
- Topka(){}
- Topka(char *b, int g, int r):Igrachka(b, g),Forma()
- {
- radius=r;
- }
- double getVolumen()
- {
- return 4/3.0*radius*radius*radius*3.14;
- }
- double getMasa()
- {
- return gustina*getVolumen();
- }
- double getPlostina()
- {
- return 4*radius*radius*3.14;
- }
- };
- class Kocka: public Igrachka, public Forma
- {
- private:
- int a;
- int b;
- int c;
- public:
- Kocka(){}
- Kocka(char *b, int g, int aa, int bb, int cc):Igrachka(b, g),Forma()
- {
- a=aa;
- this->b=bb;
- c=cc;
- }
- double getVolumen()
- {
- return a*b*c;
- }
- double getMasa()
- {
- return gustina*getVolumen();
- }
- double getPlostina()
- {
- return 2*(a*b+a*c+b*c);
- }
- };
- int main()
- {
- int k,n,visina,shirina,dlabocina,radius,gustina;
- char boja[50];
- cin>>n;
- Igrachka **kupche=new Igrachka*[n];
- for(int i=0; i<n; i++)
- {
- cin>>k;
- if(k==1)
- {
- cin>>boja>>gustina>>radius;
- kupche[i]=new Topka(boja,gustina,radius);
- }
- if(k==2)
- {
- cin>>boja>>gustina>>visina>>shirina>>dlabocina;
- kupche[i]=new Kocka(boja,gustina,visina,shirina,dlabocina);
- }
- }
- cin>>boja>>gustina>>visina>>shirina>>dlabocina;
- Kocka Petra(boja,gustina,visina,shirina,dlabocina);
- float suma=0;
- for(int i=0; i<n; i++)
- {
- suma+=kupche[i]->getMasa();
- }
- if(suma>Petra.getMasa())
- cout<<"DA"<<endl;
- else
- cout<<"NE"<<endl;
- float max_volumen=0;
- float min_plostina=kupche[0]->getPlostina();
- for(int i=0; i<n; i++)
- {
- if(kupche[i]->getVolumen() > max_volumen)
- {
- max_volumen=kupche[i]->getVolumen();
- }
- if(kupche[i]->getPlostina() < min_plostina)
- {
- min_plostina=kupche[i]->getPlostina();
- }
- }
- cout<<"Razlikata e: "<<abs(max_volumen - Petra.getVolumen())<<endl;
- cout<<"Razlikata e: "<<abs(min_plostina - Petra.getPlostina())<<endl;
- }
- //13. Race
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Runner {
- char *ime;
- char drzhava[50];
- int vreme[2];
- int medali;
- public:
- Runner() {
- ime=new char[0];
- vreme[0]=vreme[1]=0;
- medali=0;
- }
- Runner(char *i, char *d, int m, int s, int med) {
- ime=new char[strlen(i)+1];
- strcpy(ime, i);
- strcpy(drzhava,d);
- vreme[0]=m;
- vreme[1]=s;
- medali=med;
- }
- Runner(const Runner &r) {
- ime=new char[strlen(r.ime)+1];
- strcpy(ime, r.ime);
- strcpy(drzhava,r.drzhava);
- vreme[0]=r.vreme[0];
- vreme[1]=r.vreme[1];
- medali=r.medali;
- }
- Runner& operator = (const Runner &r) {
- delete [] ime;
- ime=new char[strlen(r.ime)+1];
- strcpy(ime, r.ime);
- strcpy(drzhava,r.drzhava);
- vreme[0]=r.vreme[0];
- vreme[1]=r.vreme[1];
- medali=r.medali;
- return *this;
- }
- Runner &operator ++ () {
- ++medali;
- return *this;
- }
- bool operator != (Runner &r) {
- return(strcmp(drzhava, r.drzhava)!=0);
- }
- bool operator < (Runner &r) {
- if((vreme[0]*60+vreme[1])<(r.vreme[0]*60+r.vreme[1]))
- return true;
- else return false;
- }
- friend ostream& operator<<(ostream &os, Runner &r) {
- os<<r.ime<<" - "<<r.drzhava<<" - "<<r.vreme[0]<<":"<<r.vreme[1]<<" - "<<r.medali;
- return os;
- }
- ~Runner() {
- delete[]ime;
- }
- };
- class Race {
- char imeTrka[50];
- Runner *trkachi;
- int broj;
- public:
- Race(char *i) {
- strcpy(imeTrka,i);
- trkachi=new Runner[0];
- broj=0;
- }
- Race(const Race &r)
- {
- strcpy(imeTrka,r.imeTrka);
- trkachi=new Runner[r.broj];
- for(int i=0; i<r.broj; i++)
- {
- trkachi[i]=r.trkachi[i];
- }
- broj=r.broj;
- }
- Race &operator = (const Race &r)
- {
- delete [] trkachi;
- strcpy(imeTrka,r.imeTrka);
- trkachi=new Runner[r.broj];
- for(int i=0; i<r.broj; i++)
- {
- trkachi[i]=r.trkachi[i];
- }
- broj=r.broj;
- return *this;
- }
- Race &operator += (const Runner &r)
- {
- Runner *pom=new Runner[broj];
- for(int i=0; i<broj; i++)
- {
- pom[i]=trkachi[i];
- }
- delete [] trkachi;
- trkachi=new Runner[broj+1];
- for(int i=0; i<broj; i++)
- {
- trkachi[i]=pom[i];
- }
- delete [] pom;
- trkachi[broj]=r;
- broj++;
- return *this;
- }
- Race &operator -= (Runner &r)
- {
- int j=0;
- Runner *pom=new Runner[broj];
- for(int i=0; i<broj; i++)
- {
- if(trkachi[i]!=r)
- {
- pom[j]=trkachi[i];
- j++;
- }
- }
- delete [] trkachi;
- trkachi=new Runner[j];
- for(int i=0; i<j; i++)
- {
- trkachi[i]=pom[i];
- }
- delete [] pom;
- broj=j;
- return *this;
- }
- Race &operator ++ () {
- Runner pom=trkachi[0];
- int index=0;
- for(int i=1; i<broj; i++)
- {
- if(trkachi[i]<pom)
- {
- pom=trkachi[i];
- index=i;
- }
- }
- ++trkachi[index];
- return *this;
- }
- friend ostream& operator << (ostream &os, Race &r)
- {
- os<<r.imeTrka<<":"<<endl;
- for(int i=0; i<r.broj; i++)
- {
- os<<r.trkachi[i]<<endl;
- }
- return os;
- }
- ~Race() {
- delete[]trkachi;
- }
- };
- int main() {
- int n;
- cin >> n;
- char nameRace[50];
- cin >> nameRace;
- Race race = Race(nameRace);
- int m;
- cin >> m;
- char name[50];
- char country[50];
- int minutes;
- int seconds;
- int numberOfMedals;
- for (int i=0; i < m; ++i) {
- cin >> name;
- cin >> country;
- cin >> minutes;
- cin >> seconds;
- cin >> numberOfMedals;
- Runner r = Runner(name,country,minutes,seconds,numberOfMedals);
- race += r;
- }
- cout << race;
- if (n == 1) {
- ++race;
- cout << race;
- } else if (n == 2) {
- cin >> name;
- cin >> country;
- cin >> minutes;
- cin >> seconds;
- cin >> numberOfMedals;
- Runner r = Runner(name,country,minutes,seconds,numberOfMedals);
- race -= r;
- cout << race;
- } else if (n == 3) {
- cin >> name;
- cin >> country;
- cin >> minutes;
- cin >> seconds;
- cin >> numberOfMedals;
- Runner r = Runner(name,country,minutes,seconds,numberOfMedals);
- race -= r;
- ++race;
- cout << race;
- }
- }
- //14. SocialNetwork
- #include <iostream>
- #include <cstring>
- using namespace std;
- class InvalidPassword
- {
- private:
- char text[50];
- public:
- InvalidPassword(const char *txt)
- {
- strcpy(text, txt);
- }
- void message()
- {
- cout<<text<<endl;
- }
- };
- class InvalidEmail
- {
- private:
- char text[50];
- public:
- InvalidEmail(const char *txt)
- {
- strcpy(text, txt);
- }
- void message()
- {
- cout<<text<<endl;
- }
- };
- class MaximumSizeLimit
- {
- private:
- int broj;
- public:
- MaximumSizeLimit(int a)
- {
- broj=a;
- }
- void message()
- {
- cout<<"You can't add more than "<<broj<<" users."<<endl;
- }
- };
- bool proveriPass(char *p)
- {
- int brojac1=0, brojac2=0, brojac3=0;
- for(int i=0; i<(int)strlen(p); i++)
- {
- if(isupper(p[i]))
- brojac1++;
- if(islower(p[i]))
- brojac2++;
- if(isdigit(p[i]))
- brojac3++;
- }
- return brojac1>=1&&brojac2>=1&&brojac3>=1;
- }
- bool proveriMail(char *m)
- {
- int brojac1=0;
- for(int i=0; i<(int)strlen(m); i++)
- {
- if(m[i]=='@')
- brojac1++;
- }
- return brojac1==1;
- }
- class User
- {
- protected:
- char username[50];
- char password[50];
- char email[50];
- static double koefLike;
- static double koefComm;
- static double koefTwit;
- public:
- User(char *u, char *p, char *e)
- {
- if(proveriPass(p)==false)
- throw InvalidPassword("Password is too weak.");
- if(proveriMail(e)==false)
- throw InvalidEmail("Mail is not valid.");
- strcpy(username, u);
- strcpy(password, p);
- strcpy(email, e);
- }
- virtual double popularity()=0;
- virtual ~User() {}
- };
- double User::koefLike=0.1;
- double User::koefComm=0.5;
- double User::koefTwit=0.5;
- class FacebookUser: public User
- {
- private:
- int friends;
- int likes;
- int comments;
- public:
- FacebookUser(char *u,char *p,char *e,int f, int l, int c):User(u, p, e)
- {
- friends=f;
- likes=l;
- comments=c;
- }
- double popularity()
- {
- return friends+likes*koefLike+comments*koefComm;
- }
- };
- class TwitterUser: public User
- {
- private:
- int follower;
- int twits;
- public:
- TwitterUser(char *u,char *p,char *e,int f,int t):User(u,p,e)
- {
- follower=f;
- twits=t;
- }
- double popularity()
- {
- return follower+twits*koefTwit;
- }
- };
- class SocialNetwork
- {
- private:
- User **korisnici;
- int brojKorisnici;
- static int maxKorisnici;
- public:
- SocialNetwork()
- {
- korisnici=new User*[0];
- brojKorisnici=0;
- }
- SocialNetwork(const SocialNetwork &s)
- {
- korisnici=new User*[s.brojKorisnici];
- brojKorisnici=s.brojKorisnici;
- for(int i=0; i<brojKorisnici; i++)
- {
- korisnici[i]=s.korisnici[i];
- }
- }
- SocialNetwork &operator += (User *u)
- {
- if(brojKorisnici+1>maxKorisnici)
- throw MaximumSizeLimit(maxKorisnici);
- User **temp=new User*[brojKorisnici+1];
- for(int i=0; i<brojKorisnici; i++)
- {
- temp[i]=korisnici[i];
- }
- temp[brojKorisnici++]=u;
- delete [] korisnici; //proveri
- korisnici=new User*[brojKorisnici];
- korisnici=temp;
- return *this;
- }
- double avgPopularity()
- {
- double vk=0;
- for(int i=0; i<brojKorisnici; i++)
- {
- vk+=korisnici[i]->popularity();
- }
- return vk/brojKorisnici;
- }
- static void changeMaximumSize(int number)
- {
- maxKorisnici=number;
- }
- ~SocialNetwork()
- {
- for(int i=0; i<brojKorisnici; i++)
- {
- delete korisnici[i];
- }
- delete [] korisnici;
- }
- };
- int SocialNetwork::maxKorisnici=5;
- int main()
- {
- SocialNetwork network = SocialNetwork();
- int n;
- cin >> n;
- char username[50];
- char password[50];
- char email[50];
- int userType;
- for (int i=0; i < n; ++i)
- {
- cin >> username;
- cin >> password;
- cin >> email;
- cin >> userType;
- if (userType == 1)
- {
- int friends;
- int likes;
- int comments;
- cin >> friends >> likes >> comments;
- // TODO: Try-catch
- try
- {
- User * u = new FacebookUser(username,password,email,friends,likes,comments);
- try
- {
- network += u;
- }
- catch(MaximumSizeLimit ms)
- {
- ms.message();
- }
- }
- catch(InvalidPassword ip)
- {
- ip.message();
- }
- catch(InvalidEmail ie)
- {
- ie.message();
- }
- }
- else
- {
- int followers;
- int tweets;
- cin >> followers >> tweets;
- // TODO: Try-catch
- try
- {
- User * u= new TwitterUser(username,password,email,followers,tweets);
- try
- {
- network += u;
- }
- catch(MaximumSizeLimit ms)
- {
- ms.message();
- }
- }
- catch(InvalidPassword ip)
- {
- ip.message();
- }
- catch(InvalidEmail ie)
- {
- ie.message();
- }
- }
- }
- network.changeMaximumSize(6);
- cin >> username;
- cin >> password;
- cin >> email;
- int followers;
- int tweets;
- cin >> followers >> tweets;
- // TODO: Try-catch
- try
- {
- User * u= new TwitterUser(username,password,email,followers,tweets);
- try
- {
- network += u;
- }
- catch(MaximumSizeLimit ms)
- {
- ms.message();
- }
- }
- catch(InvalidPassword ip)
- {
- ip.message();
- }
- catch(InvalidEmail ie)
- {
- ie.message();
- }
- cout << network.avgPopularity();
- }
- //15. Колекција од парови
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Par {
- char *kluch;
- double vrednost;
- public:
- Par(const double v) {
- kluch=new char[0];
- vrednost=v;
- }
- Par(const char *k="", const double v=0) {
- kluch=new char[strlen(k)+1];
- strcpy(kluch,k);
- vrednost=v;
- }
- Par(const Par &p) {
- kluch=new char[strlen(p.kluch)+1];
- strcpy(kluch,p.kluch);
- vrednost=p.vrednost;
- }
- Par& operator = (const Par &p) {
- delete [] kluch;
- kluch=new char[strlen(p.kluch)+1];
- strcpy(kluch,p.kluch);
- vrednost=p.vrednost;
- return *this;
- }
- friend ostream &operator << (ostream &os, const Par &p) {
- os<<"("<<p.kluch<<", "<<p.vrednost<<")"<<endl;
- return os;
- }
- Par &operator ++() {
- ++vrednost;
- return *this;
- }
- Par operator ++ (int) {
- Par pom(*this);
- ++vrednost;
- return pom;
- }
- Par operator + (const Par &p) {
- char *pom;
- if(strlen(kluch)>=strlen(p.kluch)) {
- pom=new char[strlen(kluch)+1];
- strcpy(pom, kluch);
- } else {
- pom=new char[strlen(p.kluch)+1];
- strcpy(pom, p.kluch);
- }
- double pomVrednost=vrednost+p.vrednost;
- Par nov(pom, pomVrednost);
- return nov;
- }
- bool operator == (const Par &p) {
- return((strcmp(kluch,p.kluch)==0)&&(vrednost==p.vrednost));
- }
- char* getKluch() {
- return kluch;
- }
- ~Par() {
- delete [] kluch;
- }
- };
- class Kolekcija {
- Par *parovi;
- int dolzhina;
- public:
- Kolekcija() {
- parovi=new Par[0];
- dolzhina=0;
- }
- Kolekcija(const Kolekcija &k) {
- parovi=new Par[k.dolzhina];
- dolzhina=k.dolzhina;
- for(int i=0; i<dolzhina; i++) {
- parovi[i]=k.parovi[i];
- }
- }
- Kolekcija &operator = (const Kolekcija &k) {
- delete [] parovi;
- parovi=new Par[k.dolzhina];
- dolzhina=k.dolzhina;
- for(int i=0; i<dolzhina; i++) {
- parovi[i]=k.parovi[i];
- }
- return *this;
- }
- Kolekcija &operator += (const Par &p) {
- Par *pom=new Par[dolzhina];
- for(int i=0; i<dolzhina; i++) {
- pom[i]=parovi[i];
- }
- delete [] parovi;
- parovi=new Par[dolzhina+1];
- for(int i=0; i<dolzhina; i++) {
- parovi[i]=pom[i];
- }
- delete [] pom;
- parovi[dolzhina]=p;
- dolzhina++;
- return *this;
- }
- friend ostream &operator << (ostream &o, const Kolekcija &k) {
- o<<k.dolzhina<<endl;
- for(int i=0; i<k.dolzhina; i++) {
- o<<k.parovi[i];
- }
- return o;
- }
- bool operator == (const Kolekcija &k) {
- if(dolzhina!=k.dolzhina)
- return false;
- for(int i=0; i<dolzhina; i++) {
- if(!(parovi[i]==k.parovi[i]))
- return false;
- }
- return true;
- }
- void najdi (const char * kluch) {
- for(int i=0; i<dolzhina; i++) {
- if(strcmp(parovi[i].getKluch(),kluch)==0) {
- cout<<parovi[i];
- break;
- }
- }
- }
- ~Kolekcija() {
- delete [] parovi;
- }
- };
- void printTrueOrFalse (Kolekcija k1, Kolekcija k2) {
- if (k1==k2)
- cout << "TRUE" <<endl;
- else
- cout <<"FALSE" << endl;
- }
- int main() {
- int testCase;
- cin >> testCase;
- if (testCase == 1) {
- cout<<"Testiranje na konstruktori za Par i operator << "<<endl;
- Par p[20];
- int n;
- cin>>n;
- char kluc[50];
- double vrednost;
- for (int i=0; i<n; i++) {
- cin >> kluc >> vrednost;
- //cout << kluc << vrednost;
- Par p1 = Par(kluc,vrednost);
- //cout <<"GRESKA";
- p[i] = p1;
- cout << p[i];
- }
- } else if (testCase == 2) {
- cout << "Testiranje na operatorite ++ vo prefix i postfix notacija" <<endl;
- Par p1 = Par("FINKI",10.20);
- cout << p1;
- cout << p1++;
- cout << p1;
- Par p2 = Par("OOP",69.69);
- cout << p2;
- cout << ++p2;
- cout << p2;
- } else if (testCase == 3) {
- cout << "Testiranje na operatorot + vo klasata Par"<<endl;
- double vrednost;
- char kluc[50];
- Par p[2];
- for (int i=0; i<2; i++) {
- cin >> kluc >> vrednost;
- p[i]=Par(kluc,vrednost);
- }
- cout << p[0]+p[1];
- } else if (testCase==4) {
- cout << "Testiranje na operatorot + vo klasata Par"<<endl;
- double vrednost;
- char kluc [50];
- int n;
- cin >> n;
- Par p [50];
- for (int i=0; i<n; i++) {
- cin>>kluc>>vrednost;
- p[i]=Par(kluc,vrednost);
- }
- Par p1 = p[0];
- for (int i=1; i<n; i++)
- p1 = (p1 + p[i]);
- cout << p1;
- } else if (testCase == 5) {
- cout<<"Testiranje na operatorite << i += vo klasata Kolekcija"<<endl;
- Kolekcija k;
- int n;
- double vrednost;
- char kluc [50];
- cin >> n;
- for (int i=0; i<n; i++) {
- cin >> kluc >> vrednost;
- Par p = Par (kluc,vrednost);
- k+=p;
- //cout << p;
- }
- cout << k;
- } else if (testCase == 6) {
- cout << "Testiranje na operator == za klasata Kolekcija"<<endl;
- Par p1 ("A",1);
- Par p2 ("B",2);
- Par p3 ("B",3);
- Par p4 ("C",4);
- Kolekcija k1;
- k1 += p1;
- k1 += p2;
- k1 += p3;
- Kolekcija k2;
- k2+=p1;
- k2+=p4;
- Kolekcija k3;
- k3+=p1;
- k3+=p4;
- Kolekcija k4;
- k4+=p1;
- k4+=p3;
- printTrueOrFalse(k1,k2);
- printTrueOrFalse(k1,k3);
- printTrueOrFalse(k1,k4);
- printTrueOrFalse(k2,k3);
- printTrueOrFalse(k2,k4);
- printTrueOrFalse(k3,k4);
- } else {
- cout << "Testiranje na metodot najdi() vo klasata Kolekcija"<<endl;
- Kolekcija k;
- int n;
- double vrednost;
- char kluc [50];
- cin >> n;
- for (int i=0; i<n; i++) {
- cin >> kluc >> vrednost;
- Par p = Par (kluc,vrednost);
- k+=p;
- //cout << p;
- }
- char toFind[50];
- cin >> toFind;
- k.najdi(toFind);
- }
- return 0;
- }
- //16. Листа од цели броеви
- #include<iostream>
- #include<cstring>
- #include<cmath>
- using namespace std;
- class List {
- int *broevi;
- int dolzhina;
- public:
- List()
- {
- broevi=new int[0];
- dolzhina=0;
- }
- List(int l) {
- broevi=new int[l];
- dolzhina=l;
- }
- List(int *b, int l) {
- broevi=new int[l];
- for(int i=0; i<l; i++) {
- broevi[i]=b[i];
- }
- dolzhina=l;
- }
- List(const List &l) {
- broevi=new int[l.dolzhina];
- for(int i=0; i<l.dolzhina; i++) {
- broevi[i]=l.broevi[i];
- }
- dolzhina=l.dolzhina;
- }
- List &operator = (const List &l) {
- delete [] broevi;
- broevi=new int[l.dolzhina];
- for(int i=0; i<l.dolzhina; i++) {
- broevi[i]=l.broevi[i];
- }
- dolzhina=l.dolzhina;
- return *this;
- }
- int sum() const {
- int suma=0;
- for(int i=0; i<dolzhina; i++) {
- suma+=broevi[i];
- }
- return suma;
- }
- void setDol(int d)
- {
- int *pom=new int[d];
- for(int i=0; i<d; i++)
- {
- pom[i]=broevi[i];
- }
- delete [] broevi;
- broevi=new int[d];
- for(int i=0; i<d; i++)
- {
- broevi[i]=pom[i];
- }
- dolzhina=d;
- delete [] pom;
- }
- double average() const {
- return (sum()*1.0)/dolzhina;
- }
- bool operator == (List &l) {
- return(sum()==l.sum());
- }
- friend ostream &operator << (ostream &o, const List &l) {
- if(l.dolzhina<=0) {
- o<<"The list is empty"<<endl;
- return o;
- }
- o<<l.dolzhina<<": ";
- for(int i=0; i<l.dolzhina; i++) {
- o<<l.broevi[i]<<" ";
- }
- o<<"sum: "<<l.sum()<<" average: "<<l.average()<<endl;
- return o;
- }
- friend istream &operator >> (istream &i, List &l) {
- i>>l.dolzhina;
- //l.setDol(l.dolzhina);
- l.broevi=new int[l.dolzhina];
- for(int j=0; j<l.dolzhina; j++) {
- i>>l.broevi[j];
- }
- return i;
- }
- List operator + (List l) {
- if(dolzhina==l.dolzhina)
- {
- int *pom = new int [dolzhina];
- for(int i=0; i<dolzhina; i++)
- {
- pom[i]=broevi[i]+l.broevi[i];
- }
- List pom1(pom, dolzhina);
- return pom1;
- }
- else
- {
- List pom;
- return pom;
- }
- }
- List operator - (List l) {
- if(dolzhina==l.dolzhina)
- {
- int *pom = new int [dolzhina];
- for(int i=0; i<dolzhina; i++)
- {
- pom[i]=broevi[i]-l.broevi[i];
- }
- List pom1(pom, dolzhina);
- return pom1;
- }
- else
- {
- List pom;
- return pom;
- }
- }
- List operator ++ () {
- for(int i=0; i<dolzhina; i++) {
- ++broevi[i];
- }
- return *this;
- }
- List operator -- (int) {
- List newList(broevi, dolzhina);
- for(int i=0; i<dolzhina; i++) {
- --broevi[i];
- }
- return newList;
- }
- List &operator += (int a) {
- int brojac=0;
- for(int i=0; i<dolzhina; i++) {
- if(a==broevi[i])
- brojac++;
- }
- if(brojac<2) {
- int *pom=new int [dolzhina];
- for(int i=0; i<dolzhina; i++) {
- pom[i]=broevi[i];
- }
- delete [] broevi;
- broevi=new int[dolzhina+1];
- for(int i=0; i<dolzhina; i++) {
- broevi[i]=pom[i];
- }
- broevi[dolzhina]=a;
- delete [] pom;
- dolzhina++;
- }
- return *this;
- }
- int operator [] (int index) {
- return broevi[index];
- }
- List addList (List &l) {
- int newDol=dolzhina+l.dolzhina-1;
- int *newNum=new int[newDol];
- for(int i=0; i<dolzhina; i++) {
- newNum[i]=broevi[i];
- }
- for(int i=0; i<l.dolzhina; i++) {
- newNum[dolzhina+i]=l.broevi[i+1];
- }
- List nova(newNum, newDol);
- return nova;
- }
- ~List() {
- delete [] broevi;
- }
- };
- int main() {
- int testCase;
- cin>>testCase;
- if (testCase==1) {
- cout<<"Testiranje na operatorite << i >>"<<endl;
- List l;
- cin >> l;
- cout<< l;
- } else if (testCase == 2) {
- cout<<"Testiranje na operatorot = za klasata List"<<endl;
- List l1;
- cin >> l1;
- List l2;
- l2 = l1;
- cout << l2;
- } else if (testCase == 3) {
- //2 test primeri tuka
- cout << "Testiranje na operatorot +"<<endl;
- List l1,l2;
- cin >> l1;
- cin >> l2;
- List l3;
- l3 = l1+l2;
- cout << l3;
- } else if (testCase == 4) {
- cout << "Testiranje na operatorot - "<<endl;
- List l1,l2;
- cin >> l1;
- cin >> l2;
- List l3;
- l3 = l1-l2;
- cout << l3;
- } else if (testCase == 5) {
- cout << "Testiranje na operator ++ vo prefix notacija"<<endl;
- List l1;
- cin >> l1;
- cout << l1;
- cout << ++l1;
- } else if (testCase == 6) {
- cout << "Testiranje na operatorot -- vo sufix notacija"<<endl;
- List l1;
- cin >> l1;
- cout << "Pocetna vrednost: " << l1;
- List l2;
- l2 = l1--;
- cout << "Se povikuva ++ vo sufiks: " << l2;
- cout << "Posle povik: " << l1;
- } else if (testCase == 7) {
- cout << "Testiranje na operator += "<<endl;
- List l1;
- cin >> l1;
- int n;
- cin >> n;
- for (int i=0; i<n; i++) {
- int broj;
- cin >> broj;
- l1 += broj;
- }
- cout << l1;
- } else if (testCase == 8) {
- cout << "Testiranje na operatorot [ ] "<< endl;
- List l1;
- cin >> l1;
- int n;
- cin >> n;
- for (int i=0; i<n; i++) {
- int idx;
- cin >> idx;
- cout << "List["<< idx <<"] = " << l1[idx] << endl;
- }
- } else {
- //Dopolnitelno baranje
- cout <<"Testiranje na addList() metodot"<<endl;
- List l1,l2;
- cin >> l1;
- cin >> l2;
- cout << l1.addList(l2);
- }
- return 0;
- }
- //17. Vector
- #include<iostream>
- #include<cstring>
- using namespace std;
- class MyVector
- {
- int broevi[15];
- int elementi;
- public:
- MyVector()
- {
- elementi=0;
- }
- MyVector(int *b, int e)
- {
- for(int i=0; i<e; i++)
- {
- broevi[i]=b[i];
- }
- elementi=e;
- }
- void setElementi(int e)
- {
- elementi=e;
- }
- friend istream &operator >> (istream &is, MyVector &m)
- {
- is>>m.elementi;
- m.setElementi(m.elementi);
- for(int i=0; i<m.elementi; i++)
- {
- is>>m.broevi[i];
- }
- return is;
- }
- friend ostream &operator << (ostream &os, MyVector &m)
- {
- os<<"<";
- for(int i=0; i<m.elementi; i++)
- {
- if(i!=m.elementi-1)
- os<<m.broevi[i]<<",";
- else
- os<<m.broevi[i];
- }
- os<<">"<<endl;
- return os;
- }
- MyVector &operator -= (MyVector &m)
- {
- for(int i=0; i<elementi; i++)
- {
- broevi[i]-=m.broevi[i];
- }
- return *this;
- }
- int operator * (MyVector &m)
- {
- int suma=0;
- for(int i=0; i<elementi; i++)
- {
- suma+=broevi[i]*m.broevi[i];
- }
- return suma;
- }
- bool operator <= (MyVector &m)
- {
- int suma1=0, suma2=0;
- for(int i=0; i<elementi; i++)
- {
- suma1+=broevi[i];
- }
- for(int i=0; i<m.elementi; i++)
- {
- suma2+=m.broevi[i];
- }
- return(suma1<=suma2);
- }
- void Error()
- {
- cout<<"Index out of bounds"<<endl;
- }
- int operator [] (int index)
- {
- if(index<0 || index>elementi-1)
- {
- Error();
- return -1;
- }
- else
- return broevi[index];
- }
- MyVector &operator --()
- {
- for(int i=0; i<elementi; i++)
- {
- if(broevi[i]>0)
- --broevi[i];
- }
- return *this;
- }
- MyVector operator ++(int)
- {
- MyVector temp(*this);
- for(int i=0; i<elementi; i++)
- {
- if(broevi[i]<0)
- ++broevi[i];
- }
- return temp;
- }
- };
- int main() {
- int n;
- cin >> n;
- if (n == 1) {
- cout << "Testiranje na operatorite >> i <<" << endl;
- cout << "==============================\n";
- MyVector a;
- MyVector b;
- cin >> a;
- cin >> b;
- cout << a;
- cout << b;
- }
- else if (n == 2) {
- cout << "Testiranje na operatorot -="<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- for (int i=0; i < m; ++i) {
- cin >> niza[i];
- }
- MyVector b(niza,m);
- a -= b;
- cout << a;
- }
- else if (n == 3) {
- cout << "Testiranje na operatorot *"<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- for (int i=0; i < m; ++i) {
- cin >> niza[i];
- }
- MyVector b(niza,m);
- cout << a * b;
- }
- else if (n == 4){
- cout << "Testiranje na operatorot <="<< endl;
- cout << "==============================\n";
- int m;
- int l;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- cin >> l;
- for (int i=0; i < l; ++i) {
- cin >> niza[i];
- }
- MyVector b(niza,l);
- cout << (a <= b);
- }
- else if (n == 5){
- cout << "Testiranje na operatorot []"<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- for (int i=0; i < m; ++i) {
- cin >> niza[i];
- }
- MyVector b(niza,m);
- cout << a[2];
- cout << endl;
- cout << b[3];
- }
- else if (n == 6) {
- cout << "Testiranje na operatorot --"<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- --a;
- cout << a;
- }
- else if (n == 7) {
- cout << "Testiranje na operatorot ++"<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- MyVector b = a++;
- cout << a;
- cout << b;
- }
- }
- //18. Мој термин
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Lekar
- {
- protected:
- int faksimil;
- char ime[20];
- char prezime[20];
- double pay;
- public:
- Lekar(){}
- Lekar(int faksimil, char *ime, char *prezime, double pay)
- {
- this->faksimil=faksimil;
- strcpy(this->ime, ime);
- strcpy(this->prezime, prezime);
- this->pay=pay;
- }
- Lekar(const Lekar &l)
- {
- this->faksimil=l.faksimil;
- strcpy(this->ime, l.ime);
- strcpy(this->prezime, l.prezime);
- this->pay=l.pay;
- }
- Lekar &operator = (const Lekar &l)
- {
- this->faksimil=l.faksimil;
- strcpy(this->ime, l.ime);
- strcpy(this->prezime, l.prezime);
- this->pay=l.pay;
- return *this;
- }
- void pecati()
- {
- cout<<faksimil<<": "<<ime<<" "<<prezime<<endl;
- }
- double plata()
- {
- return pay;
- }
- };
- class MaticenLekar: public Lekar
- {
- private:
- int broj;
- double *kotizacii;
- public:
- MaticenLekar():Lekar()
- {
- broj=0;
- kotizacii=new double[0];
- }
- MaticenLekar(const Lekar &l, int broj, double *kotizacii):Lekar(l)
- {
- this->broj=broj;
- this->kotizacii=new double[broj];
- for(int i=0; i<broj; i++)
- {
- this->kotizacii[i]=kotizacii[i];
- }
- }
- MaticenLekar(const MaticenLekar &l):Lekar(l)
- {
- this->broj=l.broj;
- this->kotizacii=new double[broj];
- for(int i=0; i<broj; i++)
- {
- this->kotizacii[i]=l.kotizacii[i];
- }
- }
- MaticenLekar &operator = (const MaticenLekar &l)
- {
- (Lekar&)(*this)=l;
- delete [] kotizacii;
- this->broj=l.broj;
- this->kotizacii=new double[broj];
- for(int i=0; i<broj; i++)
- {
- this->kotizacii[i]=l.kotizacii[i];
- }
- return *this;
- }
- void pecati()
- {
- Lekar::pecati();
- double sum=0;
- for(int i=0; i<broj; i++)
- {
- sum+=kotizacii[i];
- }
- cout<<"Prosek na kotizacii: "<<sum/broj<<endl;
- }
- double plata()
- {
- double sum=0;
- for(int i=0; i<broj; i++)
- {
- sum+=kotizacii[i];
- }
- return 0.3*sum/broj+Lekar::plata();
- }
- ~MaticenLekar()
- {
- delete [] kotizacii;
- }
- };
- int main() {
- int n;
- cin>>n;
- int pacienti;
- double kotizacii[100];
- int faksimil;
- char ime [20];
- char prezime [20];
- double osnovnaPlata;
- Lekar * lekari = new Lekar [n];
- MaticenLekar * maticni = new MaticenLekar [n];
- for (int i=0;i<n;i++){
- cin >> faksimil >> ime >> prezime >> osnovnaPlata;
- lekari[i] = Lekar(faksimil,ime,prezime,osnovnaPlata);
- }
- for (int i=0;i<n;i++){
- cin >> pacienti;
- for (int j=0;j<pacienti;j++){
- cin >> kotizacii[j];
- }
- maticni[i]=MaticenLekar(lekari[i],pacienti,kotizacii);
- }
- int testCase;
- cin>>testCase;
- if (testCase==1){
- cout<<"===TESTIRANJE NA KLASATA LEKAR==="<<endl;
- for (int i=0;i<n;i++){
- lekari[i].pecati();
- cout<<"Osnovnata plata na gorenavedeniot lekar e: "<<lekari[i].plata()<<endl;
- }
- }
- else {
- cout<<"===TESTIRANJE NA KLASATA MATICENLEKAR==="<<endl;
- for (int i=0;i<n;i++){
- maticni[i].pecati();
- cout<<"Platata na gorenavedeniot maticen lekar e: "<<maticni[i].plata()<<endl;
- }
- }
- delete [] lekari;
- delete [] maticni;
- return 0;
- }
- //19. Квадрат и правоаголник
- #include <iostream>
- using namespace std;
- class Kvadrat
- {
- protected:
- double a;
- public:
- Kvadrat() {}
- Kvadrat(double a)
- {
- this->a=a;
- }
- Kvadrat(const Kvadrat &k)
- {
- a=k.a;
- }
- double perimetar()
- {
- return 4*a;
- }
- double plostina()
- {
- return a*a;
- }
- void pecati()
- {
- cout<<"Kvadrat so dolzina a="<<a<<" ima plostina P="<<plostina()<<" i perimetar L="<<perimetar()<<endl;
- }
- };
- class Pravoagolnik: public Kvadrat //da se vmetni nasleduvanjeto
- {
- private:
- double x;
- double y;
- public:
- Pravoagolnik() {}
- Pravoagolnik(const Kvadrat &k, double x, double y):Kvadrat(k)
- {
- this->x=x;
- this->y=y;
- }
- Pravoagolnik(const Pravoagolnik &p):Kvadrat(p)
- {
- x=p.x;
- y=p.y;
- }
- double perimetar()
- {
- double per = Kvadrat::perimetar()+2*(x+y);
- return per;
- }
- double plostina()
- {
- double plos = Kvadrat::plostina()+a*x+a*y+x*y;
- return plos;
- }
- void pecati()
- {
- if(x==y)
- {
- a+=x;
- Kvadrat::pecati();
- a-=x;
- }
- else
- cout<<"Pravoagolnik so strani: "<<a+x<<" i "<<a+y<<" ima plostina P="<<plostina()<<" i perimetar L="<<perimetar()<<endl;
- }
- };
- int main()
- {
- int n;
- double a,x,y;
- Kvadrat * kvadrati;
- Pravoagolnik * pravoagolnici;
- cin>>n;
- kvadrati = new Kvadrat [n];
- pravoagolnici = new Pravoagolnik [n];
- for (int i=0; i<n; i++)
- {
- cin>>a;
- kvadrati[i] = Kvadrat(a);
- }
- for (int i=0; i<n; i++)
- {
- cin>>x>>y;
- pravoagolnici[i]=Pravoagolnik(kvadrati[i],x,y);
- }
- int testCase;
- cin>>testCase;
- if (testCase==1)
- {
- cout<<"===Testiranje na klasata Kvadrat==="<<endl;
- for (int i=0; i<n; i++)
- kvadrati[i].pecati();
- }
- else
- {
- cout<<"===Testiranje na klasata Pravoagolnik==="<<endl;
- for (int i=0; i<n; i++)
- pravoagolnici[i].pecati();
- }
- }
- //20. NBA
- #include <iostream>
- #include <cstring>
- using namespace std;
- class NBAPlayer
- {
- protected:
- char *ime;
- char tim[40];
- double points;
- double assists;
- double rebounds;
- public:
- NBAPlayer()
- {
- ime=new char[0];
- points=assists=rebounds=0;
- }
- NBAPlayer(char *ime, char *tim, double points, double assists, double rebounds)
- {
- this->ime = new char[strlen(ime)+1];
- strcpy(this->ime, ime);
- strcpy(this->tim, tim);
- this->points=points;
- this->assists=assists;
- this->rebounds=rebounds;
- }
- NBAPlayer(const NBAPlayer &n)
- {
- this->ime = new char[strlen(n.ime)+1];
- strcpy(this->ime, n.ime);
- strcpy(this->tim, n.tim);
- this->points=n.points;
- this->assists=n.assists;
- this->rebounds=n.rebounds;
- }
- NBAPlayer &operator = (const NBAPlayer &n)
- {
- delete [] ime;
- this->ime = new char[strlen(n.ime)+1];
- strcpy(this->ime, n.ime);
- strcpy(this->tim, n.tim);
- this->points=n.points;
- this->assists=n.assists;
- this->rebounds=n.rebounds;
- return *this;
- }
- double rating()
- {
- return 0.45*points+0.3*assists+0.25*rebounds;
- }
- void print()
- {
- cout<<ime<<" - "<<tim<<endl;
- cout<<"Points: "<<points<<endl;
- cout<<"Assists: "<<assists<<endl;
- cout<<"Rebounds: "<<rebounds<<endl;
- cout<<"Rating: "<<rating()<<endl;
- }
- ~NBAPlayer()
- {
- delete [] ime;
- }
- };
- class AllStarPlayer: public NBAPlayer
- {
- protected:
- double pointsAvg;
- double assistsAvg;
- double reboundsAvg;
- public:
- AllStarPlayer():NBAPlayer()
- {
- pointsAvg=assistsAvg=reboundsAvg=0;
- }
- AllStarPlayer(char *ime, char *tim, double points, double assists, double rebounds, double pointsAvg, double assistsAvg, double reboundsAvg):NBAPlayer(ime, tim, points, assists, rebounds)
- {
- this->pointsAvg=pointsAvg;
- this->assistsAvg=assistsAvg;
- this->reboundsAvg=reboundsAvg;
- }
- AllStarPlayer(const NBAPlayer &n, double pointsAvg, double assistsAvg, double reboundsAvg):NBAPlayer(n)
- {
- this->pointsAvg=pointsAvg;
- this->assistsAvg=assistsAvg;
- this->reboundsAvg=reboundsAvg;
- }
- AllStarPlayer(const AllStarPlayer &n):NBAPlayer(n)
- {
- this->pointsAvg=n.pointsAvg;
- this->assistsAvg=n.assistsAvg;
- this->reboundsAvg=n.reboundsAvg;
- }
- AllStarPlayer &operator = (const AllStarPlayer &n)
- {
- (NBAPlayer&)(*this)=n;
- this->pointsAvg=n.pointsAvg;
- this->assistsAvg=n.assistsAvg;
- this->reboundsAvg=n.reboundsAvg;
- return *this;
- }
- double AllStarRating()
- {
- return 0.3*pointsAvg+0.4*assistsAvg+0.3*reboundsAvg;
- }
- double rating()
- {
- return (AllStarRating()+NBAPlayer::rating())/2;
- }
- void print()
- {
- NBAPlayer::print();
- cout<<"All Star Rating: "<<AllStarRating()<<endl;
- cout<<"New Rating: "<<rating()<<endl;
- }
- };
- int main() {
- char name[50];
- char team[40];
- double points;
- double assists;
- double rebounds;
- double allStarPoints;
- double allStarAssists;
- double allStarRebounds;
- NBAPlayer * players = new NBAPlayer[5];
- AllStarPlayer * asPlayers = new AllStarPlayer[5];
- int n;
- cin >> n;
- if (n == 1) {
- cout << "NBA PLAYERS:" << endl;
- cout << "=====================================" << endl;
- for (int i = 0; i < 5; ++i) {
- cin >> name >> team >> points >> assists >> rebounds;
- players[i] = NBAPlayer(name,team,points,assists,rebounds);
- players[i].print();
- }
- }
- else if (n == 2) {
- for (int i=0; i < 5; ++i){
- cin >> name >> team >> points >> assists >> rebounds;
- cin >> allStarPoints >> allStarAssists >> allStarRebounds;
- players[i] = NBAPlayer(name,team,points,assists,rebounds);
- asPlayers[i] = AllStarPlayer(players[i],allStarPoints,allStarAssists,allStarAssists);
- }
- cout << "NBA PLAYERS:" << endl;
- cout << "=====================================" << endl;
- for (int i=0; i < 5; ++i)
- players[i].print();
- cout << "ALL STAR PLAYERS:" << endl;
- cout << "=====================================" << endl;
- for (int i=0; i < 5; ++i)
- asPlayers[i].print();
- }
- else if (n == 3) {
- for (int i=0; i < 5; ++i){
- cin >> name >> team >> points >> assists >> rebounds;
- cin >> allStarPoints >> allStarAssists >> allStarRebounds;
- asPlayers[i] = AllStarPlayer(name, team, points, assists, rebounds,
- allStarPoints,allStarAssists,allStarAssists);
- }
- cout << "ALL STAR PLAYERS:" << endl;
- cout << "=====================================" << endl;
- for (int i=0; i < 5; ++i)
- asPlayers[i].print();
- }
- delete [] players;
- delete [] asPlayers;
- }
- //21. Employee
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Employee
- {
- protected:
- char ime[50];
- int godini;
- int rabotnoIskustvo;
- public:
- Employee(const char *ime, int godini, int rabotnoIskustvo)
- {
- strcpy(this->ime, ime);
- this->godini=godini;
- this->rabotnoIskustvo=rabotnoIskustvo;
- }
- int getGod()
- {
- return godini;
- }
- virtual double plata()const =0;
- virtual double bonus()const
- {
- return 0;
- }
- virtual ~Employee() {}
- };
- bool operator == (Employee &emp1,Employee &emp2) {
- return emp1.getGod() == emp2.getGod()&&emp1.bonus() == emp2.bonus();
- }
- class SalaryEmployee:public Employee
- {
- private:
- double osnovnaPlata;
- public:
- SalaryEmployee(char *ime, int godini, int rabotnoIskustvo, double osnovnaPlata):Employee(ime, godini, rabotnoIskustvo)
- {
- this->osnovnaPlata=osnovnaPlata;
- }
- double bonus()const
- {
- return (osnovnaPlata*rabotnoIskustvo)/100.00;
- }
- double plata()const
- {
- return bonus()+osnovnaPlata;
- }
- };
- class HourlyEmployee:public Employee
- {
- private:
- int rabotniChasovi;
- int plataPoChas;
- public:
- HourlyEmployee(const char *ime, int godini, int rabotnoIskustvo, int rabotniChasovi, int plataPoChas):Employee(ime, godini, rabotnoIskustvo)
- {
- this->rabotniChasovi=rabotniChasovi;
- this->plataPoChas=plataPoChas;
- }
- double bonus()const
- {
- if(rabotniChasovi>320)
- return (rabotniChasovi-320)*0.5*plataPoChas;
- else return 0;
- }
- double plata()const
- {
- return bonus()+rabotniChasovi*plataPoChas;
- }
- };
- class Freelancer:public Employee
- {
- private:
- int brojProekti;
- double plati[20];
- public:
- Freelancer(char *ime, int godini, int rabotnoIskustvo, int brojProekti, double *plati):Employee(ime, godini, rabotnoIskustvo)
- {
- this->brojProekti=brojProekti;
- for(int i=0; i<brojProekti; i++)
- {
- this->plati[i]=plati[i];
- }
- }
- double bonus()const
- {
- if(brojProekti>5)
- return (brojProekti-5)*1000.0;
- else return 0;
- }
- double plata()const
- {
- double sum=0;
- for(int i=0; i<brojProekti; i++)
- {
- sum+=plati[i];
- }
- return sum+bonus();
- }
- };
- class Company
- {
- private:
- char ime[50];
- int brojVraboteni;
- Employee **vraboteni;
- public:
- Company(char *ime)
- {
- strcpy(this->ime, ime);
- brojVraboteni=0;
- vraboteni=new Employee*[0];
- }
- Company &operator += (Employee *p)
- {
- Employee **temp=new Employee*[brojVraboteni+1];
- for(int i=0; i<brojVraboteni; i++)
- {
- temp[i]=vraboteni[i];
- }
- temp[brojVraboteni]=p;
- brojVraboteni++;
- delete [] vraboteni;
- vraboteni=temp;
- return *this;
- }
- double vkupnaPlata()
- {
- double sum=0;
- for(int i=0; i<brojVraboteni; i++)
- {
- sum+=vraboteni[i]->plata();
- }
- return sum;
- }
- double filtriranaPlata(Employee * emp)
- {
- double sum=0;
- for(int i=0; i<brojVraboteni; i++)
- {
- if(*emp==*vraboteni[i])
- sum+=vraboteni[i]->plata();
- }
- return sum;
- }
- void pecatiRabotnici()
- {
- int salary, hourly, free;
- salary=hourly=free=0;
- for(int i=0; i<brojVraboteni; i++)
- {
- SalaryEmployee *temp1=dynamic_cast<SalaryEmployee*>(vraboteni[i]);
- HourlyEmployee *temp2=dynamic_cast<HourlyEmployee*>(vraboteni[i]);
- Freelancer *temp3=dynamic_cast<Freelancer*>(vraboteni[i]);
- if(temp1!=0)
- salary++;
- if(temp2!=0)
- hourly++;
- if(temp3!=0)
- free++;
- }
- cout << "Vo kompanijata " << ime << " rabotat:" <<endl;
- cout << "Salary employees: " << salary << endl;
- cout << "Hourly employees: " << hourly << endl;
- cout << "Freelancers: " << free << endl;
- }
- ~Company()
- {
- for(int i=0; i<brojVraboteni; i++)
- {
- delete vraboteni[i];
- }
- delete [] vraboteni;
- }
- };
- int main()
- {
- char name[50];
- cin >> name;
- Company c(name);
- int n;
- cin >> n;
- char employeeName[50];
- int age;
- int experience;
- int type;
- for (int i=0; i <n; ++i)
- {
- cin >> type;
- cin >> employeeName >> age >> experience;
- if (type == 1)
- {
- int basicSalary;
- cin >> basicSalary;
- c += new SalaryEmployee(employeeName, age, experience, basicSalary);
- }
- else if (type == 2)
- {
- int hoursWorked;
- int hourlyPay;
- cin >> hoursWorked >> hourlyPay;
- c += new HourlyEmployee(employeeName, age, experience, hoursWorked, hourlyPay);
- }
- else
- {
- int numProjects;
- cin >> numProjects;
- double projects[10];
- for (int i=0; i < numProjects; ++i)
- {
- cin >> projects[i];
- }
- c += new Freelancer(employeeName, age, experience, numProjects, projects);
- }
- }
- c.pecatiRabotnici();
- cout << "Vkupnata plata e: " << c.vkupnaPlata() << endl;
- Employee * emp = new HourlyEmployee("Petre_Petrov",31,6,340,80);
- cout << "Filtriranata plata e: " << c.filtriranaPlata(emp);
- delete emp;
- }
- //22. Распоредувач на задачи
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Task {
- protected:
- char ID[5];
- public:
- Task(){}
- Task(const char *id) {
- strcpy(ID, id);
- }
- char *getID()
- {
- return ID;
- }
- Task (Task &t)
- {
- strcpy(ID, t.ID);
- }
- virtual int getOrder()=0;
- virtual void print()=0;
- virtual ~Task() {}
- };
- class TimedTask: public Task {
- private:
- int time;
- public:
- TimedTask():Task(){}
- TimedTask(const char *id, const int t):Task(id) {
- time=t;
- }
- TimedTask(TimedTask &t):Task(t) {
- time=t.time;
- }
- int getOrder() {
- return time;
- }
- void print() {
- cout<<"TT->"<<ID<<":"<<getOrder()<<endl;
- }
- };
- class PriorityTask: public Task {
- private:
- int priority;
- public:
- PriorityTask():Task(){}
- PriorityTask(const char *id, const int t):Task(id) {
- priority=t;
- }
- PriorityTask(PriorityTask &t):Task(t) {
- priority=t.priority;
- }
- int getOrder() {
- return priority;
- }
- void print() {
- cout<<"PT->"<<ID<<":"<<getOrder()<<endl;
- }
- };
- void scheduleTimedTasks (Task ** tasks, int n, int t) {
- for(int i=0; i<n-1; i++) {
- TimedTask *temp1=dynamic_cast<TimedTask*>(tasks[i]);
- if(temp1!=0)
- for(int j=i; j<n; j++) {
- TimedTask *temp2=dynamic_cast<TimedTask*>(tasks[j]);
- if(temp2!=0&&tasks[i]->getOrder()>tasks[j]->getOrder()) {
- Task *temp;
- temp=tasks[i];
- tasks[i]=tasks[j];
- tasks[j]=temp;
- }
- }
- }
- for(int i=0; i<n; i++) {
- TimedTask *temp=dynamic_cast<TimedTask*>(tasks[i]);
- if(temp!=0&&tasks[i]->getOrder()<t)
- tasks[i]->print();
- }
- }
- void schedulePriorityTasks(Task ** tasks, int n,int p) {
- for(int i=0; i<n-1; i++) {
- PriorityTask *temp1=dynamic_cast<PriorityTask*>(tasks[i]);
- if(temp1!=0)
- for(int j=i; j<n; j++) {
- PriorityTask *temp2=dynamic_cast<PriorityTask*>(tasks[j]);
- if(temp2!=0&&tasks[i]->getOrder()>tasks[j]->getOrder()) {
- Task *temp;
- temp=tasks[i];
- tasks[i]=tasks[j];
- tasks[j]=temp;
- }
- }
- }
- for(int i=0; i<n; i++) {
- PriorityTask *temp=dynamic_cast<PriorityTask*>(tasks[i]);
- if(temp!=0&&tasks[i]->getOrder()<p)
- tasks[i]->print();
- }
- }
- bool operator == (Task *t, Task &p)
- {
- return t->getOrder()==p.getOrder()&&strcmp(t->getID(), p.getID())==0;
- }
- int main () {
- int testCase;
- int n;
- cin>>testCase;
- if (testCase==0) {
- cin>>n;
- Task ** tasks;
- tasks = new Task * [n];
- for (int i=0; i<n; i++) {
- char id [5];
- int timeOrPriority;
- int type; //0 za timed, 1 za priority
- cin >> type >>id >> timeOrPriority;
- if (type==0)
- tasks[i] = new TimedTask(id,timeOrPriority);
- else
- tasks[i] = new PriorityTask(id,timeOrPriority);
- //tasks[i]->print();
- }
- cout<<"SCHEDULING PRIORITY TASKS WITH PRIORITY DEGREE LESS THAN 10"<<endl;
- schedulePriorityTasks(tasks,n,10);
- } else if (testCase==1) {
- cin>>n;
- Task ** tasks;
- tasks = new Task * [n];
- for (int i=0; i<n; i++) {
- char id [5];
- int timeOrPriority;
- int type; //0 za timed, 1 za priority
- cin >> type >>id >> timeOrPriority;
- if (type==0)
- tasks[i] = new TimedTask(id,timeOrPriority);
- else
- tasks[i] = new PriorityTask(id,timeOrPriority);
- //tasks[i]->print();
- }
- cout<<"SCHEDULING TIMED TASKS WITH EXECUTION TIME LESS THAN 50"<<endl;
- scheduleTimedTasks(tasks,n,50);
- } else {
- TimedTask * tt1 = new TimedTask("11",10);
- TimedTask * tt2 = new TimedTask("11",11);
- TimedTask * tt3 = new TimedTask("11",11);
- PriorityTask * pp1 = new PriorityTask("aa",10);
- PriorityTask * pp2 = new PriorityTask("11",10);
- cout << (tt1==(*tt2))<<endl;
- cout << (tt2==(*tt3))<<endl;
- cout << (pp1==(*pp2))<<endl;
- cout << (pp2==(*tt1))<<endl;
- }
- return 0;
- }
- //23. Numbers
- #include<iostream>
- using namespace std;
- class Number
- {
- public:
- virtual double doubleValue()const=0;
- virtual int intValue()const=0;
- virtual void print()=0;
- virtual ~Number() {}
- };
- class Integer: public Number
- {
- private:
- int a;
- public:
- Integer(int a):Number()
- {
- this->a=a;
- }
- double doubleValue()const
- {
- return 0;
- }
- int intValue()const
- {
- return a;
- }
- void print()
- {
- cout<<"Integer: "<<a<<endl;
- }
- };
- class Double: public Number
- {
- private:
- double a;
- public:
- Double(double a):Number()
- {
- this->a=a;
- }
- double doubleValue()const
- {
- return a;
- }
- int intValue()const
- {
- return 0;
- }
- void print()
- {
- cout<<"Double: "<<a<<endl;
- }
- };
- class Numbers
- {
- private:
- Number **broevi;
- int elementi;
- public:
- Numbers()
- {
- elementi=0;
- broevi=new Number*[0];
- }
- Numbers(const Numbers &n)
- {
- broevi=new Number*[n.elementi];
- elementi=n.elementi;
- for(int i=0; i<elementi; i++)
- {
- broevi[i]=n.broevi[i];
- }
- }
- Numbers &operator = (const Numbers &n)
- {
- for(int i=0; i<elementi; i++)
- {
- delete broevi[i];
- }
- delete [] broevi;
- broevi=new Number*[n.elementi];
- elementi=n.elementi;
- for(int i=0; i<elementi; i++)
- {
- broevi[i]=n.broevi[i];
- }
- return *this;
- }
- ~Numbers()
- {
- for(int i=0; i<elementi; i++)
- {
- delete broevi[i];
- }
- delete [] broevi;
- }
- Numbers &operator += (Number *n)
- {
- Number **temp=new Number*[elementi];
- for(int i=0; i<elementi; i++)
- {
- temp[i]=broevi[i];
- }
- delete [] broevi;
- broevi=new Number*[elementi+1];
- for(int i=0; i<elementi; i++)
- {
- broevi[i]=temp[i];
- }
- broevi[elementi]=n;
- elementi++;
- delete [] temp;
- return *this;
- }
- void statistics()
- {
- double sumaSite=0, sumaDouble=0;
- int sumaInt=0, elementiDouble=0, elementiInt=0;
- cout<<"Count of numbers: "<<elementi<<endl;
- for(int i=0; i<elementi; i++)
- {
- Integer *temp=dynamic_cast<Integer*>(broevi[i]);
- if(temp!=0)
- {
- sumaInt+=broevi[i]->intValue();
- elementiInt++;
- }
- else
- {
- sumaDouble+=broevi[i]->doubleValue();
- elementiDouble++;
- }
- }
- sumaSite=sumaInt+sumaDouble;
- cout<<"Sum of all numbers: "<<sumaSite<<endl;
- cout<<"Count of integer numbers: "<<elementiInt<<endl;
- cout<<"Sum of integer numbers: "<<sumaInt<<endl;
- cout<<"Count of double numbers: "<<elementiDouble<<endl;
- cout<<"Sum of double numbers: "<<sumaDouble<<endl;
- }
- void integersLessThan (Integer n)
- {
- bool f=true;
- for(int i=0; i<elementi; i++)
- {
- Integer *temp=dynamic_cast<Integer*>(broevi[i]);
- if(broevi[i]->intValue()<n.intValue()&&temp!=0)
- {
- broevi[i]->print();
- f=false;
- }
- }
- if(f)
- {
- cout<<"None"<<endl;
- }
- }
- void doublesBiggerThan (Double n)
- {
- bool f=true;
- for(int i=0; i<elementi; i++)
- {
- Integer *temp=dynamic_cast<Integer*>(broevi[i]);
- if(broevi[i]->doubleValue()>n.doubleValue()&&temp==0)
- {
- broevi[i]->print();
- f=false;
- }
- }
- if(f)
- {
- cout<<"None"<<endl;
- }
- }
- };
- int main()
- {
- int n;
- cin>>n;
- Numbers numbers;
- for (int i=0; i<n; i++)
- {
- int type;
- double number;
- cin>>type>>number;
- if (type==0) //Integer object
- {
- Integer * integer = new Integer((int) number);
- numbers+=integer;
- }
- else
- {
- Double * doublee = new Double(number);
- numbers+=doublee;
- }
- }
- int lessThan;
- double biggerThan;
- cin>>lessThan;
- cin>>biggerThan;
- cout<<"STATISTICS FOR THE NUMBERS\n";
- numbers.statistics();
- cout<<"INTEGER NUMBERS LESS THAN "<<lessThan<<endl;
- numbers.integersLessThan(Integer(lessThan));
- cout<<"DOUBLE NUMBERS BIGGER THAN "<<biggerThan<<endl;
- numbers.doublesBiggerThan(Double(biggerThan));
- return 0;
- }
- //24. Тајни пораки
- #include<cstring>
- #include<iostream>
- using namespace std;
- class Secret {
- public:
- virtual double simpleEntropy()=0;
- virtual int total()=0;
- virtual ~Secret() {}
- };
- bool operator == (Secret &s1, Secret &s2) {
- return s1.total()==s2.total()&&s1.simpleEntropy()==s2.simpleEntropy();
- }
- bool operator != (Secret &s1, Secret &s2) {
- return s1.total()!=s2.total() || s1.simpleEntropy()!=s2.simpleEntropy();
- }
- class DigitSecret: public Secret {
- private:
- int broevi[100];
- int elementi;
- public:
- DigitSecret():Secret() {
- elementi=0;
- }
- DigitSecret(const int *broevi, const int elementi):Secret() {
- for(int i=0; i<elementi; i++)
- this->broevi[i]=broevi[i];
- this->elementi=elementi;
- }
- DigitSecret(DigitSecret *p):Secret() {
- for(int i=0; i<p->elementi; i++)
- this->broevi[i]=p->broevi[i];
- this->elementi=p->elementi;
- }
- double simpleEntropy() {
- int brojac=0;
- int glaven=0;
- for(int i=0; i<10; i++) {
- brojac=0;
- for(int j=0; j<elementi; j++) {
- if(i==broevi[j]) {
- brojac++;
- }
- }
- if(brojac==1)
- glaven++;
- }
- return (double)glaven/elementi;
- }
- int total() {
- return elementi;
- }
- friend ostream &operator <<(ostream &o, DigitSecret &d) {
- for(int i=0; i<d.elementi; i++)
- o<<d.broevi[i];
- o<<" Simple entropy: "<<d.simpleEntropy()<<" Total: "<<d.total();
- return o;
- }
- };
- class CharSecret:public Secret {
- private:
- char znaci[100];
- int elementi;
- public:
- CharSecret():Secret() {
- elementi=0;
- }
- CharSecret(const char *z):Secret() {
- strcpy(znaci, z);
- elementi=strlen(znaci);
- }
- CharSecret(CharSecret *p):Secret() {
- strcpy(znaci, p->znaci);
- elementi=strlen(znaci);
- }
- double simpleEntropy() {
- int brojac=0;
- int glaven=0;
- for(char i='a'; i<='z'; i++) {
- brojac=0;
- for(int j=0; j<elementi; j++) {
- if(i==znaci[j]) {
- brojac++;
- }
- }
- if(brojac==1)
- glaven++;
- }
- return (double)glaven/elementi;
- }
- int total() {
- return elementi;
- }
- friend ostream &operator <<(ostream &o, CharSecret &d) {
- for(int i=0; i<d.elementi; i++)
- o<<d.znaci[i];
- o<<" Simple entropy: "<<d.simpleEntropy()<<" Total: "<<d.total();
- return o;
- }
- };
- void process(Secret ** secrets, int n) {
- double maxE=0;
- int index;
- for(int i=0; i<n; i++) {
- if(secrets[i]->simpleEntropy()>maxE) {
- maxE=secrets[i]->simpleEntropy();
- index=i;
- }
- }
- DigitSecret *temp1=dynamic_cast<DigitSecret*>(secrets[index]);
- CharSecret *temp2=dynamic_cast<CharSecret*>(secrets[index]);
- if(temp1!=0) {
- DigitSecret nov(temp1);
- cout<<nov;
- } else {
- CharSecret nov(temp2);
- cout<<nov;
- }
- }
- void printAll (Secret ** secrets, int n) {
- for(int i=0; i<n; i++) {
- DigitSecret *temp1=dynamic_cast<DigitSecret*>(secrets[i]);
- CharSecret *temp2=dynamic_cast<CharSecret*>(secrets[i]);
- if(temp1!=0) {
- DigitSecret nov(temp1);
- cout<<nov<<endl;
- } else {
- CharSecret nov(temp2);
- cout<<nov<<endl;
- }
- }
- }
- int main() {
- int n;
- cin >> n;
- if(n == 0) {
- cout << "Constructors" << endl;
- int numbers [] = {1,2,3,4,5};
- DigitSecret ds(numbers,5);
- CharSecret cs("abcabc");
- cout << "OK" << endl;
- } else if(n == 1) {
- cout << "operator <<" << endl;
- int numbers [] = {1,2,3,4,5};
- DigitSecret ds(numbers,5);
- CharSecret cs("abcabc");
- cout << ds << endl;
- cout << cs << endl;
- } else if(n == 2) {
- cout << "== and !=" << endl;
- int numbers [] = {1,2,3,4,5};
- DigitSecret ds(numbers,5);
- CharSecret cs("abcabc");
- CharSecret css("abcabc");
- cout << (ds == cs) << endl;
- cout << (cs != ds) << endl;
- cout << (cs == css) << endl;
- cout << (cs != css) << endl;
- } else if(n == 3) {
- cout << "Secret processor" << endl;
- int numbers1 [] = {1,2,3,4,5,6,4,3,2,1,1,2,3,4,5};
- DigitSecret ds1(numbers1,15);
- int numbers2 [] = {1,2,3,4,5,0,0,0,5,5,4,4,3,3,2};
- DigitSecret ds2(numbers2,15);
- int numbers3 [] = {1,0,9,4,3,8,4,0,9,3,1,4,3,2,1,4,4,3,7,2};
- DigitSecret ds3(numbers3,20);
- CharSecret cs1("fhdaieowujkfjdsafjdsakjhueiqoyroq");
- CharSecret cs2("nvzcfsadrqipqhfjdfncxoqw");
- CharSecret cs3("uyoihfdsanmqeqrzvdhfeqyrq");
- Secret** s = new Secret*[6];
- s[0] = &ds1;
- s[1] = &ds2;
- s[2] = &ds3;
- s[3] = &cs1;
- s[4] = &cs2;
- s[5] = &cs3;
- process(s,6);
- delete [] s;
- } else if (n==4) {
- cout << "Print all secrets" << endl;
- int numbers1 [] = {1,2,3,4,5,5,4,3,2,1,1,2,3,4,5};
- DigitSecret ds1(numbers1,15);
- int numbers2 [] = {1,2,3,4,5,0,0,0,5,5,4,4,3,3,2};
- DigitSecret ds2(numbers2,15);
- int numbers3 [] = {1,0,9,4,3,8,4,0,9,3,1,4,3,2,1,4,4,3,7,2};
- DigitSecret ds3(numbers3,20);
- CharSecret cs1("fhdaieowujkfjdsafjdsakjhueiqoyroq");
- CharSecret cs2("nvzcfsadrqipqhfjdfncxoqw");
- CharSecret cs3("uyoihfdsanmqeqrzvdhfeqyrq");
- Secret** s = new Secret*[6];
- s[0] = &ds1;
- s[1] = &ds2;
- s[2] = &ds3;
- s[3] = &cs1;
- s[4] = &cs2;
- s[5] = &cs3;
- printAll(s,6);
- delete [] s;
- }
- return 0;
- }
- //25. Shapes
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Shape
- {
- protected:
- int a;
- public:
- Shape(){}
- Shape(int a)
- {
- this->a=a;
- }
- virtual double plostina()=0;
- virtual void pecati(){}
- virtual int getType()=0;
- };
- class Square: public Shape
- {
- public:
- Square(int a):Shape(a){}
- double plostina()
- {
- return a*a;
- }
- void pecati()
- {
- cout<<"Kvadrat so plostina = "<<plostina()<<endl;
- }
- int getType()
- {
- return 1;
- }
- };
- class Circle: public Shape
- {
- public:
- Circle(int a):Shape(a){};
- double plostina()
- {
- return 3.14*a*a;
- }
- void pecati()
- {
- cout<<"Krug so plostina = "<<plostina()<<endl;
- }
- int getType()
- {
- return 2;
- }
- };
- class Triangle: public Shape
- {
- public:
- Triangle(int a):Shape(a){};
- double plostina()
- {
- return (sqrt(3)/4)*a*a;
- }
- void pecati()
- {
- cout<<"Triagolnik so plostina = "<<plostina()<<endl;
- }
- int getType()
- {
- return 3;
- }
- };
- void checkNumTypes(Shape** niza, int n)
- {
- int kvadrati, krugovi, triagolnici;
- kvadrati=krugovi=triagolnici=0;
- for(int i=0; i<n; i++)
- {
- if(niza[i]->getType()==1)
- kvadrati++;
- else if(niza[i]->getType()==2)
- krugovi++;
- else triagolnici++;
- }
- cout<<"Broj na kvadrati vo nizata = "<<kvadrati<<endl;
- cout<<"Broj na krugovi vo nizata = "<<krugovi<<endl;
- cout<<"Broj na triagolnici vo nizata = "<<triagolnici<<endl;
- }
- int main(){
- int n;
- cin >> n;
- Shape **pokazhuvachi;
- pokazhuvachi=new Shape*[n];
- //TODO: alociraj memorija so golemina n za prethodno navedenata niza
- int classType;
- int side;
- //TODO: konstruiraj for ciklus so chija pomosh ke ja popolnish nizata
- for(int i = 0; i < n; ++i){
- cin >> classType;
- cin >> side;
- if(classType==1)
- pokazhuvachi[i]=new Square(side);
- else if(classType==2)
- pokazhuvachi[i]=new Circle(side);
- else
- pokazhuvachi[i]=new Triangle(side);
- }
- for(int i = 0; i < n; ++i){
- pokazhuvachi[i]->pecati();
- }
- checkNumTypes(pokazhuvachi, n);
- return 0;
- }
- //26. Трансакции
- #include<iostream>
- #include<cstring>
- using namespace std;
- class InvalidDataException
- {
- private:
- int den;
- int mesec;
- int godina;
- public:
- InvalidDataException(int d, int m, int g)
- {
- den=d;
- mesec=m;
- godina=g;
- }
- void message()
- {
- cout<<"Invalid Date "<<den<<"/"<<mesec<<"/"<<godina<<endl;
- }
- };
- class NotSupportedCurrencyException
- {
- private:
- char currency[3];
- public:
- NotSupportedCurrencyException(char *c)
- {
- strcpy(currency, c);
- }
- void message()
- {
- cout<<currency<<" is not a supported currency"<<endl;
- }
- };
- class Transakcija
- {
- protected:
- int den;
- int mesec;
- int godina;
- double parichenIznos;
- static double EUR;
- static double USD;
- public:
- Transakcija(int d, int m, int g, double p)
- {
- if(d<1 || d>31 || m<1 || m>12)
- throw InvalidDataException(d, m, g);
- den=d;
- mesec=m;
- godina=g;
- parichenIznos=p;
- }
- static void setEUR(double E)
- {
- EUR=E;
- }
- static void setUSD(double U)
- {
- USD=U;
- }
- static double getEUR()
- {
- return EUR;
- }
- static double getUSD()
- {
- return USD;
- }
- virtual double voDenari()=0;
- virtual double voEvra()=0;
- virtual double voDolari()=0;
- virtual void pecati() {}
- virtual ~Transakcija() {}
- };
- double Transakcija::EUR=61;
- double Transakcija::USD=50;
- class DenarskaTransakcija: public Transakcija
- {
- public:
- DenarskaTransakcija(int d, int m, int g, double iznos):Transakcija(d, m, g, iznos) {}
- double voDenari()
- {
- return parichenIznos;
- }
- double voEvra()
- {
- return parichenIznos/EUR;
- }
- double voDolari()
- {
- return parichenIznos/USD;
- }
- void pecati()
- {
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<parichenIznos<<" MKD"<<endl;
- }
- };
- class DeviznaTransakcija: public Transakcija
- {
- private:
- char valuta[3];
- public:
- DeviznaTransakcija(int d, int m, int g, double iznos,char* v):Transakcija(d, m, g, (int)iznos)
- {
- if(strcmp(v,"EUR")==0 || strcmp(v,"USD")==0)
- {
- strcpy(valuta, v);
- }
- else
- throw NotSupportedCurrencyException(v);
- }
- double voDenari()
- {
- if(strcmp(valuta, "EUR")==0)
- return parichenIznos*EUR;
- else if(strcmp(valuta, "USD")==0)
- return parichenIznos*USD;
- else
- return parichenIznos;
- }
- double voEvra()
- {
- return voDenari()/EUR;
- }
- double voDolari()
- {
- return voDenari()/USD;
- }
- void pecati()
- {
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<parichenIznos<<" "<<valuta<<endl;
- }
- };
- class Smetka
- {
- private:
- Transakcija **transakcii;
- int brojTransakcii;
- char IDsmetka[50];
- double saldo;
- public:
- Smetka(const char *ID, double sal)
- {
- strcpy(IDsmetka, ID);
- saldo=sal;
- transakcii=new Transakcija*[0];
- brojTransakcii=0;
- }
- Smetka &operator += (Transakcija *t)
- {
- Transakcija **temp=new Transakcija*[brojTransakcii+1];
- for(int i=0; i<brojTransakcii; i++)
- {
- temp[i]=transakcii[i];
- }
- temp[brojTransakcii++]=t;
- transakcii=temp;
- return *this;
- }
- void izvestajVoDenari()
- {
- double vk=saldo;
- for(int i=0; i<brojTransakcii; i++)
- {
- vk+=transakcii[i]->voDenari();
- }
- cout<<"Korisnikot so smetka: "<<IDsmetka<<" ima momentalno saldo od "<<vk<<" MKD"<<endl;
- }
- void izvestajVoEvra()
- {
- double vk=saldo/Transakcija::getEUR();
- for(int i=0; i<brojTransakcii; i++)
- {
- vk+=transakcii[i]->voEvra();
- }
- cout<<"Korisnikot so smetka: "<<IDsmetka<<" ima momentalno saldo od "<<vk<<" EUR"<<endl;
- }
- void izvestajVoDolari()
- {
- double vk=saldo/Transakcija::getUSD();
- for(int i=0; i<brojTransakcii; i++)
- {
- vk+=transakcii[i]->voDolari();
- }
- cout<<"Korisnikot so smetka: "<<IDsmetka<<" ima momentalno saldo od "<<vk<<" USD"<<endl;
- }
- void pecatiTransakcii()
- {
- for(int i=0; i<brojTransakcii; i++)
- {
- transakcii[i]->pecati();
- }
- }
- ~Smetka()
- {
- for(int i=0; i<brojTransakcii; i++)
- {
- delete transakcii[i];
- }
- delete [] transakcii;
- }
- };
- int main () {
- Smetka s ("300047024112789",1500);
- int n, den, mesec, godina, tip;
- double iznos;
- char valuta [3];
- cin>>n;
- cout<<"===VNESUVANJE NA TRANSAKCIITE I SPRAVUVANJE SO ISKLUCOCI==="<<endl;
- for (int i=0;i<n;i++){
- cin>>tip>>den>>mesec>>godina>>iznos;
- if (tip==2){
- cin>>valuta;
- try
- {
- Transakcija * t = new DeviznaTransakcija(den,mesec,godina,iznos,valuta);
- s+=t;
- }
- catch (InvalidDataException id)
- {
- id.message();
- }
- catch(NotSupportedCurrencyException c)
- {
- c.message();
- }
- //delete t;
- }
- else {
- try
- {
- Transakcija * t = new DenarskaTransakcija(den,mesec,godina,iznos);
- s+=t;
- }
- catch(InvalidDataException id)
- {
- id.message();
- }
- catch(NotSupportedCurrencyException c)
- {
- c.message();
- }
- //delete t;
- }
- }
- cout<<"===PECHATENJE NA SITE TRANSAKCII==="<<endl;
- s.pecatiTransakcii();
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
- s.izvestajVoDenari();
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO EVRA==="<<endl;
- s.izvestajVoEvra();
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DOLARI==="<<endl;
- s.izvestajVoDolari();
- cout<<"\n===PROMENA NA KURSOT NA EVROTO I DOLAROT===\n"<<endl;
- double newEUR, newUSD;
- cin>>newEUR>>newUSD;
- Transakcija::setEUR(newEUR);
- Transakcija::setUSD(newUSD);
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
- s.izvestajVoDenari();
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO EVRA==="<<endl;
- s.izvestajVoEvra();
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DOLARI==="<<endl;
- s.izvestajVoDolari();
- return 0;
- }
- //27. Трасаккции (simple version)
- #include<iostream>
- #include<cstring>
- using namespace std;
- class InvalidDataException
- {
- private:
- int den;
- int mesec;
- int godina;
- public:
- InvalidDataException(int d, int m, int g)
- {
- den=d;
- mesec=m;
- godina=g;
- }
- void message()
- {
- cout<<"Invalid Date "<<den<<"/"<<mesec<<"/"<<godina<<endl;
- }
- };
- class NotSupportedCurrencyException
- {
- private:
- char currency[3];
- public:
- NotSupportedCurrencyException(char *c)
- {
- strcpy(currency, c);
- }
- void message()
- {
- cout<<currency<<" is not a supported currency"<<endl;
- }
- };
- class Transakcija
- {
- protected:
- int den;
- int mesec;
- int godina;
- double parichenIznos;
- static double EUR;
- static double USD;
- public:
- Transakcija(int d, int m, int g, double p)
- {
- if(d<1 || d>31 || m<1 || m>12)
- throw InvalidDataException(d, m, g);
- den=d;
- mesec=m;
- godina=g;
- parichenIznos=p;
- }
- static void setEUR(double E)
- {
- EUR=E;
- }
- static void setUSD(double U)
- {
- USD=U;
- }
- virtual double voDenari()=0;
- virtual void pecati() {}
- virtual ~Transakcija() {}
- };
- double Transakcija::EUR=61;
- double Transakcija::USD=50;
- class DenarskaTransakcija: public Transakcija
- {
- public:
- DenarskaTransakcija(int d, int m, int g, double iznos):Transakcija(d, m, g, iznos) {}
- double voDenari()
- {
- return parichenIznos;
- }
- void pecati()
- {
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<parichenIznos<<" MKD"<<endl;
- }
- };
- class DeviznaTransakcija: public Transakcija
- {
- private:
- char valuta[3];
- public:
- DeviznaTransakcija(int d, int m, int g, double iznos,char* v):Transakcija(d, m, g, iznos)
- {
- if(strcmp(v,"EUR")==0 || strcmp(v,"USD")==0)
- strcpy(valuta, v);
- else
- throw NotSupportedCurrencyException(v);
- }
- double voDenari()
- {
- if(strcmp(valuta, "EUR")==0)
- return parichenIznos*EUR;
- else if(strcmp(valuta, "USD")==0)
- return parichenIznos*USD;
- else
- return parichenIznos;
- }
- void pecati()
- {
- cout<<den<<"/"<<mesec<<"/"<<godina<<" "<<parichenIznos<<" "<<valuta<<endl;
- }
- };
- class Smetka
- {
- private:
- Transakcija **transakcii;
- int brojTransakcii;
- char IDsmetka[50];
- double saldo;
- public:
- Smetka(const char *ID, double sal)
- {
- strcpy(IDsmetka, ID);
- saldo=sal;
- transakcii=new Transakcija*[0];
- brojTransakcii=0;
- }
- Smetka &operator += (Transakcija *t)
- {
- Transakcija **temp=new Transakcija*[brojTransakcii+1];
- for(int i=0; i<brojTransakcii; i++)
- {
- temp[i]=transakcii[i];
- }
- temp[brojTransakcii++]=t;
- transakcii=temp;
- return *this;
- }
- void izvestajVoDenari()
- {
- double vk=saldo;
- for(int i=0; i<brojTransakcii; i++)
- {
- vk+=transakcii[i]->voDenari();
- }
- cout<<"Korisnikot so smetka: "<<IDsmetka<<" ima momentalno saldo od "<<vk<<" MKD"<<endl;
- }
- void pecatiTransakcii()
- {
- for(int i=0; i<brojTransakcii; i++)
- {
- transakcii[i]->pecati();
- }
- }
- ~Smetka()
- {
- for(int i=0; i<brojTransakcii; i++)
- {
- delete transakcii[i];
- }
- delete [] transakcii;
- }
- };
- int main ()
- {
- Smetka s ("300047024112789",1500);
- int n, den, mesec, godina, tip;
- double iznos;
- char valuta [3];
- cin>>n;
- cout<<"===VNESUVANJE NA TRANSAKCIITE I SPRAVUVANJE SO ISKLUCOCI==="<<endl;
- for (int i=0; i<n; i++)
- {
- cin>>tip>>den>>mesec>>godina>>iznos;
- if (tip==2)
- {
- cin>>valuta;
- try
- {
- Transakcija * t = new DeviznaTransakcija(den,mesec,godina,iznos,valuta);
- s+=t;
- }
- catch (InvalidDataException id)
- {
- id.message();
- }
- catch(NotSupportedCurrencyException c)
- {
- c.message();
- }
- //delete t;
- }
- else
- {
- try
- {
- Transakcija * t = new DenarskaTransakcija(den,mesec,godina,iznos);
- s+=t;
- }
- catch(InvalidDataException id)
- {
- id.message();
- }
- catch(NotSupportedCurrencyException c)
- {
- c.message();
- }
- //delete t;
- }
- }
- cout<<"===PECHATENJE NA SITE TRANSAKCII==="<<endl;
- s.pecatiTransakcii();
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
- s.izvestajVoDenari();
- cout<<"\n===PROMENA NA KURSOT NA EVROTO I DOLAROT===\n"<<endl;
- double newEUR, newUSD;
- cin>>newEUR>>newUSD;
- Transakcija::setEUR(newEUR);
- Transakcija::setUSD(newUSD);
- cout<<"===IZVESHTAJ ZA SOSTOJBATA NA SMETKATA VO DENARI==="<<endl;
- s.izvestajVoDenari();
- return 0;
- }
- //28. Броеви (само искчучоци)
- #include <iostream>
- #include <cstring>
- using namespace std;
- /*EXCEPTION*/
- class ArithmeticException
- {
- private:
- char text[50];
- public:
- ArithmeticException(const char *t)
- {
- strcpy(text, t);
- }
- void print()
- {
- cout<<text<<endl;
- }
- };
- class NumbersNotDivisibleException
- {
- private:
- int broj;
- public:
- NumbersNotDivisibleException(int a)
- {
- broj=a;
- }
- void print()
- {
- cout<<"Division by "<<broj<<" is not supported"<<endl;
- }
- };
- class ArrayFullException
- {
- private:
- char text[50];
- public:
- ArrayFullException(const char *t)
- {
- strcpy(text, t);
- }
- void print()
- {
- cout<<text<<endl;
- }
- };
- class IndexOutOfBoundsException
- {
- private:
- int broj;
- public:
- IndexOutOfBoundsException(int a)
- {
- broj=a;
- }
- void print()
- {
- cout<<"Index "<<broj<<" is out of bounds"<<endl;
- }
- };
- class NumberIsNotPositiveException
- {
- private:
- int broj;
- public:
- NumberIsNotPositiveException(int a)
- {
- broj=a;
- }
- void print()
- {
- cout<<"Number "<<broj<<" is not positive integer"<<endl;
- }
- };
- class PositiveIntegers
- {
- private:
- int *broevi;
- int elementi;
- int capacity;
- public:
- PositiveIntegers()
- {
- broevi=new int[0];
- elementi=0;
- }
- PositiveIntegers(int c)
- {
- broevi=new int[0];
- elementi=0;
- capacity=c;
- }
- void increaseCapacity(int c)
- {
- capacity+=c;
- }
- PositiveIntegers &operator += (const int &a)
- {
- if(elementi+1>capacity)
- throw ArrayFullException("The array is full. Increase the capacity");
- else if(a<=0)
- throw NumberIsNotPositiveException(a);
- int *temp=new int[elementi];
- for(int i=0; i<elementi; i++)
- {
- temp[i]=broevi[i];
- }
- delete [] broevi;
- broevi=new int[elementi+1];
- for(int i=0; i<elementi; i++)
- {
- broevi[i]=temp[i];
- }
- broevi[elementi++]=a;
- delete [] temp;
- return *this;
- }
- PositiveIntegers (const PositiveIntegers &p)
- {
- broevi=new int[p.elementi];
- elementi=p.elementi;
- capacity=p.capacity;
- for(int i=0; i<elementi; i++)
- {
- broevi[i]=p.broevi[i];
- }
- }
- PositiveIntegers &operator = (const PositiveIntegers &p)
- {
- delete [] broevi;
- broevi=new int[p.elementi];
- elementi=p.elementi;
- capacity=p.capacity;
- for(int i=0; i<elementi; i++)
- {
- broevi[i]=p.broevi[i];
- }
- return *this;
- }
- PositiveIntegers operator * (const int a)
- {
- PositiveIntegers nov(*this);
- for(int i=0; i<elementi; i++)
- {
- nov.broevi[i]*=a;
- }
- return nov;
- }
- PositiveIntegers operator / (int a)
- {
- if(a==0)
- throw ArithmeticException("Division by zero is not allowed");
- PositiveIntegers nov(*this);
- for(int i=0; i<elementi; i++)
- {
- if(nov.broevi[i]%a!=0)
- throw NumbersNotDivisibleException(a);
- }
- for(int i=0; i<elementi; i++)
- {
- nov.broevi[i]/=a;
- }
- return nov;
- }
- int &operator [] (int a)
- {
- if(a<0 || a>=elementi)
- throw IndexOutOfBoundsException(a);
- return broevi[a];
- }
- void print()
- {
- cout<<"Size: "<<elementi<<" Capacity: "<<capacity<<" Numbers: ";
- for(int i=0; i<elementi; i++)
- {
- cout<<broevi[i]<<" ";
- }
- cout<<endl;
- }
- };
- int main()
- {
- int n, capacity;
- cin>>n>>capacity;
- PositiveIntegers pi (capacity);
- for(int i=0; i<n; i++)
- {
- int number;
- cin>>number;
- try
- {
- pi+=number;
- }
- catch(ArrayFullException af)
- {
- af.print();
- }
- catch(NumberIsNotPositiveException np)
- {
- np.print();
- }
- }
- cout<<"===FIRST ATTEMPT TO ADD NUMBERS==="<<endl;
- pi.print();
- int incCapacity;
- cin>>incCapacity;
- pi.increaseCapacity(incCapacity);
- cout<<"===INCREASING CAPACITY==="<<endl;
- pi.print();
- int n1;
- cin>>n1;
- for(int i=0; i<n1; i++)
- {
- int number;
- cin>>number;
- try
- {
- pi+=number;
- }
- catch(ArrayFullException af)
- {
- af.print();
- }
- catch(NumberIsNotPositiveException np)
- {
- np.print();
- }
- }
- cout<<"===SECOND ATTEMPT TO ADD NUMBERS==="<<endl;
- pi.print();
- PositiveIntegers pi1;
- cout<<"===TESTING DIVISION==="<<endl;
- try
- {
- pi1=pi/0;
- pi1.print();
- }
- catch(NumbersNotDivisibleException nd)
- {
- nd.print();
- }
- catch(ArithmeticException ar)
- {
- ar.print();
- }
- try
- {
- pi1=pi/1;
- pi1.print();
- }
- catch(NumbersNotDivisibleException nd)
- {
- nd.print();
- }
- catch(ArithmeticException ar)
- {
- ar.print();
- }
- try
- {
- pi1=pi/2;
- pi1.print();
- }
- catch(NumbersNotDivisibleException nd)
- {
- nd.print();
- }
- catch(ArithmeticException ar)
- {
- ar.print();
- }
- cout<<"===TESTING MULTIPLICATION==="<<endl;
- pi1=pi*3;
- pi1.print();
- cout<<"===TESTING [] ==="<<endl;
- try
- {
- cout<<"PositiveIntegers[-1] = "<<pi[-1]<<endl;
- }
- catch(IndexOutOfBoundsException ib)
- {
- ib.print();
- }
- try
- {
- cout<<"PositiveIntegers[2] = "<<pi[2]<<endl;
- }
- catch(IndexOutOfBoundsException ib)
- {
- ib.print();
- }
- try
- {
- cout<<"PositiveIntegers[3] = "<<pi[3]<<endl;
- }
- catch(IndexOutOfBoundsException ib)
- {
- ib.print();
- }
- try
- {
- cout<<"PositiveIntegers[12] = "<<pi[12]<<endl;
- }
- catch(IndexOutOfBoundsException ib)
- {
- ib.print();
- }
- return 0;
- }
- //29. Едноставен датотечен систем
- #include<iostream>
- #include<cstring>
- using namespace std;
- class FileAlreadyExists
- {
- private:
- char text[50];
- public:
- FileAlreadyExists(const char *t)
- {
- strcpy(text, t);
- }
- void message(){
- cout<<"File with name "<<text<<" already exists in this folder"<<endl;
- }
- };
- class FileInformation
- {
- protected:
- char ime[50];
- double golemina;
- bool read;
- bool write;
- bool execute;
- public:
- FileInformation(){}
- FileInformation(char *i, double g, bool r, bool w, bool e)
- {
- strcpy(ime, i);
- golemina=g;
- read=r;
- write=w;
- execute=e;
- }
- virtual void printFileInfo() {}
- virtual double totalFileMemory()=0;
- bool checkPermissionsAndSize (bool r, bool w, bool x, double size)
- {
- return (read==r&&write==w&&execute==x&&golemina<size);
- }
- char *getIme()
- {
- return ime;
- }
- };
- bool operator > (FileInformation &f1, FileInformation &f2)
- {
- return f1.totalFileMemory()>f2.totalFileMemory();
- }
- class File:public FileInformation
- {
- public:
- File():FileInformation(){}
- File(char *i, double g, bool r, bool w, bool e):FileInformation(i, g, r, w, e) {}
- void printFileInfo()
- {
- cout<<"-";
- if(read)
- cout<<"r";
- else
- cout<<"-";
- if(write)
- cout<<"w";
- else
- cout<<"-";
- if(execute)
- cout<<"x ";
- else
- cout<<"- ";
- cout<<ime<<" "<<golemina<<endl;
- }
- double totalFileMemory()
- {
- return golemina;
- }
- bool sameName(File &f)
- {
- return (strcmp(ime, f.ime)==0);
- }
- };
- class Folder:public FileInformation
- {
- private:
- File *fajl;
- int brojFajlovi;
- public:
- Folder(char *i, bool r, bool w, bool e):FileInformation(i, 0, r, w, e)
- {
- fajl=new File[0];
- brojFajlovi=0;
- }
- Folder &operator += (File &f)
- {
- for(int i=0; i<brojFajlovi; i++)
- {
- if(fajl[i].sameName(f))
- throw FileAlreadyExists(f.getIme());
- }
- File *temp=new File[brojFajlovi];
- for(int i=0; i<brojFajlovi; i++)
- {
- temp[i]=fajl[i];
- }
- delete [] fajl;
- fajl=new File[brojFajlovi+1];
- for(int i=0; i<brojFajlovi; i++)
- {
- fajl[i]=temp[i];
- }
- fajl[brojFajlovi++]=f;
- golemina+=f.totalFileMemory();
- delete [] temp;
- return *this;
- }
- File* getFajlovi()
- {
- return fajl;
- }
- int getBrojFajlovi()
- {
- return brojFajlovi;
- }
- void printFileInfo()
- {
- cout<<"d";
- if(read)
- cout<<"r";
- else
- cout<<"-";
- if(write)
- cout<<"w";
- else
- cout<<"-";
- if(execute)
- cout<<"x ";
- else
- cout<<"- ";
- cout<<ime<<" "<<golemina<<endl;
- for(int i=0; i<brojFajlovi; i++)
- {
- cout<<" ";
- fajl[i].printFileInfo();
- }
- }
- double totalFileMemory()
- {
- double vk=0;
- for(int i=0; i<brojFajlovi; i++)
- {
- vk+=fajl[i].totalFileMemory();
- }
- return vk;
- }
- };
- class FileSystem
- {
- public:
- static void printFileSystem(FileInformation ** fi, int n)
- {
- for(int i=0; i<n; i++)
- {
- fi[i]->printFileInfo();
- }
- }
- static void printFileWithMaxSize(FileInformation **fi, int n)
- {
- double maxMem=0;
- int index;
- for(int i=0; i<n; i++)
- {
- if(maxMem<fi[i]->totalFileMemory())
- {
- maxMem=fi[i]->totalFileMemory();
- index=i;
- }
- }
- fi[index]->printFileInfo();
- }
- static void printFilesLessThanWithPermissions(FileInformation ** fi, int n, bool r, bool w, bool x, double size)
- {
- for(int i=0; i<n; i++)
- {
- Folder *temp=dynamic_cast<Folder*>(fi[i]);
- if(temp!=0)
- for(int j=0; j<temp->getBrojFajlovi(); j++)
- {
- if(temp->getFajlovi()[j].checkPermissionsAndSize(r, w, x, size))
- temp->getFajlovi()[j].printFileInfo();
- }
- else
- {
- File *temp=dynamic_cast<File*>(fi[i]);
- if(temp->checkPermissionsAndSize(r, w, x, size))
- temp->printFileInfo();
- }
- }
- }
- };
- int main()
- {
- int n;
- cin>>n;
- FileInformation ** fi = new FileInformation * [n];
- for (int i=0; i<n; i++)
- {
- char name [50];
- bool read, write, execute;
- double size;
- int type;
- cin>>type;
- if (type==1) //File
- {
- cin>>name>>size>>read>>write>>execute;
- fi[i] = new File(name,size,read,write,execute);
- }
- else //Folder
- {
- cin>>name>>read>>write>>execute;
- fi[i] = new Folder(name,read,write,execute);
- int N;
- cin>>N;
- for (int j=0; j<N; j++)
- {
- //cin>>N;
- cin>>name>>size>>read>>write>>execute;
- File f = File(name,size,read,write,execute);
- Folder * folder = dynamic_cast<Folder *>(fi[i]);
- try{
- (*folder)+=f;
- }
- catch(FileAlreadyExists fe)
- {
- fe.message();
- }
- }
- }
- }
- cout<<"===TESTING printFileSystem()==="<<endl;
- FileSystem::printFileSystem(fi,n);
- cout<<"===TESTING printFileWithMaxSize()==="<<endl;
- FileSystem::printFileWithMaxSize(fi,n);
- cout<<"===TESTING printFilesLessThanWithPermissions()==="<<endl;
- FileSystem::printFilesLessThanWithPermissions(fi,n,1,1,1,20.5);
- return 0;
- }
- //30. Скијачки центар
- #include<stdio.h>
- #include<string.h>
- typedef struct SkiLift{
- char ime[20];
- int max_skijaci;
- int voUpotreba;
- }skiLift;
- typedef struct SkiCenter {
- char ime[20];
- char drzava[20];
- skiLift niza[20];
- int br_lifts;
- }skiCenter;
- int kapacitet(skiCenter sc)
- {
- int i;
- int tmp = 0;
- for (i = 0; i < sc.br_lifts; i++)
- {
- if (sc.niza[i].voUpotreba == 1)
- {
- tmp += sc.niza[i].max_skijaci;
- }
- }
- return tmp;
- }
- void najgolemKapacitet(skiCenter *sc, int n)
- {
- int tmp, i, j, max, max_ind;
- max = 0;
- max_ind = 0;
- for (i = 0; i < n; i++)
- {
- tmp = kapacitet(sc[i]);
- if ((tmp > max) || (tmp == max&&sc[i].br_lifts > sc[max_ind].br_lifts)) { max = tmp; max_ind = i; }
- }
- printf("%s\n%s\n%d\n", sc[max_ind].ime, sc[max_ind].drzava, max);
- }
- int main()
- {
- int i, j, n, broj;
- skiCenter sc[20];
- scanf("%d", &n);
- for (i = 0; i < n; i++){
- //printf("Ime:");
- scanf("%s", sc[i].ime);
- //printf("\nDrzava:");
- scanf("%s", sc[i].drzava);
- scanf("%d", &sc[i].br_lifts);
- for (j = 0; j < sc[i].br_lifts; j++){
- scanf("%s", sc[i].niza[j].ime);
- scanf("%d", &sc[i].niza[j].max_skijaci);
- scanf("%d", &sc[i].niza[j].voUpotreba);
- }
- }
- najgolemKapacitet(sc, n);
- return 0;
- }
- //31. Компјутерска игра
- #include<iostream>
- using namespace std;
- struct Igrac
- {
- char ime[15];
- int nivo;
- int osvoenipoeni;
- };
- struct KompjuterskaIgra
- {
- char ime[20];
- Igrac igraci[20];
- int broj;
- };
- void najdobarIgrac(KompjuterskaIgra *lista,int n)
- {
- int maxbroj=0;
- int indeks1=0;
- for(int i=0;i<n;i++)
- {
- if(lista[i].broj>=maxbroj)
- {
- maxbroj=lista[i].broj;
- indeks1=i;
- }
- }
- int maxpoeni=0;
- int indeks=0;
- int maxnivo=0;
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<lista[i].broj;j++)
- {
- if(lista[i].igraci[j].osvoenipoeni>maxpoeni)
- {
- maxpoeni=lista[i].igraci[j].osvoenipoeni;
- indeks=j;
- maxnivo=lista[i].igraci[j].nivo;
- }else if(lista[i].igraci[j].osvoenipoeni==maxpoeni)
- {
- if(lista[i].igraci[j].nivo>maxnivo)
- {
- maxnivo=lista[i].igraci[j].nivo;
- maxpoeni=lista[i].igraci[j].osvoenipoeni;
- indeks=j;
- }
- }
- }
- }
- cout<<"Najdobar igrac e igracot so korisnicko ime ";
- cout<<lista[indeks1].igraci[indeks].ime<<" koj ja igra igrata "<<lista[indeks1].ime<<endl;
- }
- int main() {
- int n,m;
- char ime[20];
- cin>>n;
- KompjuterskaIgra poleigri[100];
- for (int i=0; i<n; i++) {
- KompjuterskaIgra nova;
- cin>>nova.ime>>nova.broj;
- Igrac pole[30];
- for (int j=0; j<nova.broj; j++) {
- Igrac nov;
- cin>>nov.ime>>nov.nivo>>nov.osvoenipoeni;
- nova.igraci[j]=nov;
- }
- poleigri[i]=nova;
- }
- najdobarIgrac(poleigri,n);
- return 0;
- }
- //32. Железничка станица
- #include<iostream>
- #include <cstring>
- using namespace std;
- struct Voz
- {
- char relacija[50];
- float pat;
- int patnici;
- };
- struct ZeleznickaStanica
- {
- char grad[25];
- Voz vozovi[30];
- int vozBr;
- };
- void najkratkaRelacija(ZeleznickaStanica* zs, int n, char* grad)
- {
- int k;
- char pomRelacija[50];
- int pomPat=999999;
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<zs[i].vozBr; j++)
- {
- char pochetna[25];
- for(k=0; k<25; k++)
- {
- if(zs[i].vozovi[j].relacija[k]=='-')
- break;
- else
- pochetna[k]=zs[i].vozovi[j].relacija[k];
- }
- pochetna[k]='\0';
- if(strcmp(grad,pochetna)==0)
- {
- if(zs[i].vozovi[j].pat<=pomPat)
- {
- pomPat=zs[i].vozovi[j].pat;
- strcpy(pomRelacija,zs[i].vozovi[j].relacija);
- }
- }
- }
- }
- cout<<"Najkratka relacija: "<<pomRelacija<<" ("<<pomPat<<" km)"<<endl;
- }
- int main(){
- int n;
- cin>>n; //se cita brojot na zelezlnichki stanici
- ZeleznickaStanica zStanica[100];
- for (int i=0;i<n;i++){
- //se citaat infomracii za n zelezlnichkite stanici i se zacuvuvaat vo poleto zStanica
- cin>>zStanica[i].grad>>zStanica[i].vozBr;
- for(int j=0; j<zStanica[i].vozBr; j++)
- {
- cin>>zStanica[i].vozovi[j].relacija;
- cin>>zStanica[i].vozovi[j].pat;
- cin>>zStanica[i].vozovi[j].patnici;
- }
- }
- char grad[25];
- cin>>grad;
- najkratkaRelacija(zStanica,n,grad);
- return 0;
- }
- //33. CD
- #include<iostream>
- #include<cstring>
- using namespace std;
- enum tip{pop, rap, rok};
- class Pesna
- {
- char *ime;
- int vreme;
- tip t;
- public:
- Pesna()
- {
- ime=new char[0];
- }
- Pesna(char *i, int v, tip t1)
- {
- ime=new char[strlen(i)+1];
- strcpy(ime,i);
- vreme=v;
- t=t1;
- }
- Pesna(Pesna &p)
- {
- ime=new char[strlen(p.ime)+1];
- strcpy(ime,p.ime);
- vreme=p.vreme;
- t=p.t;
- }
- Pesna& operator =(Pesna &p)
- {
- if(this!=&p)
- {
- delete [] ime;
- ime=new char [strlen(p.ime)+1];
- strcpy(ime,p.ime);
- vreme=p.vreme;
- t=p.t;
- }
- return *this;
- }
- void pecati()
- {
- cout<<"\""<<ime<<"\"-"<<vreme<<"min"<<endl;
- }
- int getVreme()
- {
- return vreme;
- }
- tip getTip()
- {
- return t;
- }
- ~Pesna()
- {
- delete [] ime;
- }
- };
- class CD
- {
- Pesna pesni[10];
- int brojPesni;
- int vremetraenje;
- public:
- CD(int v)
- {
- vremetraenje=v;
- brojPesni=0;
- }
- Pesna& getPesna(int i)
- {
- return pesni[i];
- }
- int getBroj()
- {
- return brojPesni;
- }
- void dodadiPesna (Pesna p)
- {
- int vkupno=0;
- for(int i=0; i<brojPesni; i++)
- {
- vkupno+=pesni[i].getVreme();
- }
- if((vkupno+p.getVreme()<=vremetraenje)&&(brojPesni<10))
- {
- pesni[brojPesni]=p;
- brojPesni++;
- }
- }
- void pecatiPesniPoTip(tip t)
- {
- for(int i=0; i<brojPesni; i++)
- {
- if(pesni[i].getTip()==t)
- {
- pesni[i].pecati();
- }
- }
- }
- };
- int main() {
- // se testira zadacata modularno
- int testCase;
- cin >> testCase;
- int n, minuti, kojtip;
- char ime[50];
- if(testCase == 1) {
- cout << "===== Testiranje na klasata Pesna ======" << endl;
- cin >> ime;
- cin >> minuti;
- cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
- Pesna p(ime,minuti,(tip)kojtip);
- p.pecati();
- } else if(testCase == 2) {
- cout << "===== Testiranje na klasata CD ======" << endl;
- CD omileno(20);
- cin>>n;
- for (int i=0;i<n;i++){
- cin >> ime;
- cin >> minuti;
- cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
- Pesna p(ime,minuti,(tip)kojtip);
- omileno.dodadiPesna(p);
- }
- for (int i=0; i<n; i++)
- (omileno.getPesna(i)).pecati();
- }
- else if(testCase == 3) {
- cout << "===== Testiranje na metodot dodadiPesna() od klasata CD ======" << endl;
- CD omileno(20);
- cin>>n;
- for (int i=0;i<n;i++){
- cin >> ime;
- cin >> minuti;
- cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
- Pesna p(ime,minuti,(tip)kojtip);
- omileno.dodadiPesna(p);
- }
- for (int i=0; i<omileno.getBroj(); i++)
- (omileno.getPesna(i)).pecati();
- }
- else if(testCase == 4) {
- cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
- CD omileno(20);
- cin>>n;
- for (int i=0;i<n;i++){
- cin >> ime;
- cin >> minuti;
- cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
- Pesna p(ime,minuti,(tip)kojtip);
- omileno.dodadiPesna(p);
- }
- cin>>kojtip;
- omileno.pecatiPesniPoTip((tip)kojtip);
- }
- else if(testCase == 5) {
- cout << "===== Testiranje na metodot pecatiPesniPoTip() od klasata CD ======" << endl;
- CD omileno(20);
- cin>>n;
- for (int i=0;i<n;i++){
- cin >> ime;
- cin >> minuti;
- cin >> kojtip; //se vnesuva 0 za POP,1 za RAP i 2 za ROK
- Pesna p(ime,minuti,(tip)kojtip);
- omileno.dodadiPesna(p);
- }
- cin>>kojtip;
- omileno.pecatiPesniPoTip((tip)kojtip);
- }
- return 0;
- }
- //34. Пицерија
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Pica {
- private:
- char ime[15];
- int cena;
- char *sostojki;
- int namaluvanje;
- public:
- Pica() {
- sostojki=new char[0];
- }
- Pica(char *i, int c, char *s, int n) {
- strcpy(ime,i);
- sostojki=new char[strlen(s)+1];
- cena=c;
- strcpy(sostojki, s);
- namaluvanje=n;
- }
- Pica(Pica &p) {
- strcpy(ime,p.ime);
- sostojki=new char[strlen(p.sostojki)+1];
- cena=p.cena;
- strcpy(sostojki, p.sostojki);
- namaluvanje=p.namaluvanje;
- }
- void pecati() {
- cout<<ime<<" - "<<sostojki<<", "<<cena;
- }
- bool istiSe(Pica p) {
- if(strcmp(sostojki,p.sostojki)==0) {
- return true;
- } else return false;
- }
- char *getSostojki() {
- return sostojki;
- }
- int getCena() {
- return cena;
- }
- int getNamaluvanje() {
- return namaluvanje;
- }
- Pica& operator = (Pica &p) {
- if(this!=&p) {
- strcpy(ime,p.ime);
- cena=p.cena;
- delete [] sostojki;
- sostojki=new char[strlen(p.sostojki)+1];
- strcpy(sostojki, p.sostojki);
- namaluvanje=p.namaluvanje;
- }
- return *this;
- }
- ~Pica() {
- delete [] sostojki;
- }
- };
- class Picerija {
- char ime[15];
- Pica *pici;
- int brpici;
- public:
- Picerija() {
- pici=new Pica[0];
- }
- Picerija(char *i, Pica *p, int n) {
- strcpy(ime, i);
- pici = new Pica[n];
- for(int i=0; i<n; i++) {
- pici[i]=p[i];
- }
- brpici=n;
- }
- Picerija(char *i) {
- strcpy(ime,i);
- pici=new Pica[0];
- brpici=0;
- }
- Picerija(Picerija &p) {
- strcpy(ime, p.ime);
- pici=new Pica[p.brpici];
- for(int i=0; i<p.brpici; i++) {
- pici[i]=p.pici[i];
- }
- brpici=p.brpici;
- }
- Picerija &operator = (Picerija &p) {
- if(this!=&p) {
- strcpy(ime,p.ime);
- delete [] pici;
- pici=new Pica[p.brpici];
- for(int i=0; i<p.brpici; i++) {
- pici[i]=p.pici[i];
- }
- brpici=p.brpici;
- }
- return *this;
- }
- void dodadi (Pica &p) {
- bool f=true;
- for(int i=0; i<brpici; i++) {
- if(p.istiSe(pici[i])) {
- f=false;
- }
- }
- if(f) {
- Pica *tmp = new Pica[brpici];
- for(int i=0; i<brpici; i++) {
- tmp[i]=pici[i];
- }
- delete [] pici;
- pici=new Pica[brpici+1];
- for(int i=0; i<brpici; i++) {
- pici[i]=tmp[i];
- }
- pici[brpici]=p;
- ++brpici;
- delete [] tmp;
- }
- }
- void setIme(char *i) {
- strcpy(ime, i);
- }
- char *getIme() {
- return ime;
- }
- void piciNaPromocija() {
- for(int i=0; i<brpici; i++) {
- if(pici[i].getNamaluvanje()>0) {
- pici[i].pecati();
- cout<<" "<<pici[i].getCena()*(100-pici[i].getNamaluvanje())/100<<endl;
- }
- }
- }
- ~Picerija() {
- delete [] pici;
- }
- };
- int main () {
- int n;
- char ime[15];
- cin >> ime;
- cin >> n;
- Picerija p1(ime);
- for(int i = 0; i < n; i++) {
- char imp[100];
- cin.get();
- cin.getline(imp,100);
- int cena;
- cin >> cena;
- char sostojki[100];
- cin.get();
- cin.getline(sostojki,100);
- int popust;
- cin >> popust;
- Pica p(imp,cena,sostojki,popust);
- p1.dodadi(p);
- }
- Picerija p2 = p1;
- cin >> ime;
- p2.setIme(ime);
- char imp[100];
- cin.get();
- cin.getline(imp,100);
- int cena;
- cin >> cena;
- char sostojki[100];
- cin.get();
- cin.getline(sostojki,100);
- int popust;
- cin >> popust;
- Pica p(imp,cena,sostojki,popust);
- p2.dodadi(p);
- cout<<p1.getIme()<<endl;
- cout<<"Pici na promocija:"<<endl;
- p1.piciNaPromocija();
- cout<<p2.getIme()<<endl;
- cout<<"Pici na promocija:"<<endl;
- p2.piciNaPromocija();
- return 0;
- }
- //35. Маратон
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Ucesnik {
- char *ime;
- bool pol;
- int vozrast;
- public:
- Ucesnik() {
- ime=new char[0];
- }
- Ucesnik(char *i, bool p, int v) {
- ime=new char[strlen(i)+1];
- strcpy(ime,i);
- pol=p;
- vozrast=v;
- }
- Ucesnik(Ucesnik &u) {
- ime=new char[strlen(u.ime)+1];
- strcpy(ime,u.ime);
- pol=u.pol;
- vozrast=u.vozrast;
- }
- Ucesnik &operator = (Ucesnik &u) {
- if(this!=&u) {
- delete [] ime;
- ime=new char[strlen(u.ime)+1];
- strcpy(ime,u.ime);
- pol=u.pol;
- vozrast=u.vozrast;
- }
- return *this;
- }
- bool operator > (Ucesnik &u) {
- if(vozrast>u.vozrast) {
- return true;
- } else return false;
- }
- friend ostream &operator << (ostream &os, Ucesnik &u) {
- os<<u.ime<<endl;
- if(!u.pol)
- os<<"zhenski"<<endl;
- else
- os<<"mashki"<<endl;
- os<<u.vozrast;
- return os;
- }
- int getVozrast() {
- return vozrast;
- }
- ~Ucesnik() {
- delete [] ime;
- }
- };
- class Maraton {
- char lokacija[100];
- Ucesnik *ucesnici;
- int broj;
- public:
- Maraton(char *l) {
- strcpy(lokacija,l);
- ucesnici=new Ucesnik[0];
- broj=0;
- }
- Maraton(char *l, Ucesnik *u, int b) {
- ucesnici=new Ucesnik[b];
- strcpy(lokacija,l);
- for(int i=0; i<b; i++) {
- ucesnici[i]=u[i];
- }
- broj=b;
- }
- Maraton(Maraton &m) {
- ucesnici=new Ucesnik[m.broj];
- strcpy(lokacija,m.lokacija);
- for(int i=0; i<m.broj; i++) {
- ucesnici[i]=m.ucesnici[i];
- }
- broj=m.broj;
- }
- Maraton &operator += (Ucesnik &u) {
- Ucesnik *temp=new Ucesnik[broj];
- for(int i=0; i<broj; i++) {
- temp[i]=ucesnici[i];
- }
- delete [] ucesnici;
- ucesnici = new Ucesnik[broj+1];
- for(int i=0; i<broj; i++) {
- ucesnici[i]=temp[i];
- }
- ucesnici[broj]=u;
- broj++;
- delete [] temp;
- return *this;
- }
- float prosecnoVozrast() {
- float suma=0;
- for(int i=0; i<broj; i++) {
- suma+=ucesnici[i].getVozrast();
- }
- return suma/broj;
- }
- void pecatiPomladi(Ucesnik &u) {
- for(int i=0; i<broj; i++) {
- if(ucesnici[i].getVozrast() < u.getVozrast())
- cout<<ucesnici[i]<<endl;
- }
- }
- ~Maraton() {
- delete [] ucesnici;
- }
- };
- int main() {
- char ime[100];
- bool maski;
- int vozrast, n;
- cin >> n;
- char lokacija[100];
- cin >> lokacija;
- Maraton m(lokacija);
- Ucesnik **u = new Ucesnik*[n];
- for(int i = 0; i < n; ++i) {
- cin >> ime >> maski >> vozrast;
- u[i] = new Ucesnik(ime, maski, vozrast);
- m += *u[i];
- }
- m.pecatiPomladi(*u[n - 1]);
- cout << m.prosecnoVozrast() << endl;
- for(int i = 0; i < n; ++i) {
- delete u[i];
- }
- delete [] u;
- return 0;
- }
- //36. Сладолед
- #include <iostream>
- #include <cstring>
- using namespace std;
- class IceCream {
- private:
- char *name;
- char ingredients[100];
- float price;
- int discount;
- void copy(const IceCream &ic) {
- name = new char[strlen(ic.name) + 1];
- strcpy(name, ic.name);
- strncpy(ingredients, ic.ingredients, 99);
- ingredients[99] = '\0';
- price = ic.price;
- discount = ic.discount;
- }
- public:
- IceCream(const char *nm = "", const char *ingr = "", float p = 0) {
- name = new char[strlen(nm) + 1];
- strcpy(name, nm);
- strncpy(ingredients, ingr, 99);
- ingredients[99] = '\0';
- price = p;
- discount = 0;
- }
- IceCream(const IceCream &ic) {
- copy(ic);
- }
- IceCream& operator=(const IceCream &ic) {
- if (this == &ic) return *this;
- delete [] name;
- copy(ic);
- return *this;
- }
- friend ostream& operator<<(ostream &out, const IceCream &ic) {
- out << ic.name << ": ";
- out << ic.ingredients << " ";
- out << ic.price << " ";
- if (ic.discount > 0) {
- out << "(" << ic.price * (100 - ic.discount) / 100 << ")";
- }
- return out;
- }
- void setName(char *n) {
- delete [] name;
- name = new char[strlen(n) + 1];
- strcpy(name, n);
- }
- IceCream& operator++() {
- discount += 5;
- return *this;
- }
- IceCream operator+(const char* extra) {
- char* newName = new char[strlen(name) + strlen(extra) + 4];
- strcat(newName, name);
- strcat(newName, " + ");
- strcat(newName, extra);
- IceCream res(newName, ingredients, price + 10);
- res.setDiscount(discount);
- return res;
- }
- void setName(const char* n) {
- delete [] name;
- name = new char[strlen(n) + 1];
- strcpy(name, n);
- }
- void setDiscount(int d) {
- if(d>=0&&d<=100)
- discount = d;
- }
- ~IceCream() {
- delete [] name;
- }
- };
- class IceCreamShop {
- private:
- char name[50];
- IceCream *icecreams;
- int n;
- void copy(const IceCreamShop &ics) {
- strcpy(name, ics.name);
- n = ics.n;
- icecreams = new IceCream[n];
- for (int i = 0; i < n; ++i) {
- icecreams[i] = ics.icecreams[i];
- }
- }
- public:
- IceCreamShop(char* nm) {
- strcpy(name, nm);
- icecreams = NULL;
- n = 0;
- }
- IceCreamShop(const IceCreamShop &ics) {
- copy(ics);
- }
- IceCreamShop& operator=(const IceCreamShop &ics) {
- if (this == &ics) return *this;
- delete [] icecreams;
- copy(ics);
- return *this;
- }
- ~IceCreamShop() {
- delete [] icecreams;
- }
- IceCreamShop& operator+= (IceCream &ic) {
- IceCream *tmp = icecreams;
- icecreams = new IceCream[n + 1];
- for (int i = 0; i < n; ++i) {
- icecreams[i] = tmp[i];
- }
- icecreams[n] = ic;
- ++n;
- delete [] tmp;
- return *this;
- }
- friend ostream& operator<<(ostream &out, const IceCreamShop &ics) {
- cout << ics.name << endl;
- for (int i = 0; i < ics.n; ++i) {
- out << ics.icecreams[i] << endl;
- }
- return out;
- }
- };
- int main() {
- char name[100];
- char ingr[100];
- float price;
- int discount;
- int testCase;
- cin >> testCase;
- cin.get();
- if(testCase == 1) {
- cout << "====== TESTING IceCream CLASS ======" << endl;
- cin.getline(name,100);
- cin.getline(ingr,100);
- cin >> price;
- cin >> discount;
- cout << "CONSTRUCTOR" << endl;
- IceCream ic1(name, ingr, price);
- ic1.setDiscount(discount);
- cin.get();
- cin.getline(name,100);
- cin.getline(ingr,100);
- cin >> price;
- cin >> discount;
- IceCream ic2(name, ingr, price);
- ic2.setDiscount(discount);
- cout << "OPERATOR <<" << endl;
- cout << ic1 << endl;
- cout << ic2 << endl;
- cout << "OPERATOR ++" << endl;
- ++ic1;
- cout << ic1 << endl;
- cout << "OPERATOR +" << endl;
- IceCream ic3 = ic2 + "chocolate";
- cout << ic3 << endl;
- } else if(testCase == 2) {
- cout << "====== TESTING IceCream CONSTRUCTORS ======" << endl;
- cin.getline(name,100);
- cin.getline(ingr,100);
- cin >> price;
- //cin >> discount;
- cout << "CONSTRUCTOR" << endl;
- IceCream ic1(name, ingr, price);
- cout << ic1 << endl;
- cout << "COPY CONSTRUCTOR" << endl;
- IceCream ic2(ic1);
- cin.get();
- cin.getline(name,100);
- ic2.setName(name);
- cout << ic1 << endl;
- cout << ic2 << endl;
- cout << "OPERATOR =" << endl;
- ic1 = ic2;
- cin.getline(name,100);
- ic2.setName(name);
- cout << ic1 << endl;
- cout << ic2 << endl;
- cin >> discount;
- ic1.setDiscount(discount);
- } else if(testCase == 3) {
- cout << "====== TESTING IceCreamShop ======" << endl;
- char icsName[50];
- cin.getline(icsName,100);
- cout << "CONSTRUCTOR" << endl;
- IceCreamShop ics(icsName);
- int n;
- cin >> n;
- cout << "OPERATOR +=" << endl;
- for(int i = 0; i < n; ++i) {
- cin.get();
- cin.getline(name,100);
- cin.getline(ingr,100);
- cin >> price;
- IceCream ic(name, ingr, price);
- ics += ic;
- }
- cout << ics;
- } else if(testCase == 4) {
- cout << "====== TESTING IceCreamShop CONSTRUCTORS ======" << endl;
- char icsName[50];
- cin.getline(icsName,100);
- IceCreamShop ics(icsName);
- int n;
- cin >> n;
- for(int i = 0; i < n; ++i) {
- cin.get();
- cin.getline(name,100);
- cin.getline(ingr,100);
- cin >> price;
- IceCream ic(name, ingr, price);
- ics += ic;
- }
- IceCream x("FINKI fruits", "strawberry ice cream, raspberry ice cream, blueberry ice cream", 60);
- IceCreamShop icp = ics;
- ics+=x;
- cout << ics << endl;
- cout << icp << endl;
- }
- return 0;
- }
- //37. Планинарски дом
- #include<iostream>
- #include<string.h>
- using namespace std;
- class Zichara
- {
- char *mesto;
- int cena;
- public:
- Zichara()
- {
- mesto=new char[0];
- }
- Zichara(char *m, int c)
- {
- mesto=new char[strlen(m)+1];
- strcpy(mesto,m);
- cena=c;
- }
- Zichara(Zichara &z)
- {
- mesto=new char[strlen(z.mesto)+1];
- strcpy(mesto,z.mesto);
- cena=z.cena;
- }
- int getCena()
- {
- return cena;
- }
- Zichara& operator = (Zichara &z)
- {
- if(this!=&z)
- {
- delete [] mesto;
- mesto=new char[strlen(z.mesto)+1];
- strcpy(mesto,z.mesto);
- cena=z.cena;
- }
- return *this;
- }
- ~Zichara()
- {
- delete [] mesto;
- }
- };
- class PlaninarskiDom
- {
- char ime[15];
- int cenaSezona[2];
- char klasa;
- bool imaZichara;
- Zichara *pok;
- public:
- PlaninarskiDom(){}
- PlaninarskiDom(char *i, int *cSezona, char k)
- {
- strcpy(ime,i);
- cenaSezona[0]=cSezona[0];
- cenaSezona[1]=cSezona[1];
- klasa=k;
- }
- PlaninarskiDom(PlaninarskiDom &p)
- {
- strcpy(ime,p.ime);
- cenaSezona[0]=p.cenaSezona[0];
- cenaSezona[1]=p.cenaSezona[1];
- klasa=p.klasa;
- imaZichara=p.imaZichara;
- pok=p.pok;
- }
- PlaninarskiDom& operator = (PlaninarskiDom &p)
- {
- strcpy(ime,p.ime);
- cenaSezona[0]=p.cenaSezona[0];
- cenaSezona[1]=p.cenaSezona[1];
- klasa=p.klasa;
- imaZichara=p.imaZichara;
- pok=p.pok;
- return *this;
- }
- void setZichara(Zichara &p)
- {
- pok=&p;
- imaZichara=1;
- }
- PlaninarskiDom& operator --()
- {
- if(klasa<'F')
- klasa++;
- return *this;
- }
- friend ostream& operator << (ostream &os,const PlaninarskiDom &p)
- {
- if(p.imaZichara)
- os<<p.ime<<" klasa:"<<p.klasa<<" so Zichara"<<endl;
- else
- os<<p.ime<<" klasa:"<<p.klasa<<endl;
- return os;
- }
- bool operator <= (char znak)
- {
- if(klasa>=znak)
- return true;
- else
- return false;
- }
- void presmetajDnevenPrestoj(int den, int mesec, int &cena)
- {
- if(mesec<1 || mesec>12)
- throw mesec;
- else if(den<1 || den>12)
- throw den;
- else
- {
- if(mesec>3&&mesec<9)
- {
- if(imaZichara)
- cena=cenaSezona[0]+pok->getCena();
- else
- cena=cenaSezona[0];
- }
- else
- {
- if(imaZichara)
- cena=cenaSezona[1]+pok->getCena();
- else
- cena=cenaSezona[1];
- }
- }
- }
- };
- int main()
- {
- PlaninarskiDom p; //креирање на нов објект од класата планинарски дом
- //во следниот дел се вчитуваат информации за планинарскиот дом
- char imePlaninarskiDom[15],mestoZichara[30],klasa;
- int ceni[12];
- int dnevnakartaZichara;
- bool daliZichara;
- cin>>imePlaninarskiDom;
- for (int i=0; i<2; i++) cin>>ceni[i];
- cin>>klasa;
- cin>>daliZichara;
- //во следниот дел се внесуваат информации и за жичарата ако постои
- if (daliZichara)
- {
- cin>>mestoZichara>>dnevnakartaZichara;
- PlaninarskiDom pom(imePlaninarskiDom,ceni,klasa);
- Zichara r(mestoZichara,dnevnakartaZichara);
- pom.setZichara(r);
- p=pom;
- }
- else
- {
- PlaninarskiDom *pok=new PlaninarskiDom(imePlaninarskiDom,ceni,klasa);
- p=*pok;
- }
- //се намалува класата на планинарскиот дом за 2
- --p;
- --p;
- int cena;
- int den,mesec;
- cin>>den>>mesec;
- try
- {
- p.presmetajDnevenPrestoj(den,mesec,cena); //тука се користи функцијата presmetajDnevenPrestoj
- cout<<"Informacii za PlaninarskiDomot:"<<endl;
- cout<<p;
- if (p<='D')
- cout<<"Planinarskiot dom za koj se vneseni informaciite ima klasa poniska ili ista so D\n";
- cout<<"Cenata za "<<den<<"."<<mesec<<" e "<<cena; //се печати цената за дадениот ден и месец
- }
- catch (int)
- {
- cout<<"Mesecot ili denot e greshno vnesen!";
- }
- }
- //38. Фактура C
- #include <stdio.h>
- #include <string.h>
- typedef struct Proizvod
- {
- char kod[20];
- int cena;
- int kolichina;
- }Proizvod;
- typedef struct Narachka
- {
- char ime[15];
- Proizvod proizvodi[10];
- int kolichina[10];
- int n;
- }Narachka;
- void swapProizvod(Proizvod *a, Proizvod *b)
- {
- char pom[20];
- int c, k;
- strcpy(pom,a->kod);
- strcpy(a->kod,b->kod);
- strcpy(b->kod,pom);
- c=a->cena;
- a->cena=b->cena;
- b->cena=c;
- }
- void pecatiFaktura(Narachka n)
- {
- int i, j;
- printf("Faktura za %s\n",n.ime);
- for(i=0; i<n.n; i++ )
- if(n.kolichina[i]>n.proizvodi[i].kolichina)
- {
- printf("Fakturata ne moze da se izgotvi\n");
- return;
- }
- int suma=0;
- for(i=0; i<n.n-1; i++)
- {
- for(j=i+1; j<n.n; j++)
- {
- if(strcmp(n.proizvodi[i].kod,n.proizvodi[j].kod)>0)
- {
- swapProizvod(&n.proizvodi[i], &n.proizvodi[j]);
- }
- }
- }
- for(i=0; i<n.n; i++)
- {
- suma+=n.kolichina[i]*n.proizvodi[i].cena;
- printf("%s %d %d %d\n", n.proizvodi[i].kod, n.proizvodi[i].cena, n.kolichina[i], n.kolichina[i]*n.proizvodi[i].cena );
- }
- printf("Vkupnata suma na fakturata e %d", suma);
- }
- int main() {
- Narachka narachka;
- // внеси го името лицето кое ја прави нарачката
- scanf("%s", narachka.ime);
- // внеси го бројот на порачани производи во нарачката
- scanf("%d", &narachka.n);
- int i;
- //за секој од нарачаните производи се внесуваат информации
- for (i = 0; i < narachka.n; ++i) {
- // внеси код
- scanf("%s", narachka.proizvodi[i].kod);
- // внеси единицчна цена
- scanf("%d", &narachka.proizvodi[i].cena);
- // внеси број на производи во магацин
- scanf("%d", &narachka.proizvodi[i].kolichina);
- }
- //за секој производ се внесува колку такви производи се порачани во нарачката
- int j;
- for (j = 0; j < narachka.n; ++j) {
- //се внесува број на производи во нарачката
- scanf("%d", &narachka.kolichina[j]);
- }
- // повик на функцијата pecatiFaktura
- pecatiFaktura(narachka);
- return 0;
- }
- //39. Воз
- #include<iostream>
- #include<cstring>
- #include<cmath>
- using namespace std;
- class Patnik {
- private:
- char ime [100];
- int klasa;
- bool velosiped;
- public:
- Patnik() {}
- Patnik (char *i, int k, bool v) {
- strcpy(ime, i);
- klasa=k;
- velosiped=v;
- }
- Patnik(Patnik &p) {
- strcpy(ime,p.ime);
- klasa=p.klasa;
- velosiped=p.velosiped;
- }
- Patnik& operator = (Patnik &p) {
- if(this!=&p) {
- strcpy(ime,p.ime);
- klasa=p.klasa;
- velosiped=p.velosiped;
- }
- return *this;
- }
- friend ostream& operator << (ostream& os, const Patnik &p) {
- os << p.ime << "\n" << p.klasa << "\n" <<p.velosiped<<endl;
- return os;
- }
- int getKlasa() {
- return klasa;
- }
- bool getVelosiped() {
- return velosiped;
- }
- ~Patnik() {}
- };
- class Voz {
- private:
- char destinacija [100];
- Patnik *patnici;
- int elementi;
- int maxv;
- public:
- Voz() {
- patnici=new Patnik[0];
- }
- Voz(char *d, int m) {
- strcpy(destinacija, d);
- maxv=m;
- patnici=new Patnik[0];
- elementi=0;
- }
- Voz(char *d, Patnik *p, int e, int m) {
- strcpy(destinacija, d);
- maxv=m;
- elementi=e;
- patnici=new Patnik[e];
- for(int i=0; i<e; i++) {
- patnici[i]=p[i];
- }
- }
- Voz& operator += (Patnik &p) {
- if((maxv==0&&p.getVelosiped()==false)||(maxv>0))
- {
- int i;
- Patnik *pom=new Patnik[elementi];
- for(i=0; i<elementi; i++)
- pom[i]=patnici[i];
- delete [] patnici;
- patnici=new Patnik[elementi+1];
- for(i=0; i<elementi; i++)
- patnici[i]=pom[i];
- patnici[i]=p;
- ++elementi;
- delete [] pom;
- return *this;
- }
- return *this;
- }
- friend ostream& operator << (ostream &os, const Voz &v) {
- os << v.destinacija<<"\n";
- for(int i=0; i<v.elementi; i++) {
- os<<v.patnici[i]<<endl;
- }
- return os;
- }
- void patniciNemaMesto() {
- int vkupnoPrva=0, vkupnoVtora=0;
- int Prva,Vtora;
- for(int i=0; i<elementi; i++)
- {
- if(patnici[i].getKlasa()==1&&patnici[i].getVelosiped()==true)
- vkupnoPrva++;
- if(patnici[i].getKlasa()==2&&patnici[i].getVelosiped()==true)
- vkupnoVtora++;
- }
- if(vkupnoPrva<=maxv)
- {
- Prva=0;
- maxv-=vkupnoPrva;
- if(vkupnoVtora<=maxv)
- Vtora=0;
- else
- Vtora=abs(maxv-vkupnoVtora);
- }
- else
- {
- Prva=abs(maxv-vkupnoPrva);
- Vtora=vkupnoVtora;
- }
- cout << "Brojot na patnici od 1-va klasa koi ostanale bez mesto e: "<<Prva<<endl;
- cout << "Brojot na patnici od 2-ra klasa koi ostanale bez mesto e: "<<Vtora<<endl;
- }
- ~Voz()
- {
- delete [] patnici;
- }
- };
- int main() {
- Patnik p;
- char ime[100], destinacija[100];
- int n;
- bool velosiped;
- int klasa;
- int maxv;
- cin >> destinacija >> maxv;
- cin >> n;
- Voz v(destinacija, maxv);
- //cout<<v<<endl;
- for (int i = 0; i < n; i++) {
- cin >> ime >> klasa >> velosiped;
- Patnik p(ime, klasa, velosiped);
- //cout<<p<<endl;
- v += p;
- }
- cout << v;
- v.patniciNemaMesto();
- return 0;
- }
- //40. Работни часови C
- #include <stdio.h>
- #include <string.h>
- #define NEDELI 4
- #define DENOVI 5
- struct RabotnaNedela
- {
- int casovi[DENOVI];
- int broj;
- };
- typedef struct RabotnaNedela RN;
- struct Rabotnik
- {
- char ime[50];
- RN nedeli[NEDELI];
- };
- typedef struct Rabotnik R;
- int maxNedela(R *r)
- {
- int i, j;
- int maxrab=0, sum=0, maxbr=0;
- for(i=0; i<NEDELI; i++)
- {
- sum=0;
- for(j=0; j<DENOVI; j++)
- {
- sum+=r->nedeli[i].casovi[j];
- }
- if(maxrab<sum)
- {
- maxrab=sum;
- maxbr=i;
- }
- }
- return maxbr+1;
- }
- void table(R *r, int n)
- {
- int i, j, k;
- int vkNed, vkRab;
- printf("Rab\t1\t2\t3\t4\tVkupno\n");
- for(i=0; i<n; i++)
- {
- printf("%s\t", r[i].ime);
- vkRab=0;
- for(j=0; j<NEDELI; j++)
- {
- vkNed=0;
- for(k=0; k<DENOVI; k++)
- {
- vkNed+=r[i].nedeli[j].casovi[k];
- }
- printf("%d\t",vkNed);
- vkRab+=vkNed;
- }
- printf("%d\n",vkRab);
- }
- }
- int main() {
- int n;
- scanf("%d", &n);
- R rabotnici[n];
- int i;
- for (i = 0; i < n; ++i) {
- scanf("%s", rabotnici[i].ime);
- int j;
- for (j = 0; j < NEDELI; ++j) {
- int k;
- for (k = 0; k < DENOVI; ++k) {
- scanf("%d", &rabotnici[i].nedeli[j].casovi[k]);
- }
- }
- }
- printf("TABLE\n");
- table(rabotnici, n);
- printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
- printf("%d\n", maxNedela(&rabotnici[n / 2]));
- return 0;
- }
- //41. Танчери
- #include<iostream>
- #include<cstring>
- using namespace std;
- struct Tanc {
- char ime[15];
- char zemja[15];
- };
- struct Tancer {
- char ime[20];
- char prezime[20];
- Tanc niza[5];
- };
- void tancuvanje(Tancer *t, int n, char *zemja) {
- int i;
- int j;
- for(i=0; i<n; i++) {
- for(j=0; j<5; j++) {
- if(strcmp(t[i].niza[j].zemja,zemja)==0) {
- cout<<t[i].ime<<" "<<t[i].prezime<<", "<<t[i].niza[j].ime<<endl;
- break;
- }
- }
- }
- }
- int main() {
- int i, j, n;
- char zemja[15];
- Tancer tanceri[5];
- cin >> n;
- for(i = 0; i < n; i++) {
- cin >> tanceri[i].ime;
- cin >> tanceri[i].prezime;
- for(j = 0; j < 3; j++) {
- cin >> tanceri[i].niza[j].ime;
- cin >> tanceri[i].niza[j].zemja;
- }
- }
- cin >> zemja;
- tancuvanje(tanceri, n, zemja);
- return 0;
- }
- //42. Работни часови (40 поени) C
- #include <stdio.h>
- #include <string.h>
- #define NEDELI 4
- #define DENOVI 5
- struct RabotnaNedela
- {
- int casovi[DENOVI];
- int broj;
- };
- typedef struct RabotnaNedela RN;
- struct Rabotnik
- {
- char ime[50];
- RN nedeli[NEDELI];
- };
- typedef struct Rabotnik R;
- int maxNedela(R *r)
- {
- int i, j;
- int maxrab=0, sum=0, maxbr=0;
- for(i=0; i<NEDELI; i++)
- {
- sum=0;
- for(j=0; j<DENOVI; j++)
- {
- sum+=r->nedeli[i].casovi[j];
- }
- if(maxrab<sum)
- {
- maxrab=sum;
- maxbr=i;
- }
- }
- return maxbr+1;
- }
- void table(R *r, int n)
- {
- int i, j, k;
- int vkNed, vkRab;
- printf("Rab\t1\t2\t3\t4\tVkupno\n");
- for(i=0; i<n; i++)
- {
- printf("%s\t", r[i].ime);
- vkRab=0;
- for(j=0; j<NEDELI; j++)
- {
- vkNed=0;
- for(k=0; k<DENOVI; k++)
- {
- vkNed+=r[i].nedeli[j].casovi[k];
- }
- printf("%d\t",vkNed);
- vkRab+=vkNed;
- }
- printf("%d\n",vkRab);
- }
- }
- int main() {
- int n;
- scanf("%d", &n);
- R rabotnici[n];
- int i;
- for (i = 0; i < n; ++i) {
- scanf("%s", rabotnici[i].ime);
- int j;
- for (j = 0; j < NEDELI; ++j) {
- int k;
- for (k = 0; k < DENOVI; ++k) {
- scanf("%d", &rabotnici[i].nedeli[j].casovi[k]);
- }
- }
- }
- printf("TABLE\n");
- table(rabotnici, n);
- printf("MAX NEDELA NA RABOTNIK: %s\n", rabotnici[n / 2].ime);
- printf("%d\n", maxNedela(&rabotnici[n / 2]));
- return 0;
- }
- //43. Структура во C C
- #include<stdio.h>
- #include<string.h>
- struct Pacient
- {
- char ime[100];
- int zdrastveno;
- int pregledi;
- };
- typedef struct MaticenDoktor
- {
- char ime[100];
- int br_pac;
- struct Pacient niza[200];
- float cena;
- } doktor;
- void najuspesen_doktor (doktor *md, int n)
- {
- float suma=0, maxsuma=0;
- char ID[100];
- int maxpac=0, i, j, preg;
- for(i=0; i<n; i++)
- {
- suma=0;
- preg=0;
- for(j=0; j<md[i].br_pac; j++)
- {
- if(md[i].niza[j].zdrastveno==0)
- {
- suma+=md[i].cena*md[i].niza[j].pregledi;
- }
- preg+=md[i].niza[j].pregledi;
- }
- if(maxsuma<suma)
- {
- maxsuma=suma;
- strcpy(ID, md[i].ime);
- maxpac=preg;
- }
- else if(maxsuma==suma)
- {
- if(maxpac<preg)
- {
- maxpac=preg;
- maxsuma=suma;
- strcpy(ID, md[i].ime);
- }
- }
- }
- printf("%s %.2f %d", ID, maxsuma , maxpac);
- }
- int main()
- {
- int i, j, n, broj;
- doktor md[200];
- scanf("%d", &n);
- for (i = 0; i < n; i++){
- //ime na doktor
- scanf("%s", md[i].ime);
- //broj na pacienti
- scanf("%d", &md[i].br_pac);
- //cena na pregled
- scanf("%f", &md[i].cena);
- for (j = 0; j < md[i].br_pac; j++){
- scanf("%s", md[i].niza[j].ime);
- scanf("%d", &md[i].niza[j].zdrastveno);
- scanf("%d", &md[i].niza[j].pregledi);
- }
- }
- najuspesen_doktor(md, n);
- return 0;
- }
- //44. Акции
- #include<iostream>
- #include<cstring>
- using namespace std;
- class StockRecord {
- char ID[12];
- char ime[50];
- double cenaKupovna;
- double cenaMomentalna;
- int brojKupeni;
- public:
- StockRecord() {}
- StockRecord(const char *id, const char *i, double cK, int br) {
- strcpy(ID,id);
- strcpy(ime,i);
- cenaKupovna=cK;
- brojKupeni=br;
- cenaMomentalna=0;
- }
- StockRecord(StockRecord &s) {
- strcpy(ID,s.ID);
- strcpy(ime,s.ime);
- cenaKupovna=s.cenaKupovna;
- brojKupeni=s.brojKupeni;
- cenaMomentalna=s.cenaMomentalna;
- }
- StockRecord& operator = (StockRecord &s) {
- strcpy(ID,s.ID);
- strcpy(ime,s.ime);
- cenaKupovna=s.cenaKupovna;
- brojKupeni=s.brojKupeni;
- cenaMomentalna=s.cenaMomentalna;
- return *this;
- }
- double value() {
- return brojKupeni * cenaMomentalna;
- }
- double profit() {
- return brojKupeni * (cenaMomentalna-cenaKupovna);
- }
- friend ostream& operator << (ostream &os, StockRecord &s) {
- os<<s.ime<<" "<<s.brojKupeni<<" "<<s.cenaKupovna;
- os<<" "<<s.cenaMomentalna<<" "<<s.profit()<<endl;
- return os;
- }
- void setNewPrice(double c) {
- cenaMomentalna=c;
- }
- };
- class Client {
- char ime[60];
- int ID;
- StockRecord *kompanii;
- int elementi;
- public:
- Client(char *i, int id) {
- strcpy(ime,i);
- ID=id;
- kompanii=new StockRecord[0];
- elementi=0;
- }
- Client(Client &c) {
- strcpy(ime,c.ime);
- ID=c.ID;
- kompanii=new StockRecord[c.elementi];
- for(int i=0; i<c.elementi; i++) {
- kompanii[i]=c.kompanii[i];
- }
- elementi=c.elementi;
- }
- double totalValue() {
- int total=0;
- for(int i=0; i<elementi; i++) {
- total+=kompanii[i].value();
- }
- return total;
- }
- Client& operator = (Client &c) {
- delete [] kompanii;
- strcpy(ime,c.ime);
- ID=c.ID;
- kompanii=new StockRecord[c.elementi];
- for(int i=0; i<c.elementi; i++) {
- kompanii[i]=c.kompanii[i];
- }
- elementi=c.elementi;
- return *this;
- }
- Client& operator += (StockRecord &s) {
- StockRecord *temp=new StockRecord[elementi];
- for(int i=0; i<elementi; i++) {
- temp[i]=kompanii[i];
- }
- delete [] kompanii;
- kompanii=new StockRecord[elementi+1];
- for(int i=0; i<elementi; i++) {
- kompanii[i]=temp[i];
- }
- kompanii[elementi]=s;
- elementi++;
- delete [] temp;
- return *this;
- }
- friend ostream& operator << (ostream &os, Client &c) {
- os<<c.ID<<" "<<c.totalValue()<<endl;
- for(int i=0; i<c.elementi; i++) {
- os<<c.kompanii[i];
- }
- return os;
- }
- ~Client() {
- delete [] kompanii;
- }
- };
- // ne menuvaj vo main-ot
- int main() {
- int test;
- cin >> test;
- if(test == 1) {
- double price;
- cout << "=====TEST NA KLASATA StockRecord=====" << endl;
- StockRecord sr("1", "Microsoft", 60.0, 100);
- cout << "Konstruktor OK" << endl;
- cin >> price;
- sr.setNewPrice(price);
- cout << "SET metoda OK" << endl;
- } else if(test == 2) {
- cout << "=====TEST NA METODITE I OPERATOR << OD KLASATA StockRecord=====" << endl;
- char id[12], company[50];
- double price, newPrice;
- int n, shares;
- cin >> n;
- for(int i = 0; i < n; ++i) {
- cin >> id;
- cin >> company;
- cin >> price;
- cin >> newPrice;
- cin >> shares;
- StockRecord sr(id, company, price, shares);
- sr.setNewPrice(newPrice);
- cout << sr.value() << endl;
- cout << sr;
- }
- } else if(test == 3) {
- cout << "=====TEST NA KLASATA Client=====" << endl;
- char companyID[12], companyName[50], clientName[50];
- int clientID, n, shares;
- double oldPrice, newPrice;
- bool flag = true;
- cin >> clientName;
- cin >> clientID;
- cin >> n;
- Client c(clientName, clientID);
- cout << "Konstruktor OK" << endl;
- for(int i = 0; i < n; ++i) {
- cin >> companyID;
- cin >> companyName;
- cin >> oldPrice;
- cin >> newPrice;
- cin >> shares;
- StockRecord sr(companyID, companyName, oldPrice, shares);
- sr.setNewPrice(newPrice);
- c += sr;
- if(flag) {
- cout << "Operator += OK" << endl;
- flag = false;
- }
- }
- cout << c;
- cout << "Operator << OK" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement