Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.KOMPJUTERSKA IGRA
- #include<iostream>
- using namespace std;
- struct Igrac {
- char korisnickoIme[15];
- int nivo;
- int poeni;
- };
- struct KompjuterskaIgra {
- char ime[20];
- Igrac lista[30];
- int n;
- };
- void najdobarIgrac(KompjuterskaIgra *igri,int n) {
- int indeksNajmnoguIgraci=0;
- for (int i=1; i<n; i++) {
- if (igri[i].n>igri[indeksNajmnoguIgraci].n)
- indeksNajmnoguIgraci=i;
- }
- KompjuterskaIgra najpopularna=igri[indeksNajmnoguIgraci];
- int indeksmax=0;
- for (int i=1; i<najpopularna.n; i++) {
- if (najpopularna.lista[i].poeni>najpopularna.lista[indeksmax].poeni)
- indeksmax=i;
- else if (najpopularna.lista[i].poeni==najpopularna.lista[indeksmax].poeni) {
- if (najpopularna.lista[i].nivo>najpopularna.lista[indeksmax].nivo)
- indeksmax=i;
- }
- }
- cout<<"Najdobar igrac e igracot so korisnicko ime ";
- cout<<najpopularna.lista[indeksmax].korisnickoIme;
- cout<<" koj ja igra igrata ";
- cout<<najpopularna.ime;
- }
- 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.n;
- Igrac pole[30];
- for (int j=0; j<nova.n; j++) {
- Igrac nov;
- cin>>nov.korisnickoIme>>nov.nivo>>nov.poeni;
- nova.lista[j]=nov;
- }
- poleigri[i]=nova;
- }
- najdobarIgrac(poleigri,n);
- return 0;
- }
- 2.SKIJACKI CENTAR
- //STARTER
- /*
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- scanf("%d", &n);
- for (i = 0; i < n; i++){
- //vnesi ime
- //vnesi drzava
- //vnesi broj na liftovi
- //za sekoj ski lift vnesi:
- //vnesi ime
- //vnesi maksimalen broj korisnici
- //vnesi dali e pusten vo funkcija
- }
- //povik na funkcijata najgolemKapacitet
- return 0;
- }
- */
- //RESENIE
- #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;
- }
- 3.CD
- #include<iostream>
- #include<cstring>
- using namespace std;
- enum tip {
- POP,RAP,ROK
- };
- class Pesna {
- private:
- char *ime;
- int vremetraenje;
- tip tipPesna;
- public:
- Pesna(char *ime=" ", int vremetraenje=0, tip tipPesna=POP)
- {
- this->ime=new char[strlen(ime)+1];
- strcpy(this->ime, ime);
- this->vremetraenje=vremetraenje;
- this->tipPesna=tipPesna;
- }
- ~Pesna(){
- delete [] ime;
- }
- Pesna(const Pesna &p)
- {
- this->ime=new char[strlen(p.ime)+1];
- strcpy(this->ime, p.ime);
- this->vremetraenje=p.vremetraenje;
- this->tipPesna=p.tipPesna;
- }
- Pesna & operator=(Pesna &p)
- {
- if(this!=&p)
- {
- delete [] ime;
- this->ime=new char[strlen(p.ime)+1];
- strcpy(this->ime, p.ime);
- this->vremetraenje=p.vremetraenje;
- this->tipPesna=p.tipPesna;
- }
- return *this;
- }
- void pecati()
- {
- cout<<"\""<<ime<<"\""<<"-"<<vremetraenje<<"min"<<endl;
- }
- friend class CD;
- };
- class CD {
- private:
- Pesna pesni[10];
- int n;
- int maxVremetraenje;
- public:
- CD(int maxVremetraenje=0)
- {
- this->maxVremetraenje=maxVremetraenje;
- n=0;
- }
- void dodadiPesna(Pesna p)
- {
- int momentalnoVremetraenje=0;
- for(int i=0;i<n;i++)
- momentalnoVremetraenje +=pesni[i].vremetraenje;
- if(momentalnoVremetraenje+p.vremetraenje>maxVremetraenje)
- {
- //cout<<"Nadminato e max vremetraenje"<<endl;
- return;
- }
- if(n==10)
- {
- //cout<<"Nema vekje prostor vo nizata"<<endl;
- return;
- }
- pesni[n]=p;
- n++;
- }
- void pecatiPesniPoTip(tip Pesna)
- {
- for (int i=0;i<n;i++)
- {
- if (pesni[i].tipPesna==Pesna)
- {
- pesni[i].pecati();
- }
- }
- }
- Pesna getPesna(int i)
- {
- return pesni[i];
- }
- int getBroj(){
- return n;
- }
- };
- 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;
- }
- 4.ZELEZNICKA STANICA
- #include<iostream>
- #include <cstring>
- using namespace std;
- struct Voz{
- char relacija[50];
- float kilometri;
- int patnici;
- };
- struct ZeleznickaStanica{
- char grad[20];
- Voz vozovi[30];
- int broj_na_vozovi;
- };
- void najkratkaRelacija(ZeleznickaStanica* zs, int n, char* grad)
- {
- int tmp1=0,tmp2=0; int flag=1; int pom=0;
- for(int i=0;i<n;i++)
- {
- if(strcmp(zs[i].grad,grad)==0)
- {
- for(int j=0;j<zs[i].broj_na_vozovi;j++)
- {
- if (flag)
- {
- pom=zs[i].vozovi[j].kilometri;
- flag=0;
- }
- if(pom>= zs[i].vozovi[j].kilometri)
- {
- tmp1=i;
- tmp2=j;
- pom=zs[i].vozovi[j].kilometri;
- }
- }
- }
- }
- cout<<"Najkratka relacija: "<<zs[tmp1].vozovi[tmp2].relacija<<" ("<<zs[tmp1].vozovi[tmp2].kilometri<<" km)";
- }
- 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;
- cin>>zStanica[i].broj_na_vozovi;
- for(int j=0;j<zStanica[i].broj_na_vozovi;j++)
- {
- cin>>zStanica[i].vozovi[j].relacija;
- cin>>zStanica[i].vozovi[j].kilometri;
- cin>>zStanica[i].vozovi[j].patnici;
- }
- }
- char grad[25];
- cin>>grad;
- najkratkaRelacija(zStanica,n,grad);
- return 0;
- }
- 5.PICERIJA
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Pica {
- private:
- char ime[15];
- int cena;
- char* sostojki;
- int namaluvanje;
- public:
- Pica(const char* ime = "", int cena = 0, const char* sostojki = "", int namaluvanje = 0) {
- strcpy(this->ime, ime);
- this->cena = cena;
- this->sostojki = new char[strlen(sostojki) + 1];
- strcpy(this->sostojki, sostojki);
- this->namaluvanje = namaluvanje;
- }
- Pica(const Pica& p) {
- strcpy(ime, p.ime);
- cena = p.cena;
- sostojki = new char[strlen(p.sostojki) + 1];
- strcpy(sostojki, p.sostojki);
- namaluvanje = p.namaluvanje;
- }
- ~Pica() {
- delete[] sostojki;
- }
- 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;
- }
- void pecati(){
- cout << ime << " - " << sostojki << ", " << cena;
- }
- bool istiSe(Pica p){
- return (strcmp(sostojki, p.sostojki) == 0);
- }
- int getNamaluvanje(){
- return namaluvanje;
- }
- int getCena(){
- return cena;
- }
- };
- class Picerija {
- private:
- char ime[15];
- Pica* pici;
- int br;
- public:
- Picerija(const char *ime = ""){
- strncpy(this->ime, ime, 14);
- this->ime[14] = 0;
- pici = NULL;
- br = 0;
- }
- Picerija(const char *ime, Pica* pici, int br) {
- strncpy(this->ime, ime, 14);
- this->ime[14] = 0;
- this->br = br;
- this->pici = new Pica[br];
- for (int i = 0; i < br; i++)
- this->pici[i] = pici[i];
- }
- Picerija(const Picerija &p) {
- strcpy(ime, p.ime);
- br = p.br;
- pici = new Pica[br];
- for (int i = 0; i < br; i++)
- pici[i] = p.pici[i];
- }
- Picerija& operator= (const Picerija &p) {
- if (this != &p) {
- strcpy(ime, p.ime);
- br = p.br;
- delete[] pici;
- pici = new Pica[br];
- for (int i = 0; i < br; i++)
- pici[i] = p.pici[i];
- }
- return *this;
- }
- ~Picerija() {
- delete[] pici;
- }
- Picerija& operator+=(Pica &p){
- bool imaIsta = false;
- for (int i = 0; i < br; i++)
- if (pici[i].istiSe(p))
- imaIsta = true;
- if (!imaIsta)
- {
- Pica* tmp = new Pica[br + 1];
- for (int i = 0; i < br; i++)
- tmp[i] = pici[i];
- tmp[br++] = p;
- delete[] pici;
- pici = tmp;
- }
- return *this;
- }
- void piciNaPromocija() {
- for (int i = 0; i < br; i++){
- if (pici[i].getNamaluvanje() != 0){
- pici[i].pecati();
- cout << " " << pici[i].getCena() * (1 - pici[i].getNamaluvanje() / 100.0) << endl;
- }
- }
- }
- const char* getIme(){
- return ime;
- }
- void setIme(const char* ime){
- strncpy(this->ime, ime, 14);
- this->ime[14] = 0;
- }
- };
- 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+=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+=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;
- }
- 4.MARATON
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Ucesnik
- {
- private:
- char *ime;
- bool pol;
- int vozrast;
- public:
- Ucesnik(const char *ime="",bool pol=false,int vozrast=0)
- {
- this->ime= new char[strlen(ime)+1];
- strcpy(this->ime,ime);
- this->pol=pol;
- this->vozrast=vozrast;
- }
- Ucesnik(const Ucesnik &u)
- {
- this->ime= new char[strlen(u.ime)+1];
- strcpy(this->ime,u.ime);
- this->pol=u.pol;
- this->vozrast=u.vozrast;
- }
- Ucesnik &operator=(const Ucesnik &u)
- {
- if(this!=&u)
- {
- delete []ime;
- this->ime= new char[strlen(u.ime)+1];
- strcpy(this->ime,u.ime);
- this->pol=u.pol;
- this->vozrast=u.vozrast;
- }
- return *this;
- }
- bool sporedi(Ucesnik &u)
- {
- return (vozrast>u.vozrast);
- }
- void pecati()
- {
- if(pol==true)
- cout<<ime<<"\n"<<"mashki"<<"\n"<<vozrast<<endl;
- else
- cout<<ime<<"\n"<<"zhenski"<<"\n"<<vozrast<<endl;
- }
- int getVozrast()
- {
- return vozrast;
- }
- ~Ucesnik()
- {
- delete []ime;
- }
- };
- class Maraton
- {
- private:
- char lokacija[100];
- Ucesnik *ucesnici;
- int br_ucesnici;
- public:
- Maraton(char *lokacija)
- {
- strcpy(this->lokacija,lokacija);
- this->br_ucesnici=0;
- this->ucesnici= new Ucesnik [br_ucesnici];
- }
- Maraton(const Maraton &m)
- {
- strcpy(this->lokacija,m.lokacija);
- this->br_ucesnici=m.br_ucesnici;
- this->ucesnici=new Ucesnik [m.br_ucesnici];
- for(int i=0;i<br_ucesnici;i++)
- {
- this->ucesnici[i]=m.ucesnici[i];
- }
- }
- Maraton &operator=(const Maraton &m)
- {
- if(this!=&m)
- {
- strcpy(this->lokacija,m.lokacija);
- this->br_ucesnici=m.br_ucesnici;
- delete []ucesnici;
- this->ucesnici=new Ucesnik [m.br_ucesnici];
- for(int i=0;i<br_ucesnici;i++)
- {
- this->ucesnici[i]=m.ucesnici[i];
- }
- }
- return *this;
- }
- void dodadi(Ucesnik &u)
- {
- Ucesnik *temp;
- temp = new Ucesnik[br_ucesnici+1];
- for(int i=0;i<br_ucesnici;i++)
- {
- temp[i]=ucesnici[i];
- }
- temp[br_ucesnici++]=u;
- delete []ucesnici;
- ucesnici=temp;
- }
- double prosecnoVozrast()
- {
- double suma=0.0;
- for(int i=0;i<br_ucesnici;i++)
- {
- suma+=ucesnici[i].getVozrast();
- }
- return (double)suma/br_ucesnici;
- }
- void pecatiPomladi(Ucesnik &u)
- {
- for(int i=0;i<br_ucesnici;i++)
- {
- if(ucesnici[i].getVozrast()<u.getVozrast())
- ucesnici[i].pecati();
- }
- }
- ~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.dodadi(*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;
- }
- 4.REPOZITORIUM
- #include <iostream>
- #include <string.h>
- using namespace std;
- enum Tip {LINUX,UNIX,WINDOWS};
- class OperativenSistem
- {
- private:
- char *imeOs;
- float verzija;
- Tip tip;
- float golemina;
- public:
- OperativenSistem()
- {
- imeOs=new char[0];
- verzija=0;
- golemina=0;
- }
- OperativenSistem(char *imeOs, float verzija,enum Tip tip, float golemina)
- {
- this->imeOs=new char[strlen(imeOs)+1];
- strcpy(this->imeOs,imeOs);
- this->verzija=verzija;
- this->tip=tip;
- this->golemina=golemina;
- }
- OperativenSistem(const OperativenSistem &os)
- {
- this->imeOs=new char[strlen(os.imeOs)+1];
- strcpy(this->imeOs,os.imeOs);
- this->verzija=os.verzija;
- this->tip=os.tip;
- this->golemina=os.golemina;
- }
- OperativenSistem &operator=(const OperativenSistem &os)
- {
- if(this!=&os)
- {
- delete []imeOs;
- this->imeOs=new char[strlen(os.imeOs)+1];
- strcpy(this->imeOs,os.imeOs);
- this->verzija=os.verzija;
- this->tip=os.tip;
- this->golemina=os.golemina;
- }
- return *this;
- }
- void pecati()
- {
- cout<<"Ime: "<<imeOs<<" Verzija: "<<verzija<<" Tip: "<<tip<<" Golemina:"<<golemina<<"GB"<<endl;
- }
- bool ednakviSe(const OperativenSistem &os)
- {
- return strcmp(imeOs,os.imeOs)==0&&verzija==os.verzija &&tip==os.tip&&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(imeOs,sporedba.imeOs)==0)&&(tip==sporedba.tip);
- }
- ~OperativenSistem()
- {
- delete []imeOs;
- }
- };
- class Repozitorium
- {
- private:
- char imeRe[20];
- OperativenSistem *os;
- int brOS;
- public:
- Repozitorium(char *imeRe)
- {
- strcpy(this->imeRe,imeRe);
- brOS=0;
- os=new OperativenSistem[brOS];
- }
- Repozitorium(const Repozitorium &re)
- {
- strcpy(this->imeRe,re.imeRe);
- this->brOS=re.brOS;
- this->os=new OperativenSistem[brOS];
- for(int i=0; i<brOS; i++)
- {
- (this->os)[i]=re.os[i];
- }
- }
- Repozitorium& operator=(const Repozitorium &re)
- {
- if(this!=&re)
- {
- strcpy(this->imeRe,re.imeRe);
- this->brOS=re.brOS;
- delete []os;
- this->os=new OperativenSistem[brOS];
- for(int i=0; i<brOS; i++)
- {
- this->os[i]=re.os[i];
- }
- }
- return *this;
- }
- void pecatiOperativniSistemi()
- {
- cout<<"Repozitorium: "<<imeRe<<endl;
- for(int i=0;i<brOS;i++)
- {
- os[i].pecati();
- }
- }
- void izbrishi(const OperativenSistem &izbrisi)
- {
- int indeks=-1;
- for(int i=0;i<brOS;i++)
- {
- if(os[i].ednakviSe(izbrisi))
- {
- indeks=i;
- }
- }
- if(indeks==-1)
- {
- return;
- }
- OperativenSistem *brisi=new OperativenSistem[brOS-1];
- for(int i=0;i<brOS;i++)
- {
- if(i!=indeks)
- {
- brisi[i]=os[i];
- }
- }
- brOS--;
- delete []os;
- os=brisi;
- }
- void dodadi (const OperativenSistem &nov)
- {
- for(int i=0;i<brOS;i++)
- {
- if(os[i].istaFamilija(nov)&&os[i].sporediVerzija(nov)==-1)
- {
- os[i]=nov;
- return;
- }
- }
- OperativenSistem *dodaden=new OperativenSistem[brOS+1];
- for(int i=0;i<brOS;i++)
- {
- dodaden[i]=os[i];
- }
- dodaden[brOS++]=nov;
- delete []os;
- os=dodaden;
- }
- ~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 tip;
- float golemina;
- for (int i = 0; i<brojOperativniSistemi; i++){
- cin>>ime;
- cin>>verzija;
- cin>>tip;
- cin>>golemina;
- OperativenSistem os = OperativenSistem(ime, verzija, (Tip)tip, golemina);
- repozitorium.dodadi(os);
- }
- repozitorium.pecatiOperativniSistemi();
- cin>>ime;
- cin>>verzija;
- cin>>tip;
- cin>>golemina;
- OperativenSistem os = OperativenSistem(ime, verzija, (Tip)tip, golemina);
- cout<<"=====Brishenje na operativen sistem====="<<endl;
- repozitorium.izbrishi(os);
- repozitorium.pecatiOperativniSistemi();
- return 0;
- }
- 5.SLADOLED
- #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;
- }
- //STARTER
- /*#include <iostream>
- #include <cstring>
- using namespace std;
- // vashiot kod ovde
- // zabraneto e menuvanje na main funkcijata
- 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;
- 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;
- }
- */
- 6.PLANINARSKI DOM
- #include<iostream>
- #include<string.h>
- using namespace std;
- class Zichara
- {
- private:
- char *mesto;
- int cena;
- public:
- Zichara()
- {
- mesto = new char[0];
- }
- Zichara(char mesto[],int cena)
- {
- this->mesto = new char[strlen(mesto)+1];
- strcpy(this->mesto,mesto);
- this->cena = cena;
- }
- Zichara(const Zichara &z)
- {
- this->mesto = new char[strlen(z.mesto)+1];
- strcpy(this->mesto,z.mesto);
- this->cena = z.cena;
- }
- Zichara& operator=(const Zichara &z)
- {
- if(this!=&z)
- {
- delete []mesto;
- this->mesto = new char[strlen(z.mesto)+1];
- strcpy(this->mesto,z.mesto);
- this->cena = z.cena;
- }
- return *this;
- }
- int getCenaZichara()
- {
- return cena;
- }
- ~Zichara()
- {
- delete []mesto;
- }
- };
- class PlaninarskiDom
- {
- private:
- char ime[16];
- int ceniSezoni[2];
- char klasa;
- bool daliZichara;
- Zichara *z;
- public:
- PlaninarskiDom()
- {
- daliZichara =false;
- z = NULL;
- }
- PlaninarskiDom(char ime[],int ceniSezoni[],char klasa)
- {
- strcpy(this->ime,ime);
- for(int i=0;i<2;i++)
- {
- this->ceniSezoni[i] = ceniSezoni[i];
- }
- this->klasa = klasa;
- daliZichara =false;
- z = NULL;
- }
- PlaninarskiDom& operator--()
- {
- if(klasa<'F')
- {
- ++klasa;
- }
- return *this;
- }
- void setZichara(Zichara &zi)
- {
- this->z = &zi;
- daliZichara=true;
- }
- friend ostream& operator<<(ostream &out, const PlaninarskiDom &p)
- {
- out<<p.ime<<" klasa:"<<p.klasa;
- if(p.daliZichara)//if(p.daliZichara!=0) - isto
- out<<" so Zichara"<<endl;
- else
- out<<endl;
- return out;
- }
- bool operator<=(char znak)
- {
- return klasa >= znak;
- }
- void presmetajDnevenPrestoj(int den,int mesec,int &cena)
- {
- cena =0;
- if(den<1 || den>31 || mesec<1 || mesec>12)
- throw 1;
- if(mesec>=4&&mesec<=8)
- {
- cena = cena + ceniSezoni[0];
- }
- else
- {
- cena = cena + ceniSezoni[1];
- }
- if(daliZichara)
- cena = cena + z->getCenaZichara();
- }
- ~PlaninarskiDom(){}
- };
- 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!";
- }
- }
- 6.PODATOCEN SISTEM
- #include<iostream>
- #include<cstring>
- using namespace std;
- enum Tip{pdf,txt,exe};
- class File{
- char *ime;
- Tip tip;
- char *sopstvenik;
- int golemina;
- public:
- //File();
- File(const char *ime=" ", const char *sopstvenik=" ", int golemina=0 ,Tip tip=txt)
- {
- this->ime= new char [strlen(ime)+1];
- strcpy(this->ime,ime);
- this->sopstvenik= new char [strlen(sopstvenik)+1];
- strcpy(this->sopstvenik,sopstvenik);
- this->tip=tip;
- this->golemina=golemina;
- }
- File (const File &f)
- {
- this->ime= new char [strlen(f.ime)+1];
- strcpy(this->ime,f.ime);
- this->sopstvenik= new char [strlen(f.sopstvenik)+1];
- strcpy(this->sopstvenik,f.sopstvenik);
- this->tip=f.tip;
- this->golemina=f.golemina;
- }
- File &operator= (const File &q)
- {
- if(this!=&q)
- {
- delete [] ime;
- delete [] sopstvenik;
- this->ime= new char [strlen(q.ime)+1];
- strcpy(this->ime,q.ime);
- this->sopstvenik= new char [strlen(q.sopstvenik)+1];
- strcpy(this->sopstvenik,q.sopstvenik);
- this->tip=q.tip;
- this->golemina=q.golemina;
- }
- return *this;
- }
- ~File(){ delete [] ime; delete [] sopstvenik;}
- void print()
- {
- cout<<"File name: "<<ime;
- if(tip==0)
- cout<<"."<<"pdf"<<endl;
- else
- {
- if(tip==1)
- cout<<"."<<"txt"<<endl;
- else
- cout<<"."<<"exe"<<endl;
- }
- cout<<"File owner: "<<sopstvenik<<endl<<"File size: "<<golemina<<endl;
- }
- bool equals(const File & that)
- {
- if(((strcmp(ime,that.ime))==0)&&(tip==that.tip)&&(strcmp(sopstvenik,that.sopstvenik)==0))
- return true;
- else
- return false;
- }
- bool equalsType(const File & that)
- {
- if(tip==that.tip)
- {
- return true;
- }
- else
- return false;
- }
- };
- class Folder
- {
- char *ime;
- int broj;
- File *files;
- public:
- Folder (char *ime)
- { this->ime= new char [strlen(ime)+1];
- strcpy(this->ime,ime);
- this->broj=0;
- this->files= new File [broj];
- }
- Folder (const Folder &f)
- {
- this->ime= new char [strlen(f.ime)+1];
- strcpy(this->ime,f.ime);
- this->broj=f.broj;
- this->files= new File [broj];
- for(int i=0;i<broj;i++)
- {
- this->files[i]=files[i];
- }
- }
- Folder operator= ( const Folder &f)
- {
- if(this!=&f)
- {
- delete [] ime; delete [] files;
- this->ime= new char [strlen(f.ime)+1];
- strcpy(this->ime,f.ime);
- this->broj=f.broj;
- this->files= new File [broj];
- for(int i=0;i<broj;i++)
- {
- this->files[i]=files[i];
- }
- }
- return *this;
- }
- void print()
- {
- cout<<"Folder name: "<<ime<<endl;
- for (int i=0;i<broj;i++)
- {
- files[i].print();
- }
- }
- void add(const File & file)
- {
- File *tmp= new File [broj+1];
- for(int i=0; i<broj; i++) {
- tmp[i]=files[i];
- }
- tmp[broj++]=file;
- delete [] files;
- files=tmp;
- }
- void remove(const File & ff){
- int count=0;
- for(int i=0; i<broj; i++) {
- if(!(files[i].equals(ff))) {
- count++;
- }
- }
- File *tmp = new File[count];
- count=0;
- for(int i=0; i<broj; i++) {
- if(!(files[i].equals(ff))) {
- tmp[count++]=files[i];
- }
- }
- delete [] files;
- files=tmp;
- broj=count;
- }
- };
- int main() {
- char fileName[20];
- char fileOwner[20];
- int ext;
- int fileSize;
- int testCase;
- cin >> testCase;
- if (testCase == 1) {
- cout << "======= FILE CONSTRUCTORS AND = OPERATOR =======" << endl;
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File created = File(fileName, fileOwner, fileSize, (Tip) ext);
- File copied = File(created);
- File assigned = created;
- cout << "======= CREATED =======" << endl;
- created.print();
- cout << endl;
- cout << "======= COPIED =======" << endl;
- copied.print();
- cout << endl;
- cout << "======= ASSIGNED =======" << endl;
- assigned.print();
- }
- else if (testCase == 2) {
- cout << "======= FILE EQUALS & EQUALS TYPE =======" << endl;
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File first(fileName, fileOwner, fileSize, (Tip) ext);
- first.print();
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File second(fileName, fileOwner, fileSize, (Tip) ext);
- second.print();
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File third(fileName, fileOwner, fileSize, (Tip) ext);
- third.print();
- bool equals = first.equals(second);
- cout << "FIRST EQUALS SECOND: ";
- if (equals)
- cout << "TRUE" << endl;
- else
- cout << "FALSE" << endl;
- equals = first.equals(third);
- cout << "FIRST EQUALS THIRD: ";
- if (equals)
- cout << "TRUE" << endl;
- else
- cout << "FALSE" << endl;
- bool equalsType = first.equalsType(second);
- cout << "FIRST EQUALS TYPE SECOND: ";
- if (equalsType)
- cout << "TRUE" << endl;
- else
- cout << "FALSE" << endl;
- equalsType = second.equals(third);
- cout << "SECOND EQUALS TYPE THIRD: ";
- if (equalsType)
- cout << "TRUE" << endl;
- else
- cout << "FALSE" << endl;
- }
- else if (testCase == 3) {
- cout << "======= FOLDER CONSTRUCTOR =======" << endl;
- cin >> fileName;
- Folder folder(fileName);
- folder.print();
- }
- else if (testCase == 4) {
- cout << "======= ADD FILE IN FOLDER =======" << endl;
- char name[20];
- cin >> name;
- Folder folder(name);
- int iter;
- cin >> iter;
- while (iter > 0) {
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File file(fileName, fileOwner, fileSize, (Tip) ext);
- folder.add(file);
- iter--;
- }
- folder.print();
- }
- else {
- cout << "======= REMOVE FILE FROM FOLDER =======" << endl;
- char name[20];
- cin >> name;
- Folder folder(name);
- int iter;
- cin >> iter;
- while (iter > 0) {
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File file(fileName, fileOwner, fileSize, (Tip) ext);
- folder.add(file);
- iter--;
- }
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File file(fileName, fileOwner, fileSize, (Tip) ext);
- folder.remove(file);
- folder.print();
- }
- return 0;
- }
- 7.FAKTURA
- #include <stdio.h>
- #include <string.h>
- #include <stdio.h>
- #include <string.h>
- typedef struct Proizvod {
- char kod[20];
- int cena;
- int lager;
- } Proizvod;
- typedef struct Narachka {
- char ime[15];
- Proizvod proizvodi[10];
- int narProizvodi[10];
- int n;
- } Narachka;
- void pecatiFaktura(Narachka n) {
- printf("Faktura za %s\n",n.ime);
- int i,flag=0,j;
- Proizvod temp;
- for(i=0; i<n.n; i++) {
- if(n.proizvodi[i].lager-n.narProizvodi[i]<0)
- flag = 1;
- }
- if(flag)
- printf("Fakturata ne moze da se izgotvi");
- else {
- 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) {
- temp=n.proizvodi[i];
- n.proizvodi[i]=n.proizvodi[j];
- n.proizvodi[j]=temp;
- }
- }
- }
- int s=0;
- for(i=0; i<n.n; i++) {
- printf("%s %d %d %d\n",n.proizvodi[i].kod,n.proizvodi[i].cena,n.narProizvodi[i],n.proizvodi[i].cena*n.narProizvodi[i]);
- s+=n.proizvodi[i].cena*n.narProizvodi[i];
- }
- printf("Vkupnata suma na fakturata e %d",s);
- }
- }
- int main() {
- char ime[15],kod[20];
- int cena,lager,n,i,j;
- Narachka narachka;
- Proizvod proizvodi[30];
- scanf("%s",narachka.ime);
- scanf("%d",&narachka.n);
- for (i = 0; i < narachka.n; ++i) {
- scanf("%s",proizvodi[i].kod);
- scanf("%d",&proizvodi[i].cena);
- scanf("%d",&proizvodi[i].lager);
- narachka.proizvodi[i]=proizvodi[i];
- }
- for (j = 0; j < narachka.n; ++j) {
- scanf("%d",&narachka.narProizvodi[j]);
- }
- pecatiFaktura(narachka);
- return 0;
- }
- //место за вашиот код
- /*int main() {
- Narachka narachka;
- // внеси го името лицето кое ја прави нарачката
- // внеси го бројот на порачани производи во нарачката
- int i;
- //за секој од нарачаните производи се внесуваат информации
- for (i = 0; i < narachka.n; ++i) {
- // внеси код
- // внеси единицчна цена
- // внеси број на производи во магацин
- }
- //за секој производ се внесува колку такви производи се порачани во нарачката
- int j;
- for (j = 0; j < narachka.n; ++j) {
- //се внесува број на производи во нарачката
- }
- // повик на функцијата pecatiFaktura
- return 0;
- }*/
- 8.VOZ(TOCNA E SAMO FALAT PRAZNI MESTA U PECATENJETO)
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Patnik //od nego se pravi niza
- {
- public: //namerno se public so ogled na toa shto tupa zadacha dale
- char ime[100];
- int klasa;
- bool velosiped;
- Patnik() {}
- Patnik(char *ime,int kl,bool v)
- {
- strcpy(this->ime,ime); //KOGA IMATE ISTI IMINJA: THIS->
- klasa = kl;
- velosiped = v;
- }
- // кај динамичка алокација секогаш мора да се оптовари доделувањето
- // copy конструкторот да се напише и деструктор , сите три работи!
- //copy-konstruktor:
- Patnik ( const Patnik &p)
- {
- strcpy(ime, p.ime);
- klasa=p.klasa;
- velosiped=p.velosiped;
- }
- Patnik &operator =( const Patnik &p)
- {
- if(this!=&p)
- {
- strcpy(ime, p.ime);
- klasa=p.klasa;
- velosiped=p.velosiped;
- }
- return *this;
- }
- friend ostream &operator <<(ostream &o, Patnik &p)
- {
- o << p.ime<< endl;
- o << p.klasa <<endl;
- o << p.velosiped << endl;
- return o;
- }
- ~Patnik() {}
- };
- class Voz
- {
- private:
- char krajnaDestinacija[100];
- Patnik *p;
- int brElemeni;
- int brVelosipedi;
- public:
- Voz(char *kD="",int brV=0,Patnik *niza=0,int brEl=0 )//DIREKTNA INICIJALIZACIJA FALESHE + dopuna
- {
- strcpy(krajnaDestinacija,kD);
- brVelosipedi = brV; //vtoriot argument e max broj na velosipedi
- brElemeni = brEl;
- p = new Patnik[brElemeni];
- for (int i = 0; i<brElemeni; i++)
- p[i] = niza[i];
- }
- Voz(const Voz &v)
- {
- strcpy(krajnaDestinacija,v.krajnaDestinacija);
- this->brElemeni=v.brElemeni;
- this->brVelosipedi=v.brVelosipedi;
- this->p = new Patnik [brElemeni];
- for (int i = 0; i<brElemeni; i++)
- p[i] =v.p[i];
- }
- Voz &operator =(const Voz &v)
- {
- if(this!=&v)
- {
- delete [] p;
- brElemeni = v.brElemeni;
- for(int i=0; i < brElemeni; i++)
- {
- p[i]=v.p[i];
- }
- p= new Patnik[brElemeni];
- strcpy(krajnaDestinacija,v.krajnaDestinacija);
- brVelosipedi = v.brVelosipedi;
- }
- return *this;
- }
- Voz &operator += (Patnik x) // se dodava objekt Patnik vo objekt Voz
- {
- Patnik * pomNiza = new Patnik [brElemeni + 1 ];
- if(brElemeni == 0){ // ova e za ПРВИОТ objekt Patnik
- //za da raboti dodeluvanjeto mora da se optovari = kaj patnik!
- pomNiza[brElemeni++] = x;
- delete[]p;
- p=pomNiza;
- return * this;
- }
- else { // ОВА Е ЗА СИТЕ НАРЕДНИ
- for (int i = 0; i<brElemeni; i++)
- //za da raboti dodeluvanjeto mora da se optovari = kaj patnik!
- pomNiza[i] = p[i];
- pomNiza[brElemeni++] = x;
- delete[]p;
- p=pomNiza;
- return * this ;
- }
- }
- friend ostream &operator <<(ostream &o, const Voz &v)// ФАЛЕШЕ const
- {
- o << v.krajnaDestinacija<<endl;
- for(int i = 0; i < v.brElemeni; i++)
- {
- o << v.p[i];
- }
- return o;
- }
- void patniciNemaMesto() // samo pechatime , pa taka VOID vrshi rabota
- {
- int brPrva=0; //pomoshna brojach za prvaKlasa patnici
- int brVtora=0; //pomoshna brojach za vtoraKlasa patnici
- int kvota=0; //koga kje se napolni 10 pochnuvaat brojachite da brojat
- /*koja e idejata, znachi od MAINOT gledate deka vkupno mesta za velosipedi se 10,
- e sega, prvo smeat da vlezat velosipedisti od prva klasa, tie se so redni broevi:
- ime, 1, 1. takvi gi ima 11 na broj, znachi eden ostanuva, mestata se napolneti i
- site velosipedisto od vtora klasa : ime, 2, 1 . isto se nadvor a takvi se Mimi i Kiki
- ajde sega i kodot*/
- for(int i=0 ; i< brElemeni;i++){
- if(p[i].klasa==1&&p[i].velosiped){
- kvota++;
- }
- }
- if(kvota>=10){
- brPrva=kvota-10;
- kvota=10; //da se dobie vishok na patnici od vtora klasa
- }
- //istoto i za vtoa klasa:
- for(int i =0; i< brElemeni;i++){
- if(p[i].klasa==2 && p[i].velosiped){
- kvota++;
- }
- }
- if(kvota>=10)
- brVtora=kvota-10;
- cout << "Brojot na patnici od 1-va klasa koi ostanale bez mesto e: "<<brPrva<<endl;
- cout << "Brojot na patnici od 2-va klasa koi ostanale bez mesto e: "<<brVtora;
- }
- ~Voz()
- {
- delete [] p;
- }
- };
- 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<<endl;;
- v.patniciNemaMesto();
- return 0;
- }
- 10.RABOTNI CASOVI
- #include <stdio.h>
- #include <string.h>
- #define NEDELI 4
- #define DENOVI 5
- // ovde strukturata RabotnaNedela
- struct RabotnaNedela{
- int broj;
- int rabotniCasovi[5];
- };
- typedef struct RabotnaNedela RN;
- // ovde strukturata Rabotnik
- struct Rabotnik{
- char ime[50];
- RN nedeli[4];
- };
- typedef struct Rabotnik R;
- int maxNedela(R *r)
- {
- int maxCasovi=0;
- int maxNedela=0;
- int i;
- for(i=0;i<4;i++)
- {
- int casoviNedela=0;
- int j=0;
- for(j=0;j<5;j++)
- {
- casoviNedela+=r->nedeli[i].rabotniCasovi[j];
- }
- if (casoviNedela>maxCasovi)
- {
- maxCasovi=casoviNedela;
- maxNedela=i;
- }
- }
- return maxNedela+1;
- }
- void table(R *r, int n)
- {
- printf("Rab\t1\t2\t3\t4\tVkupno\n");
- int i,j;
- for(i=0;i<n;i++)
- {
- int vkupno=0;
- printf("%s\t",r[i].ime);
- for(j=0;j<4;j++)
- {
- int vkupnoCasovi=0;
- int z=0;
- for(z=0;z<5;z++)
- {
- vkupnoCasovi+=r[i].nedeli[j].rabotniCasovi[z];
- }
- printf("%d\t",vkupnoCasovi);
- vkupno+=vkupnoCasovi;
- }
- printf("%d\n",vkupno);
- }
- }
- // ovde funkciite
- 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].rabotniCasovi[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;
- }
- 11.TANCERI
- #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)
- {
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<n;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;
- }
- 12.RABOTNI CASOVI (40 POENA)
- #include <stdio.h>
- #include <string.h>
- #define NEDELI 4
- #define DENOVI 5
- // ovde strukturata RabotnaNedela
- struct RabotnaNedela{
- int broj;
- int rabotniCasovi[5];
- };
- typedef struct RabotnaNedela RN;
- // ovde strukturata Rabotnik
- struct Rabotnik{
- char ime[50];
- RN nedeli[4];
- };
- typedef struct Rabotnik R;
- int maxNedela(R *r)
- {
- int maxCasovi=0;
- int maxNedela=0;
- int i;
- for(i=0;i<4;i++)
- {
- int casoviNedela=0;
- int j=0;
- for(j=0;j<5;j++)
- {
- casoviNedela+=r->nedeli[i].rabotniCasovi[j];
- }
- if (casoviNedela>maxCasovi)
- {
- maxCasovi=casoviNedela;
- maxNedela=i;
- }
- }
- return maxNedela+1;
- }
- void table(R *r, int n)
- {
- printf("Rab\t1\t2\t3\t4\tVkupno\n");
- int i,j;
- for(i=0;i<n;i++)
- {
- int vkupno=0;
- printf("%s\t",r[i].ime);
- for(j=0;j<4;j++)
- {
- int vkupnoCasovi=0;
- int z=0;
- for(z=0;z<5;z++)
- {
- vkupnoCasovi+=r[i].nedeli[j].rabotniCasovi[z];
- }
- printf("%d\t",vkupnoCasovi);
- vkupno+=vkupnoCasovi;
- }
- printf("%d\n",vkupno);
- }
- }
- // ovde funkciite
- 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].rabotniCasovi[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;
- }
- 5.LIST CONTAINER
- 14.STRUKTURA VO C
- 15.AKCII
- 16.ZABAVEN PARK
- 17.GITARI
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Gitara{
- char seriski[25];
- double nabavna;
- int godinaProizvodstvo;
- char tip[40];
- public:
- Gitara(const char *tip=" ", const char * seriski =" ",int godinaProizvodstvo=0,double nabavna =0)
- {
- strcpy(this->tip,tip);
- strcpy(this->seriski,seriski);
- this->godinaProizvodstvo=godinaProizvodstvo;
- this->nabavna=nabavna;
- }
- Gitara (const Gitara &g)
- {
- strcpy(this->tip,g.tip);
- strcpy(this->seriski,g.seriski);
- this->godinaProizvodstvo=g.godinaProizvodstvo;
- this->nabavna=g.nabavna;
- }
- Gitara &operator= (const Gitara &g)
- {
- strcpy(this->tip,g.tip); strcpy(this->seriski,g.seriski);
- this->godinaProizvodstvo=g.godinaProizvodstvo;
- this->nabavna=g.nabavna;
- return *this;
- }
- bool daliisti(Gitara g)
- {
- if(strcmp(seriski,g.seriski)==0)
- return true;
- else
- return false;
- }
- void pecati()
- {
- cout<<seriski<<" "<<tip<<" "<<nabavna<<endl;
- }
- friend class Magacin;
- double getNabavna()
- {
- return nabavna;
- }
- char * getTip()
- {
- return tip;
- }
- char * getSeriski()
- {
- return seriski;
- }
- int getGodina()
- {
- return godinaProizvodstvo;
- }
- };
- class Magacin{
- char ime_mag[30];
- char lokacija[60];
- Gitara *git;
- int brg;
- int otvaranje;
- public:
- Magacin(const char *ime_mag=" ", const char *lokacija=" ", int otvaranje=0)
- {
- strcpy(this->ime_mag,ime_mag);
- strcpy(this->lokacija,lokacija);
- this->brg=0;
- this->otvaranje=otvaranje;
- this->git= new Gitara [brg];
- }
- Magacin(const Magacin &m)
- {
- strcpy(this->ime_mag,m.ime_mag);
- strcpy(this->lokacija,m.lokacija);
- this->brg=m.brg;
- this->otvaranje=m.otvaranje;
- this->git= new Gitara [brg];
- for(int i=0;i<brg;i++)
- {
- this->git[i]=m.git[i];
- }
- }
- Magacin &operator=(const Magacin &m)
- {
- if(this!=&m){
- strcpy(this->ime_mag,m.ime_mag);
- strcpy(this->lokacija,m.lokacija);
- this->brg=m.brg;
- this->otvaranje=m.otvaranje;
- delete [] git;
- this->git= new Gitara [brg];
- for(int i=0;i<brg;i++)
- {
- this->git[i]=m.git[i];
- }}
- return *this;
- }
- double vrednost ()
- {
- double suma=0;
- for(int i=0;i<brg;i++)
- {
- suma+=git[i].nabavna;
- }
- return suma;
- }
- void dodadi(const Gitara &d)
- {
- Gitara *tmp= new Gitara [brg+1];
- for(int i=0;i<brg;i++){
- tmp[i]=git[i];
- }
- tmp[brg++]=d;
- delete [] git;
- git=tmp;
- }
- void prodadi(const Gitara &p)
- {
- int count =0;
- for(int i=0;i<brg;i++)
- {
- if(git[i].daliisti(p)==false)
- {
- count++;
- }
- }
- Gitara *tmp= new Gitara [count];
- int newcount=0;
- for(int i=0;i<brg;i++)
- {
- if(git[i].daliisti(p)==false)
- {
- tmp[newcount]=git[i];
- newcount++;
- }
- }
- delete [] git;
- git=tmp;
- brg=count;
- }
- void pecati(bool daliNovi){
- cout<<ime_mag<<" "<<lokacija<<endl;
- for(int i=0;i<brg;i++)
- if(daliNovi==true&&git[i].godinaProizvodstvo>otvaranje)
- {
- git[i].pecati();
- }
- else if(daliNovi==false){
- git[i].pecati();
- }
- }
- };
- /*
- class Gitara{
- private:
- char seriski[25];
- double nabavna;
- int godinaProizvodstvo;
- char tip[40];
- public:
- Gitara(char *tip="",char * seriski ="",int godinaProizvodstvo=0,double nabavna =0)
- {
- strcpy(this->tip,tip);
- strcpy(this->seriski,seriski);
- this->godinaProizvodstvo = godinaProizvodstvo;
- this->nabavna = nabavna;
- }
- Gitara(const Gitara &g)
- {
- strcpy(this->tip,g.tip);
- strcpy(this->seriski,g.seriski);
- this->godinaProizvodstvo = g.godinaProizvodstvo;
- this->nabavna = g.nabavna;
- }
- Gitara & operator=(const Gitara &g)
- {
- strcpy(this->tip,g.tip);
- strcpy(this->seriski,g.seriski);
- this->godinaProizvodstvo = g.godinaProizvodstvo;
- this->nabavna = g.nabavna;
- return *this;
- }
- ~Gitara()
- {
- }
- bool daliIsti(Gitara &g)
- {
- return strcmp(this->seriski,g.seriski)==0;
- }
- void pecati()
- {
- cout<<seriski<<" "<<tip<<" "<<nabavna<<endl;
- }
- double getNabavna()
- {
- return nabavna;
- }
- char * getTip()
- {
- return tip;
- }
- char * getSeriski()
- {
- return seriski;
- }
- int getGodina()
- {
- return godinaProizvodstvo;
- }
- };
- class Magacin{
- private:
- char lokacija[60];
- char ime[50];
- int godinaOtvaranje;
- Gitara * niza;
- int brGitari;
- public:
- Magacin(char * ime="",char * lokacija="",int godinaOtvaranje=0)
- {
- strcpy(this->lokacija,lokacija);
- strcpy(this->ime,ime);
- this->godinaOtvaranje = godinaOtvaranje;
- niza = NULL;
- brGitari = 0;
- }
- Magacin(const Magacin & m)
- {
- strcpy(this->lokacija,m.lokacija);
- strcpy(this->ime,m.ime);
- this->godinaOtvaranje = m.godinaOtvaranje;
- niza = new Gitara[m.brGitari];
- for(int i =0;i<m.brGitari;i++)
- niza[i] = m.niza[i];
- brGitari = m.brGitari;
- }
- Magacin & operator=(const Magacin & m)
- {
- delete [] niza;
- strcpy(this->lokacija,m.lokacija);
- strcpy(this->ime,m.ime);
- this->godinaOtvaranje = m.godinaOtvaranje;
- niza = new Gitara[m.brGitari];
- for(int i =0;i<m.brGitari;i++)
- niza[i] = m.niza[i];
- brGitari = m.brGitari;
- return *this;
- }
- ~Magacin(){delete [] niza;}
- double vrednost()
- {
- double sum=0;
- for(int i=0;i<brGitari;i++)
- sum+=niza[i].getNabavna();
- return sum;
- }
- void dodadi(Gitara & g)
- {
- Gitara * tmp = new Gitara[brGitari +1];
- for(int i=0;i<brGitari;i++)
- tmp[i] = niza[i];
- tmp[brGitari++]=g;
- delete [] niza;
- niza=tmp;
- }
- void prodadi(Gitara & g)
- {
- int newBr = 0;
- for(int i=0;i<brGitari;i++)
- {
- if(niza[i].daliIsti(g)==false)
- {
- newBr++;
- }
- }
- Gitara * tmp = new Gitara[newBr];
- int j=0;
- for(int i=0;i<brGitari;i++)
- {
- if(niza[i].daliIsti(g)==false)
- {
- tmp[j] = niza[i];
- j++;
- }
- }
- delete [] niza;
- niza = tmp;
- brGitari = newBr;
- }
- void pecati(bool daliNovi)
- {
- cout<<ime<<" "<< lokacija<<endl;
- for(int i=0;i<brGitari;i++)
- {
- if(daliNovi==true&&niza[i].getGodina()>godinaOtvaranje)
- {
- niza[i].pecati();
- }
- else if(daliNovi==false){
- niza[i].pecati();
- }
- }
- }
- };*/
- int main() {
- // se testira zadacata modularno
- int testCase;
- cin >> testCase;
- int n, godina;
- float cena;
- char seriski[50],tip[50];
- if(testCase == 1) {
- cout << "===== Testiranje na klasata Gitara ======" << endl;
- cin>>tip;
- cin>>seriski;
- cin >> godina;
- cin >> cena;
- Gitara g(tip,seriski, godina,cena);
- cout<<g.getTip()<<endl;
- cout<<g.getSeriski()<<endl;
- cout<<g.getGodina()<<endl;
- cout<<g.getNabavna()<<endl;
- } else if(testCase == 2){
- cout << "===== Testiranje na klasata Magacin so metodot print() ======" << endl;
- Magacin kb("Magacin1","Lokacija1");
- kb.pecati(false);
- }
- else if(testCase == 3) {
- cout << "===== Testiranje na klasata Magacin so metodot dodadi() ======" << endl;
- Magacin kb("Magacin1","Lokacija1",2005);
- cin>>n;
- for (int i=0;i<n;i++){
- cin>>tip;
- cin>>seriski;
- cin >> godina;
- cin >> cena;
- Gitara g(tip,seriski, godina,cena);
- cout<<"gitara dodadi"<<endl;
- kb.dodadi(g);
- }
- kb.pecati(true);
- }
- else if(testCase == 4) {
- cout << "===== Testiranje na klasata Magacin so metodot prodadi() ======" << endl;
- Magacin kb("Magacin1","Lokacija1",2012);
- cin>>n;
- Gitara brisi;
- for (int i=0;i<n;i++){
- cin>>tip;
- cin>>seriski;
- cin >> godina;
- cin >> cena;
- Gitara g(tip,seriski, godina,cena);
- if(i==2)
- brisi=g;
- cout<<"gitara dodadi"<<endl;
- kb.dodadi(g);
- }
- kb.pecati(false);
- kb.prodadi(brisi);
- kb.pecati(false);
- }
- else if(testCase == 5) {
- cout << "===== Testiranje na klasata Magacin so metodot prodadi() i pecati(true) ======" << endl;
- Magacin kb("Magacin1","Lokacija1",2011);
- cin>>n;
- Gitara brisi;
- for (int i=0;i<n;i++){
- cin>>tip;
- cin>>seriski;
- cin >> godina;
- cin >> cena;
- Gitara g(tip,seriski, godina,cena);
- if(i==2)
- brisi=g;
- cout<<"gitara dodadi"<<endl;
- kb.dodadi(g);
- }
- kb.pecati(true);
- kb.prodadi(brisi);
- cout<<"Po brisenje:"<<endl;
- Magacin kb3;
- kb3=kb;
- kb3.pecati(true);
- }
- else if(testCase ==6)
- {
- cout << "===== Testiranje na klasata Magacin so metodot vrednost()======" << endl;
- Magacin kb("Magacin1","Lokacija1",2011);
- cin>>n;
- Gitara brisi;
- for (int i=0;i<n;i++){
- cin>>tip;
- cin>>seriski;
- cin >> godina;
- cin >> cena;
- Gitara g(tip,seriski, godina,cena);
- if(i==2)
- brisi=g;
- kb.dodadi(g);
- }
- cout<<kb.vrednost()<<endl;
- kb.prodadi(brisi);
- cout<<"Po brisenje:"<<endl;
- cout<<kb.vrednost();
- Magacin kb3;
- kb3=kb;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement