Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Скијачки центар
- #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;
- }
- 1. Компјутерска игра
- #include<iostream>
- #include <cstring>
- #include <string>
- using namespace std;
- struct Igrac{
- string Ime;
- int nivo;
- int poeni;
- };
- struct KompjuterskaIgra{
- string ImeIgra;
- Igrac igraci[30];
- int brigraci;
- }igri[100];
- void najdobarIgrac(KompjuterskaIgra *lista, int n){
- int i,j,maxpoena=0,maxnivo=0;
- string ndigra;
- string ndigrach;
- for (i=0;i<n;i++){
- for (j=0;j<lista[i].brigraci;j++){
- if(lista[i].igraci[j].poeni==maxpoena){
- if (lista[i].igraci[j].nivo>maxnivo) {
- maxpoena=lista[i].igraci[j].poeni;
- maxnivo=lista[i].igraci[j].nivo;
- ndigra=lista[i].ImeIgra;
- // ndigrach=new char[strlen(lista[i].igraci[j].Ime)+1];
- // strcpy(ndigrach,lista[i].igraci[j].Ime);
- ndigrach=lista[i].igraci[j].Ime;
- }} else
- if(lista[i].igraci[j].poeni>maxpoena){
- maxpoena=lista[i].igraci[j].poeni;
- maxnivo=lista[i].igraci[j].nivo;
- ndigra=lista[i].ImeIgra;
- ndigrach=lista[i].igraci[j].Ime;
- }
- };
- };
- //cout<<"zdr"<<endl;
- cout<<"Najdobar igrac e igracot so korisnicko ime "<<ndigrach<<" koj ja igra igrata "<<ndigra<<endl;
- //sostojki=new char [strlen(p.sostojki)+1];
- //strcpy(sostojki,p.sostojki);
- }
- int main(){
- int n;
- cin>>n; //se cita brojot na igri
- //cout<<n<<endl;
- KompjuterskaIgra igri[100];
- for (int i=0;i<n;i++){
- cin>>igri[i].ImeIgra;
- //cout<<igri[i].ImeIgra<<endl;
- cin>>igri[i].brigraci;
- //cout<<igri[i].brigraci<<endl;
- for (int j=0;j<igri[i].brigraci;j++){
- //cout<<j<<"eve go"<<endl;
- //strcpy(cin,lista[j].igraci[i].Ime);
- //lista[j].igraci[i].Ime=new char [strlen()]
- //getline(cin,igri[i].igraci[j].Ime);
- cin>>igri[i].igraci[j].Ime;
- //cout<<igri[i].igraci[j].Ime<<endl;
- cin>>igri[i].igraci[j].nivo;
- cin>>igri[i].igraci[j].poeni;
- };
- };
- najdobarIgrac(igri,n);
- return 0;
- }
- 2. Железничка станица
- #include<iostream>
- #include <cstring>
- using namespace std;
- struct Voz{
- char relacija[50];
- float km;
- int brojPatnici;
- };
- struct ZeleznickaStanica{
- char grad[20];
- Voz vozovi[30];
- int brojVozovi;
- };
- void najkratkaRelacija(ZeleznickaStanica* zs, int n, char* grad){
- Voz minRelacija;
- minRelacija.km=10000000;
- for (int i=0;i<n;i++){
- if(strcmp(zs[i].grad,grad)==0){
- for(int j=0;j<zs[i].brojVozovi;++j){
- if(zs[i].vozovi[j].km<=minRelacija.km){
- minRelacija=zs[i].vozovi[j];
- }
- }
- }
- }
- cout<<"Najkratka relacija: "<<minRelacija.relacija<<" ("<<minRelacija.km<<" 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>>zStanica[i].brojVozovi;
- for(int j=0;j<zStanica[i].brojVozovi;j++){
- cin>>zStanica[i].vozovi[j].relacija>>zStanica[i].vozovi[j].km>>zStanica[i].vozovi[j].brojPatnici;
- }
- }
- char grad[25];
- cin>>grad;
- najkratkaRelacija(zStanica,n,grad);
- return 0;
- }
- 2. CD
- #include <iostream>
- #include <cstring>
- using namespace std;
- enum tip {pop,rap,rok };
- class Pesna {
- private:
- char *ime;
- int minuti;
- tip muzika;
- public:
- Pesna () {}
- Pesna (char *i,int m,tip muz) {
- ime=new char [strlen(i)+1];
- strcpy(ime,i);
- minuti=m;
- muzika=muz;
- }
- void pecati() {
- cout<<"\""<<ime<<"\""<<"-"<<minuti<<"min"<<endl;
- }
- int getmin ()
- {
- return minuti;
- }
- tip getTip()
- {
- return muzika;
- }
- };
- class CD {
- private:
- Pesna pesni[10];
- int n;
- int max;
- public:
- CD () { }
- CD (int max) {
- this->max=max;
- n=0;
- }
- CD & dodadiPesna (Pesna p)
- {
- ++n;
- int temp=0;
- for(int i=0; i<n-1; i++)
- {
- temp+=pesni[i].getmin();
- }
- if(n>10 || max<(temp+p.getmin()))
- {
- --n;
- return *this;
- }
- pesni[n-1]=p;
- return *this;
- }
- Pesna & getPesna (int k)
- {
- return pesni[k];
- }
- int getBroj ()
- {
- return n;
- }
- void pecatiPesniPoTip(tip t)
- {
- for(int i=0; i<n; 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;
- }
- 3. Пицерија
- #include <iostream>
- #include <cstring>
- using namespace std;
- //Vasiot kod tuka
- class Pica{
- private:
- char ime[15];
- int cena;
- char *sostojki;
- int namaluvanje=0;
- public:
- Pica(char* ime="",int cena=0,char* sostojki="",int namaluvanje=0){
- strncpy(this->ime,ime,15);
- this->cena=cena;
- this->namaluvanje=namaluvanje;
- this->sostojki=new char [strlen(sostojki)+1];
- strcpy(this->sostojki,sostojki);
- }
- Pica(const Pica &p){
- strncpy(this->ime,p.ime,15);
- this->cena=p.cena;
- this->namaluvanje=p.namaluvanje;
- this->sostojki=new char [strlen(p.sostojki)+1];
- strcpy(this->sostojki,p.sostojki);
- }
- Pica& operator=(const Pica& p){
- if(this!=&p){
- strncpy(this->ime,p.ime,15);
- this->cena=p.cena;
- this->namaluvanje=p.namaluvanje;
- this->sostojki=new char [strlen(p.sostojki)+1];
- strcpy(this->sostojki,p.sostojki);
- }
- return *this;
- }
- ~Pica(){
- delete [] sostojki;
- }
- void pecati(){
- cout<<ime<<" - "<<sostojki<<", "<<cena<<" ";
- if(namaluvanje>0&&namaluvanje<=100){
- cout<<cena-cena*namaluvanje/100<<endl;
- }
- }
- bool istiSe(Pica &p){
- if(strcmp(this->sostojki,p.sostojki)==0) return true;
- else return false;
- }
- char* getSostojki(){
- return sostojki;
- }
- int getNamaluvanje(){
- return namaluvanje;
- }
- };
- class Picerija{
- private:
- char ime[15];
- Pica *pici;
- int brojPici;
- public:
- Picerija(){}
- Picerija(char *ime){
- strncpy(this->ime,ime,15);
- pici=new Pica [0];
- brojPici=0;
- }
- Picerija(const Picerija& p){
- strncpy(this->ime,p.ime,15);
- this->brojPici=p.brojPici;
- this->pici=new Pica [brojPici];
- for(int i=0;i<brojPici;i++){
- this->pici[i]=p.pici[i];
- }
- }
- ~Picerija(){
- delete [] pici;
- }
- void dodadi(Pica &p){
- int flag=0;
- for(int i=0;i<brojPici;i++){
- if(strcmp(this->pici[i].getSostojki(),p.getSostojki())==0){
- flag=1;
- }
- }
- if(flag==0){
- Pica *tmp=new Pica[brojPici];
- for(int i=0;i<brojPici;i++){
- tmp[i]=this->pici[i];
- }
- delete [] this->pici;
- this->pici=new Pica[brojPici+1];
- for(int i=0;i<brojPici;i++){
- this->pici[i]=tmp[i];
- }
- this->pici[brojPici]=p;
- delete [] tmp;
- brojPici++;
- }
- }
- char* getIme(){
- return this->ime;
- }
- void piciNaPromocija(){
- for(int i=0;i<brojPici;i++){
- if((this->pici[i].getNamaluvanje())!=0){
- this->pici[i].pecati();
- }
- }
- }
- void setIme(char* ime){
- strncpy(this->ime,ime,15);
- }
- };
- 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;
- }
- 4. Маратон
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Ucesnik{
- private:
- char *ime;
- bool pol;
- int vozrast;
- public:
- Ucesnik(char *ime="",bool pol=0,int vozrast=0){
- this->ime=new char [strlen(ime)+1];
- strcpy(this->ime,ime);
- this->pol=pol;
- this->vozrast=vozrast;
- }
- ~Ucesnik(){
- delete [] ime;
- }
- Ucesnik& operator=(const Ucesnik& u){
- if(this!=&u){
- delete [] this->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 operator>(Ucesnik &u){
- return this->vozrast>u.vozrast;
- }
- friend ostream& operator<<(ostream& out,Ucesnik& u){
- out<<u.ime<<endl;
- if(u.pol==0) {
- out<<"zhenski"<<endl;
- } else {
- out<<"mashki"<<endl;
- }
- out<<u.vozrast<<endl;
- return out;
- }
- int getVozrast(){
- return this->vozrast;
- }
- };
- class Maraton{
- private:
- char lokacija[100];
- Ucesnik *ucesnici;
- int brojUcesnici;
- public:
- Maraton(){}
- Maraton(char* lokacija){
- strncpy(this->lokacija,lokacija,strlen(lokacija)+1);
- ucesnici=new Ucesnik[0];
- brojUcesnici=0;
- }
- ~Maraton(){
- delete [] ucesnici;
- }
- Maraton& operator+=(Ucesnik &u){
- Ucesnik *tmp=new Ucesnik [this->brojUcesnici];
- for(int i=0;i<this->brojUcesnici;i++){
- tmp[i]=this->ucesnici[i];
- }
- delete [] ucesnici;
- ucesnici=new Ucesnik [brojUcesnici+1];
- for(int i=0;i<this->brojUcesnici;i++){
- this->ucesnici[i]=tmp[i];
- }
- this->ucesnici[brojUcesnici]=u;
- delete [] tmp;
- brojUcesnici++;
- return *this;
- }
- float prosecnoVozrast(){
- int sum=0;
- for(int i=0;i<brojUcesnici;i++){
- sum+=this->ucesnici[i].getVozrast();
- }
- return (float)sum/brojUcesnici;
- }
- void pecatiPomladi(Ucesnik &u){
- for(int i=0;i<brojUcesnici;i++){
- if(this->ucesnici[i].getVozrast()<u.getVozrast()){
- cout<<this->ucesnici[i];
- }
- }
- }
- };
- 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;
- }
- 5. Сладолед
- #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;
- }
- 6. Планинарски дом
- #include<iostream>
- #include<string.h>
- using namespace std;
- class Zichara {
- private:
- char *place;
- int dayPrice;
- public:
- Zichara() {
- place = new char[0];
- }
- Zichara(char *place, int price) {
- this->place = new char[strlen(place)+1];
- strcpy(this->place,place);
- dayPrice = price;
- }
- ~Zichara() {
- delete [] place;
- }
- Zichara(const Zichara &z) {
- place = new char[strlen(z.place)+1];
- strcpy(place,z.place);
- dayPrice = z.dayPrice;
- }
- Zichara& operator=(const Zichara &z) {
- if(this != &z){
- delete [] place;
- place = new char[strlen(z.place)+1];
- dayPrice = z.dayPrice;
- }
- return *this;
- }
- int getPrice () {
- return dayPrice;
- }
- };
- class PlaninarskiDom {
- private:
- char name[15];
- int prices [2];
- char clas;
- bool itHas;
- Zichara zichara;
- public:
- PlaninarskiDom() {
- itHas = false;
- }
- PlaninarskiDom (char *name, int *prices, char clas) {
- strcpy(this->name,name);
- for(int i=0; i<2; i++)
- this->prices[i] = prices[i];
- this->clas = clas;
- }
- ~PlaninarskiDom() {}
- PlaninarskiDom& operator=(const PlaninarskiDom &p) {
- if(this != &p){
- strcpy(name,p.name);
- for(int i=0; i<2; i++)
- prices[i] = p.prices[i];
- clas = p.clas;
- itHas = p.itHas;
- zichara = p.zichara;
- }
- return *this;
- }
- PlaninarskiDom& operator--() {
- if(clas != 'F') {
- ++clas;
- }
- return *this;
- }
- friend ostream& operator<< (ostream &out, PlaninarskiDom &p) {
- out << p.name << " klasa:" << p.clas;
- if(p.itHas)
- out << " so Zichara" << endl;
- else
- out << endl;
- return out;
- }
- bool operator <= (char znak) {
- return clas > znak;
- }
- void setZichara (Zichara z) {
- zichara = z;
- itHas = true;
- }
- void presmetajDnevenPrestoj(int den, int mesec, int &cena) {
- if(den < 1 || den > 31 || mesec < 1 || mesec > 12) {
- throw 5;
- }
- if (itHas)
- cena += zichara.getPrice();
- if ((den >= 1&&mesec >= 4&&mesec < 9) || (mesec == 9&&den == 1)) {
- cena += prices[0];
- }
- else {
- cena += prices[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!";
- }
- }
- 7. Фактура
- #include <stdio.h>
- #include <string.h>
- typedef struct Proizvod
- {
- char productCode[20];
- int price;
- int productsInStore;
- } Proizvod;
- typedef struct Narachka
- {
- char name[15];
- Proizvod p[10];
- int productsOrdered[10];
- int noProductsOrdered;
- } Narachka;
- void pecatiFaktura(Narachka n)
- {
- printf("Faktura za %s\n", n.name);
- int i, j, total=0, flag, temp[10];
- Proizvod tmp[20];
- for(i=0; i<n.noProductsOrdered-1; i++)
- {
- for(j=i+1; j<n.noProductsOrdered; j++)
- {
- if(strcmp(n.p[i].productCode, n.p[j].productCode)>0)
- {
- tmp[i]=n.p[j];
- n.p[j]=n.p[i];
- n.p[i]=tmp[i];
- }
- }
- }
- for(i=0; i<n.noProductsOrdered; i++)
- {
- if(n.p[i].productsInStore>n.productsOrdered[i])
- {
- n.p[i].productsInStore=n.productsOrdered[i];
- }
- else
- {
- flag=0;
- break;
- }
- }
- if(flag)
- {
- for(i=0; i<n.noProductsOrdered; i++)
- {
- printf("%s %d %d %d\n", n.p[i].productCode, n.p[i].price, n.p[i].productsInStore, n.p[i].price*n.p[i].productsInStore);
- total+=n.p[i].price*n.p[i].productsInStore;
- }
- printf("Vkupnata suma na fakturata e %d\n", total);
- }
- else
- {
- printf("Fakturata ne moze da se izgotvi\n");
- }
- }
- int main() {
- Narachka narachka;
- scanf("%s", &narachka.name);
- scanf("%d", &narachka.noProductsOrdered);
- int i;
- for (i=0; i<narachka.noProductsOrdered; ++i)
- {
- scanf("%s", &narachka.p[i].productCode);
- scanf("%d", &narachka.p[i].price);
- scanf("%d", &narachka.p[i].productsInStore);
- }
- int j;
- for (j=0; j<narachka.noProductsOrdered; ++j)
- {
- scanf("%d", &narachka.productsOrdered[j]);
- }
- pecatiFaktura(narachka);
- return 0;
- }
- 8. Воз
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Patnik
- {
- private:
- char name[100];
- int classType;
- bool bicycle;
- public:
- Patnik() {}
- Patnik(const char *name, const int classType, const bool bicycle)
- {
- strcpy(this->name, name);
- this->classType=classType;
- this->bicycle=bicycle;
- }
- Patnik(const Patnik &r)
- {
- strcpy(name, r.name);
- classType=r.classType;
- bicycle=r.bicycle;
- }
- Patnik &operator=(const Patnik &r)
- {
- if(this!=&r)
- {
- strcpy(name, r.name);
- classType=r.classType;
- bicycle=r.bicycle;
- }
- return *this;
- }
- ~Patnik() {}
- friend ostream &operator<<(ostream &out, const Patnik &o)
- {
- out<<o.name<<endl;
- out<<o.classType<<endl;
- out<<o.bicycle<<endl;
- return out;
- }
- const int getClass() { return classType; }
- const bool getBike() const { return bicycle; }
- };
- class Voz
- {
- private:
- char destination[100];
- Patnik *p;
- int noPassengers, bicAllowed;
- public:
- Voz(const char *destination, const int bicAllowed)
- {
- strcpy(this->destination, destination);
- this->bicAllowed=bicAllowed;
- noPassengers=0;
- p=NULL;
- }
- ~Voz() { delete [] p; }
- Voz &operator+=(const Patnik &n)
- {
- Patnik *tmp=new Patnik[noPassengers+1];
- for(int i=0; i<noPassengers; i++)
- {
- tmp[i]=p[i];
- }
- if(bicAllowed!=0&&n.getBike()==1)
- {
- tmp[noPassengers]=n;
- noPassengers++;
- }
- else if(n.getBike()==0)
- {
- tmp[noPassengers]=n;
- noPassengers++;
- }
- delete [] p;
- p=tmp;
- return *this;
- }
- friend ostream &operator<<(ostream &out, const Voz &o)
- {
- out<<o.destination<<endl;
- for(int i=0; i<o.noPassengers; i++)
- {
- out<<o.p[i]<<endl;
- }
- return out;
- }
- void patniciNemaMesto()
- {
- int count1=0, count2=0;
- for(int i=0; i<noPassengers; i++)
- {
- if(p[i].getClass()==1)
- {
- if(p[i].getBike())
- {
- count1++;
- }
- }
- else
- {
- if(p[i].getBike())
- {
- count2++;
- }
- }
- }
- if(count1+count2<=bicAllowed)
- {
- count1=count2=0;
- }
- else if(count1>bicAllowed)
- {
- count1-=bicAllowed;
- }
- else if(count1<bicAllowed)
- {
- count1=bicAllowed-count1;
- count2-=count1;
- count1=0;
- }
- cout<<"Brojot na patnici od 1-va klasa koi ostanale bez mesto e: "<<count1<<endl;
- cout<<"Brojot na patnici od 2-ra klasa koi ostanale bez mesto e: "<<count2<<endl;
- }
- };
- 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;
- }
- 9. Кабелски телевизии
- #include <iostream>
- #include <cstring>
- using namespace std;
- class TV
- {
- private:
- char name[100];
- bool type;
- int category;
- float rating;
- public:
- TV(const char *name="", const bool type=0, const int category=0, const float rating=0)
- {
- strcpy(this->name, name);
- this->type=type;
- this->category=category;
- this->rating=rating;
- }
- TV(const TV &r)
- {
- strcpy(name, r.name);
- type=r.type;
- category=r.category;
- rating=r.rating;
- }
- TV &operator=(const TV &r)
- {
- if(this!=&r)
- {
- strcpy(name, r.name);
- type=r.type;
- category=r.category;
- rating=r.rating;
- }
- return *this;
- }
- ~TV() {}
- friend ostream &operator<<(ostream &out, const TV &o)
- {
- out<<o.name<<endl;
- if(o.type)
- {
- out<<"D"<<endl;
- }
- else
- {
- out<<"A"<<endl;
- }
- out<<o.category<<endl;
- out<<o.rating<<endl;
- return out;
- }
- bool operator==(const TV &r)
- {
- return (strcmp(name, r.name)==0&&type==r.type);
- }
- TV &operator++()
- {
- rating+=0.5;
- return *this;
- }
- float getRating() const { return rating; }
- };
- class KabelskiOperator
- {
- private:
- char name[100];
- TV *p;
- int noChannels;
- public:
- KabelskiOperator(const char *name)
- {
- strcpy(this->name, name);
- p=NULL;
- noChannels=0;
- }
- ~KabelskiOperator() { delete [] p; }
- KabelskiOperator &operator+=(const TV &n)
- {
- if(n.getRating()>5)
- {
- TV *tmp=new TV[noChannels+1];
- for(int i=0; i<noChannels; i++)
- {
- tmp[i]=p[i];
- }
- tmp[noChannels]=n;
- delete [] p;
- p=tmp;
- noChannels++;
- }
- return *this;
- }
- friend ostream &operator<<(ostream &out, const KabelskiOperator &o)
- {
- out<<o.name<<endl;
- for(int i=0; i<o.noChannels; i++)
- {
- out<<o.p[i]<<endl;
- }
- return out;
- }
- void zgolemi(const TV &tv)
- {
- for(int i=0; i<noChannels; i++)
- {
- if(p[i]==tv)
- {
- ++p[i];
- break;
- }
- }
- }
- };
- int main() {
- int n, x;
- cin >> n >> x;
- char name[100];
- cin >> name;
- KabelskiOperator ko(name);
- TV t;
- for(int i = 0; i < n; ++i) {
- char name[100];
- bool digital;
- int category;
- float rating;
- cin >> name >> digital >> category >> rating;
- TV tv(name, digital, category, rating);
- ko += tv;
- if(i == x) {
- t = tv;
- }
- }
- cout << ko;
- cout << "=== ZGOLEMI ===" << endl;
- cout << t;
- ko.zgolemi(t);
- cout << ko;
- return 0;
- }
- 10. Работни часови
- #include <stdio.h>
- #include <string.h>
- #define NEDELI 4
- #define DENOVI 5
- typedef struct RabotnaNedela
- {
- int casovi[DENOVI];
- int weekNo;
- }RN;
- typedef struct Rabotnik
- {
- char ime[50];
- RN nedeli[NEDELI];
- }R;
- int maxNedela(R *s)
- {
- int i, j, max=0, index, hoursWorked=0;
- for(i=0; i<NEDELI; i++)
- {
- for(j=0; j<DENOVI; j++)
- {
- hoursWorked+=s->nedeli[i].casovi[j];
- }
- if(hoursWorked>max)
- {
- max=hoursWorked;
- index=i;
- }
- hoursWorked=0;
- }
- return index+1;
- }
- void table(R *s, int n)
- {
- int i, j, k;
- printf("Rab\t%d\t%d\t%d\t%d\tVkupno\n", 1, 2, 3, 4);
- for(i=0; i<n; i++)
- {
- int addDays[NEDELI]={0};
- for(j=0; j<NEDELI; j++)
- {
- for(k=0; k<DENOVI; k++)
- {
- addDays[j]+=s[i].nedeli[j].casovi[k];
- }
- }
- int total=addDays[0]+addDays[1]+addDays[2]+addDays[3];
- printf("%s\t%d\t%d\t%d\t%d\t%d\n", s[i].ime, addDays[0], addDays[1], addDays[2], addDays[3], total);
- }
- }
- 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;
- }
- 11. Танчери
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct Tanc{
- char ime[15], zemja[15];
- };
- struct Tancer{
- char ime[20], prezime[20];
- Tanc niza[5];
- };
- void tancuvanje(Tancer *t, int n, char *zemja)
- {
- int i, j, indexI, indexJ;
- int count[n];
- for(i=0;i<n;i++)
- {
- count[i]=0;
- for(j=0; j<3; j++)
- {
- if(strcmp(zemja, t[i].niza[j].zemja)==0)
- count[i]++;
- }
- }
- for(i=0; i<n; i++)
- {
- for(j=0; j<3; j++)
- {
- if(count[i]==1)
- {
- if(strcmp(zemja, t[i].niza[j].zemja)==0)
- {
- cout<<t[i].ime<<" "<<t[i].prezime<<", "<<t[i].niza[j].ime<<endl;
- indexI=i;
- indexJ=j;
- }
- }
- if(count[i]==2)
- {
- if(strcmp(zemja, t[i].niza[j].zemja)==0)
- if(strcmp(t[i].niza[j].ime, t[indexI].niza[indexJ].ime)==0)
- cout<<t[i].ime<<" "<<t[i].prezime<<", "<<t[i].niza[j].ime<<endl;
- }
- }
- }
- }
- int main()
- {
- int n,i,j;
- Tancer t[10];
- cin>>n;
- for(i=0;i<n;i++){
- cin>>t[i].ime;
- cin>>t[i].prezime;
- for(j=0;j<3;j++){
- cin>>t[i].niza[j].ime;
- cin>>t[i].niza[j].zemja;
- }
- }
- char zemja[15];
- cin>>zemja;
- tancuvanje(t,n,zemja);
- return 0;
- }
- 13. Работни часови (40 поени)
- #include <stdio.h>
- #include <string.h>
- #define NEDELI 4
- #define DENOVI 5
- typedef struct RabotnaNedela
- {
- int casovi[DENOVI];
- int weekNo;
- }RN;
- typedef struct Rabotnik
- {
- char ime[50];
- RN nedeli[NEDELI];
- }R;
- int maxNedela(R *s)
- {
- int i, j, max=0, index, hoursWorked=0;
- for(i=0; i<NEDELI; i++)
- {
- for(j=0; j<DENOVI; j++)
- {
- hoursWorked+=s->nedeli[i].casovi[j];
- }
- if(hoursWorked>max)
- {
- max=hoursWorked;
- index=i;
- }
- hoursWorked=0;
- }
- return index+1;
- }
- void table(R *s, int n)
- {
- int i, j, k;
- printf("Rab\t%d\t%d\t%d\t%d\tVkupno\n", 1, 2, 3, 4);
- for(i=0; i<n; i++)
- {
- int addDays[NEDELI]={0};
- for(j=0; j<NEDELI; j++)
- {
- for(k=0; k<DENOVI; k++)
- {
- addDays[j]+=s[i].nedeli[j].casovi[k];
- }
- }
- int total=addDays[0]+addDays[1]+addDays[2]+addDays[3];
- printf("%s\t%d\t%d\t%d\t%d\t%d\n", s[i].ime, addDays[0], addDays[1], addDays[2], addDays[3], total);
- }
- }
- 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;
- }
- 14. Структура во C
- #include<stdio.h>
- typedef struct Pacient{
- char ime[100];
- int zdravstveno,pregledi;
- }Pacient;
- typedef struct MaticenDoktor{
- char ime[100];
- int br_pac,brpregledi;
- Pacient niza[200];
- float cena,zarabotka;
- }doktor;
- void najuspesen_doktor(doktor a[],int n){
- int i,j;
- for(i=0;i<n;i++){
- for(j=0;j<a[i].br_pac;j++){
- if(a[i].niza[j].zdravstveno==0){
- a[i].zarabotka+=a[i].cena*a[i].niza[j].pregledi;
- }
- a[i].brpregledi+=a[i].niza[j].pregledi;
- }
- }
- doktor najdobar=a[0];
- for(i=0;i<n;i++){
- if(a[i].zarabotka==najdobar.zarabotka){
- if(a[i].brpregledi>najdobar.brpregledi)
- najdobar=a[i];
- }
- }
- printf("%s %.2f %d",najdobar.ime,najdobar.zarabotka,najdobar.brpregledi);
- }
- 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);
- md[i].zarabotka=0,md[i].brpregledi=0;
- for (j = 0; j < md[i].br_pac; j++){
- scanf("%s", md[i].niza[j].ime);
- scanf("%d", &md[i].niza[j].zdravstveno);
- scanf("%d", &md[i].niza[j].pregledi);
- }
- }
- najuspesen_doktor(md, n);
- return 0;
- }
- 15. Акции
- #include<iostream>
- #include<cstring>
- using namespace std;
- // vasiot kod za klasite ovde
- class StockRecord{
- private:
- char ID[12];
- char kompanija[50];
- float cena_spored_koja;
- float momentalna_cena;
- int br_akcii;
- public:
- StockRecord(char *ID="", char *kompanija="", float cena_spored_koja=0.0, int br_akcii=0){
- strcpy(this->ID, ID);
- strcpy(this->kompanija, kompanija);
- this->cena_spored_koja=cena_spored_koja;
- this->br_akcii=br_akcii;
- this->momentalna_cena=0;
- }
- void setNewPrice(double c){
- this->momentalna_cena=c;
- }
- double value(){
- double res=0.0;
- res=br_akcii*momentalna_cena;
- return res;
- }
- double profit(){
- double res=0.0;
- res=br_akcii*(momentalna_cena-cena_spored_koja);
- return res;
- }
- friend ostream& operator<<(ostream& out, StockRecord &sr){
- return out<<sr.kompanija<<" "<<sr.br_akcii<<" "<<sr.cena_spored_koja<<" "<<sr.momentalna_cena<<" "<<sr.profit()<<endl;
- }
- };
- class Client{
- private:
- char clientName[60];
- int clientID;
- StockRecord *kompanii;
- int n;
- public:
- Client (char *clientName="", int clientID=0){
- strcpy(this->clientName, clientName);
- this->clientID=clientID;
- this->kompanii=new StockRecord[50];
- this->n=0;
- }
- double totalValue(){
- double sum=0.0;
- for(int i=0;i<n;++i){
- sum+=kompanii[i].value();
- }
- return sum;
- }
- Client& operator+= (StockRecord &sr){
- kompanii[n]=sr;
- ++n;
- return *this;
- }
- friend ostream& operator<< (ostream& out, Client &c){
- out<<c.clientID<<" "<<c.totalValue()<<endl;
- for(int i=0;i<c.n;++i){
- out<<c.kompanii[i];
- }
- return out;
- }
- };
- // 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