Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Компјутерска игра
- #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 *lista, int n){
- int IndexNajmnoguIgraci=0, IndexMax=0, IndexNivo=0;
- for(int i=1;i<n;i++){
- if(lista[i].n>lista[IndexNajmnoguIgraci].n){
- IndexNajmnoguIgraci=i;
- }
- }
- KompjuterskaIgra najpopularna=lista[IndexNajmnoguIgraci];
- for(int i=1;i<najpopularna.n;i++){
- if(najpopularna.lista[i].poeni>najpopularna.lista[IndexMax].poeni){
- IndexMax=i;
- }
- else if(najpopularna.lista[i].poeni==najpopularna.lista[IndexMax].poeni){
- if(najpopularna.lista[i].nivo>najpopularna.lista[IndexMax].poeni){
- IndexMax=i;
- }
- }
- }
- cout<<"Najdobar igrac e igracot so korisnicko ime ";
- cout<<najpopularna.lista[IndexMax].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. Скијачки центар
- #include<stdio.h>
- #include<string.h>
- typedef struct SkiLift{
- char ime[15];
- int max;
- int voUpotreba;
- }SkiLift;
- typedef struct SkiCenter{
- char ime[20];
- char drzava[20];
- SkiLift lift[20];
- int n;
- }SkiCenter;
- void najgolemKapacitet(SkiCenter *sc, int n){
- int vkupno=0,max=0,IndexI;
- for(int i=0;i<n;i++){
- for(int j=0;j<sc[i].n;j++){
- if(sc[i].lift[j].voUpotreba==1){
- vkupno+=sc[i].lift[j].max;
- if(vkupno>=max){
- max=vkupno;
- IndexI=i;
- }
- }
- }
- vkupno=0;
- }
- printf("%s\n%s\n%d",sc[IndexI].ime,sc[IndexI].drzava,max);
- }
- int main()
- {
- int n,i,j,broj;
- SkiCenter sc[20];
- scanf("%d", &n);
- for (i = 0; i < n; i++){
- //vnesi ime
- scanf("%s",sc[i].ime);
- //vnesi drzava
- scanf("%s",sc[i].drzava);
- //vnesi broj na liftovi
- scanf("%d",&sc[i].n);
- //za sekoj ski lift vnesi:
- for(j=0;j<sc[i].n;j++){
- //vnesi ime
- scanf("%s",sc[i].lift[j].ime);
- //vnesi maksimalen broj korisnici
- scanf("%d",&sc[i].lift[j].max);
- //vnesi dali e pusten vo funkcija
- scanf("%d",&sc[i].lift[j].voUpotreba);
- }
- }
- //povik na funkcijata najgolemKapacitet
- 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 kojtip;
- public:
- Pesna() {ime = new char[0];}
- Pesna(char* ime, int vremetraenje, tip kojtip){
- this->ime = new char[strlen(ime)+1];
- strcpy(this->ime,ime);
- this->vremetraenje=vremetraenje;
- this->kojtip=kojtip;
- }
- Pesna(const Pesna &p){
- this->ime = new char[strlen(p.ime)+1];
- strcpy(this->ime,p.ime);
- this->vremetraenje=p.vremetraenje;
- this->kojtip=p.kojtip;
- }
- Pesna &operator=(const 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->kojtip=p.kojtip;
- }
- return *this;
- }
- ~Pesna(){
- delete [] ime;
- }
- void pecati(){
- cout<<"\""<<ime<<"\"-"<<vremetraenje<<"min"<<endl;
- }
- void setIme(char *ime){
- strcpy(this->ime,ime);
- }
- void setVremetraenje(int vremetraenje){
- this->vremetraenje=vremetraenje;
- }
- void setTip(tip kojtip){
- this->kojtip=kojtip;
- }
- char *getIme(){
- return ime;
- }
- int getVremetraenje(){
- return vremetraenje;
- }
- tip getTip(){
- return kojtip;
- }
- };
- class CD{
- private:
- Pesna pesni[10];
- int n;
- int maxVremetraenje;
- public:
- CD(Pesna *pesni=0, int n=0, int maxVremetraenje=0){
- for(int i=0;i<n;i++)
- this->pesni[i] = pesni[i];
- this->n=n;
- this->maxVremetraenje=maxVremetraenje;
- }
- CD(int maxVremetraenje){
- this->n=0;
- this->maxVremetraenje=maxVremetraenje;
- }
- CD(const CD &c){
- this->n=c.n;
- for(int i=0;i<n;i++)
- this->pesni[i] = c.pesni[i];
- this->maxVremetraenje=c.maxVremetraenje;
- }
- CD &operator=(const CD &c){
- if(this!=&c){
- this->n=c.n;
- for(int i=0;i<n;i++)
- this->pesni[i] = c.pesni[i];
- this->maxVremetraenje=c.maxVremetraenje;
- }
- return *this;
- }
- ~CD(){}
- Pesna getPesna(int i){
- return pesni[i];
- }
- int getBroj(){
- return n;
- }
- CD& dodadiPesna(Pesna p){
- int vkupnovreme=0;
- for(int i=0;i<n;i++){
- vkupnovreme+=pesni[i].getVremetraenje();
- }
- if(n<10&&maxVremetraenje>=(vkupnovreme+p.getVremetraenje())){
- pesni[n++]=p;
- }
- return *this;
- }
- 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;
- }
- 4. Железничка станица
- #include<iostream>
- #include <cstring>
- using namespace std;
- struct Voz{
- char relacija[50];
- float km;
- int patnici;
- };
- struct ZeleznickaStanica{
- char grad[20];
- Voz voz[30];
- int n;
- };
- int isSubString(char *l, char *r)
- {
- int lenL=strlen(l), lenR=strlen(r), count=0;
- for(int i=0; i<lenR; i++)
- {
- if(l[i]==r[i])
- {
- count++;
- }
- else
- {
- break;
- }
- }
- return count==lenR;
- }
- void najkratkaRelacija(ZeleznickaStanica* z, int n, char* grad){
- int IndexI, IndexJ, min=99999;
- for(int i=0;i<n;i++){
- for(int j=0;j<z[i].n;j++){
- if(isSubString(z[i].voz[j].relacija, grad)){
- if(z[i].voz[j].km<=min){
- min=z[i].voz[j].km;
- IndexI=i;
- IndexJ=j;
- }
- }
- }
- }
- cout<<"Najkratka relacija: "<<z[IndexI].voz[IndexJ].relacija<<" ("<<min<<" 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].n;
- for(int j=0;j<zStanica[i].n;j++){
- cin>>zStanica[i].voz[j].relacija;
- cin>>zStanica[i].voz[j].km;
- cin>>zStanica[i].voz[j].patnici;
- }
- }
- char grad[25];
- cin>>grad;
- najkratkaRelacija(zStanica,n,grad);
- return 0;
- }
- 5. Пицерија
- #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) {
- if(strcmp(sostojki, p.sostojki)==0) {
- return true;
- } else
- return false;
- }
- int getNamaluvanje() {
- return namaluvanje;
- }
- int getCena() {
- return cena;
- }
- };
- class Picerija {
- private:
- char ime[15];
- Pica* pici;
- int n;
- public:
- Picerija(const char *ime = "") {
- strncpy(this->ime,ime,14);
- this->ime[14]=0;
- pici=NULL;
- n = 0;
- }
- Picerija(const char *ime,Pica* pici, int n) {
- strncpy(this->ime,ime,14);
- this->ime[14]=0;
- this->n=n;
- this->pici = new Pica[n];
- for(int i=0; i<n; i++)
- this->pici[i]=pici[i];
- }
- Picerija(const Picerija &p) {
- strcpy(ime,p.ime);
- n=p.n;
- pici = new Pica[n];
- for(int i=0; i<n; i++)
- pici[i]=p.pici[i];
- }
- Picerija& operator= (const Picerija &p) {
- if(this!=&p) {
- strcpy(ime,p.ime);
- n=p.n;
- delete [] pici;
- pici = new Pica[n];
- for(int i=0; i<n; i++)
- pici[i]=p.pici[i];
- }
- return *this;
- }
- ~Picerija() {
- delete [] pici;
- }
- Picerija& operator+=(Pica &p) {
- int isti=0;
- for(int i=0; i<n; i++) {
- if(pici[i].istiSe(p)==true) {
- isti=1;
- }
- }
- if(!isti) {
- Pica *tmp = new Pica[n+1];
- for(int i=0; i<n; i++)
- tmp[i]=pici[i];
- tmp[n++]=p;
- delete [] pici;
- pici = tmp;
- }
- return *this;
- }
- void piciNaPromocija() {
- for(int i=0; i<n; i++) {
- if(pici[i].getNamaluvanje()!=0) {
- pici[i].pecati();
- cout<<(float)pici[i].getCena()-(((float)pici[i].getCena()/100)*pici[i].getNamaluvanje())<<endl;
- }
- }
- }
- void setIme(const char *ime) {
- strncpy(this->ime,ime,14);
- this->ime[14] = 0;
- }
- const char *getIme() {
- return ime;
- }
- };
- 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;
- }
- 6. Маратон
- // vashiot kod ovde
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Ucesnik{
- private:
- char *ime;
- bool pol;
- int vozrast;
- public:
- Ucesnik(const 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(const Ucesnik &p){
- this->ime=new char[strlen(p.ime)+1];
- strcpy(this->ime,p.ime);
- this->pol=p.pol;
- this->vozrast=p.vozrast;
- }
- Ucesnik &operator=(Ucesnik &p){
- if(this!=&p){
- delete [] ime;
- this->ime=new char[strlen(p.ime)+1];
- strcpy(this->ime,p.ime);
- this->pol=p.pol;
- this->vozrast=p.vozrast;
- }
- return *this;
- }
- ~Ucesnik(){
- delete [] ime;
- }
- bool operator>(Ucesnik &p){
- return this->vozrast>p.vozrast;
- }
- friend ostream &operator<<(ostream &out, Ucesnik &p){
- out<<p.ime<<endl;
- if(p.pol==0)
- out<<"zhenski"<<endl;
- else
- out<<"mashki"<<endl;
- out<<p.vozrast<<endl;
- return out;
- }
- int getVozrast(){
- return vozrast;
- }
- };
- class Maraton{
- private:
- char lokacija[100];
- Ucesnik *ucesnici;
- int n;
- public:
- Maraton(char *lokacija){
- strncpy(this->lokacija,lokacija,strlen(lokacija)+1);
- ucesnici=new Ucesnik[0];
- n=0;
- }
- ~Maraton(){
- delete [] ucesnici;
- }
- Maraton &operator+=(Ucesnik &p){
- Ucesnik *tmp = new Ucesnik[n+1];
- for(int i=0; i<this->n; i++)
- tmp[i]=this->ucesnici[i];
- delete [] ucesnici;
- ucesnici=new Ucesnik[n+1];
- for(int i=0; i<this->n; i++)
- this->ucesnici[i]=tmp[i];
- this->ucesnici[n]=p;
- delete [] tmp;
- n++;
- return *this;
- }
- float prosecnoVozrast(){
- float vkupno=0.0;
- for(int i=0;i<n;i++){
- vkupno+=ucesnici[i].getVozrast();
- }
- return vkupno/n;
- }
- void pecatiPomladi(Ucesnik &u){
- for(int i=0;i<n;i++){
- if(u.getVozrast()>this->ucesnici[i].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;
- }
- 7. Сладолед
- #include <iostream>
- #include <cstring>
- using namespace std;
- // vashiot kod ovde
- class IceCream{
- private:
- char *ime;
- char sostav[100];
- float cena;
- int popust;
- public:
- IceCream(){
- ime = new char[15];
- popust=0;
- }
- IceCream(const char *ime,const char *sostav,float cena){
- this->ime=new char[strlen(ime)+1];
- strcpy(this->ime,ime);
- strcpy(this->sostav,sostav);
- this->cena=cena;
- popust=0;
- }
- IceCream(const IceCream &ic){
- this->ime=new char[strlen(ic.ime)+1];
- strcpy(this->ime,ic.ime);
- strcpy(this->sostav,ic.sostav);
- this->cena=ic.cena;
- popust=ic.popust;
- }
- IceCream &operator=(const IceCream &ic){
- if(this!=&ic){
- this->ime=new char[strlen(ic.ime)+1];
- strcpy(this->ime,ic.ime);
- strcpy(this->sostav,ic.sostav);
- this->cena=ic.cena;
- popust=ic.popust;
- }
- return *this;
- }
- ~IceCream(){
- delete [] ime;
- }
- friend ostream &operator<<(ostream &out, const IceCream &ic){
- out<<ic.ime<<": ";
- out<<ic.sostav<<" ";
- out<<ic.cena<<" ";
- if(ic.popust>0)
- out<<"("<<ic.cena-((ic.cena/100)*ic.popust)<<")";
- return out;
- }
- IceCream &operator++(){
- popust+=5;
- return *this;
- }
- IceCream &operator+(char *niza){
- char *temp;
- temp = new char[strlen(ime)+1];
- strcpy(temp,ime);
- delete [] ime;
- ime = new char[strlen(temp)+strlen(niza)+4];
- strcpy(ime,temp);
- strcat(ime," + ");
- strcat(ime,niza);
- cena+=10;
- delete [] temp;
- return *this;
- }
- void setDiscount(int dis){
- if(dis>=0&&dis<=100)
- popust=dis;
- }
- void setName(char* name){
- ime=new char[strlen(name)+1];
- strcpy(ime,name);
- }
- };
- class IceCreamShop{
- private:
- char ime[50];
- IceCream *shop;
- int n;
- public:
- IceCreamShop(){
- n=0;
- shop = new IceCream[n];
- }
- IceCreamShop(const char *ime){
- n=0;
- strcpy(this->ime,ime);
- shop = new IceCream[n];
- }
- IceCreamShop(const IceCreamShop &ics){
- strcpy(this->ime,ics.ime);
- this->shop = new IceCream[ics.n];
- for(int i=0;i<ics.n;i++){
- this->shop[i]=ics.shop[i];
- }
- this->n=ics.n;
- }
- ~IceCreamShop(){
- delete [] shop;
- }
- IceCreamShop &operator+=(const IceCream &ic){
- IceCream *temp;
- temp = new IceCream[n];
- for(int i=0;i<n;i++){
- temp[i]=shop[i];
- }
- delete [] shop;
- shop = new IceCream[n+1];
- for(int i=0;i<n;i++){
- shop[i]=temp[i];
- }
- shop[n]=ic;
- delete [] temp;
- n++;
- return *this;
- }
- friend ostream &operator<<(ostream &out, const IceCreamShop &ics){
- out<<ics.ime<<endl;
- for(int i=0;i<ics.n;i++){
- out<<ics.shop[i]<<endl;
- }
- return out;
- }
- };
- // 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;
- }
- 8. Планинарски дом
- #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!";
- }
- }
- 9. Податочен систем
- #include<iostream>
- #include<cstring>
- using namespace std;
- enum Extension{txt,pdf,exe};
- class File{
- char *ime;
- Extension eks;
- char *sopstvenik;
- int gol;
- public:
- File(){}
- File(char *i,char*s,int g,Extension e){
- ime=new char[strlen(i)+1];
- strcpy(ime,i);
- sopstvenik=new char[strlen(s)+1];
- strcpy(sopstvenik,s);
- gol=g;
- eks=e;
- }
- File(const File &f){
- ime=new char[strlen(f.ime)+1];
- strcpy(ime,f.ime);
- sopstvenik=new char[strlen(f.sopstvenik)+1];
- strcpy(sopstvenik,f.sopstvenik);
- gol=f.gol;
- eks=f.eks;
- }
- File &operator=(const File &f){
- ime=new char[strlen(f.ime)+1];
- strcpy(ime,f.ime);
- sopstvenik=new char[strlen(f.sopstvenik)+1];
- strcpy(sopstvenik,f.sopstvenik);
- gol=f.gol;
- eks=f.eks;
- return *this;
- }
- ~File(){delete[]ime; delete[]sopstvenik;}
- void print(){
- cout<<"File name: "<<ime;
- if(eks==0) cout<<".pdf"<<endl;
- else if(eks==1) cout<<".txt"<<endl;
- else cout<<".exe"<<endl;
- cout<<"File owner: "<<sopstvenik<<endl;
- cout<<"File size: "<<gol<<endl;
- }
- bool equals(const File & that){
- return strcmp(ime,that.ime)==0&&strcmp(sopstvenik,that.sopstvenik)==0&&eks==that.eks;
- }
- bool equalsType(const File & that){
- return strcmp(ime,that.ime)==0&&eks==that.eks;
- }
- };
- class Folder{
- char * ime;
- File * niza;
- int n;
- public:
- Folder(){}
- Folder(const char* name){
- ime=new char[strlen(name)+1];
- strcpy(ime,name);
- n=0;
- niza=NULL;
- }
- Folder(const Folder &f){
- ime=new char[strlen(f.ime)+1];
- strcpy(ime,f.ime);
- niza=new File[f.n];
- for(int i=0;i<f.n;i++){
- niza[i]=f.niza[i];
- }
- n=f.n;
- }
- Folder &operator=(const Folder &f){
- ime=new char[strlen(f.ime)+1];
- strcpy(ime,f.ime);
- niza=new File[f.n];
- for(int i=0;i<f.n;i++){
- niza[i]=f.niza[i];
- }
- n=f.n;
- return *this;
- }
- ~Folder(){delete[]niza; delete[]ime;}
- void print(){
- cout<<"Folder name: "<<ime<<endl;
- for(int i=0;i<n;i++){
- niza[i].print();
- }
- }
- void remove(const File & file){
- int zname=0,prv;
- for(int i=0;i<n;i++){
- if(niza[i].equals(file)){
- zname=1; prv=i;
- }
- }
- if(zname){
- File *temp=niza;
- niza=new File[n-1];
- int j=0;
- for(int i=0;i<n;i++){
- if(i!=prv){
- niza[j]=temp[i];
- j++;}}
- delete []temp;
- n=j;
- }
- }
- void add(const File & file){
- File *temp=niza;
- niza=new File[n+1];
- for(int i=0;i<n;i++){
- niza[i]=temp[i];
- }
- niza[n++]=file;
- delete[]temp;
- }
- };
- 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, (Extension) 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, (Extension) ext);
- first.print();
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File second(fileName, fileOwner, fileSize, (Extension) ext);
- second.print();
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File third(fileName, fileOwner, fileSize, (Extension) 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, (Extension) 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, (Extension) ext);
- folder.add(file);
- iter--;
- }
- cin >> fileName;
- cin >> fileOwner;
- cin >> fileSize;
- cin >> ext;
- File file(fileName, fileOwner, fileSize, (Extension) ext);
- folder.remove(file);
- folder.print();
- }
- return 0;
- }
- 10. Фактура
- #include <stdio.h>
- #include <string.h>
- //место за вашиот код
- typedef struct Proizvod{
- char kod[20];
- int cena;
- int n;
- } Proizvod;
- typedef struct Narachka{
- char ime[15];
- Proizvod p[10];
- int broj[10];
- int brojnarachani;
- } Narachka;
- void pecatiFaktura(Narachka n){
- printf("Faktura za %s\n",n.ime);
- Proizvod tmp[20];
- for(int i=0;i<n.brojnarachani;i++){
- if(n.brojnarachani>n.p[i].n){
- printf("Fakturata ne moze da se izgotvi");
- return;
- }
- }
- for(int i=0;i<n.brojnarachani-1;i++){
- for(int j=i+1;j<n.brojnarachani;j++){
- if(strcmp(n.p[i].kod,n.p[j].kod)>0){
- tmp[i]=n.p[j];
- n.p[j]=n.p[i];
- n.p[i]=tmp[i];
- }
- }
- }
- int vkupno=0;
- for(int i=0;i<n.brojnarachani;i++){
- if(n.p[i].n>n.broj[i]){
- n.p[i].n=n.broj[i];
- printf("%s %d %d %d\n",n.p[i].kod,n.p[i].cena,n.p[i].n,n.p[i].cena*n.p[i].n);
- vkupno+=n.p[i].cena*n.p[i].n;
- }
- }
- printf("Vkupnata suma na fakturata e %d",vkupno);
- }
- int main() {
- Narachka narachka;
- // внеси го името лицето кое ја прави нарачката
- scanf("%s",narachka.ime);
- // внеси го бројот на порачани производи во нарачката
- scanf("%d",&narachka.brojnarachani);
- int i;
- //за секој од нарачаните производи се внесуваат информации
- for (i = 0; i < narachka.brojnarachani; ++i) {
- // внеси код
- scanf("%s",narachka.p[i].kod);
- // внеси единицчна цена
- scanf("%d",&narachka.p[i].cena);
- // внеси број на производи во магацин
- scanf("%d",&narachka.p[i].n);
- }
- //за секој производ се внесува колку такви производи се порачани во нарачката
- int j;
- for (j = 0; j < narachka.brojnarachani; ++j) {
- //се внесува број на производи во нарачката
- scanf("%d",&narachka.broj[j]);
- }
- // повик на функцијата pecatiFaktura
- pecatiFaktura(narachka);
- return 0;
- }
- 11. Воз
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Patnik {
- private:
- char ime[100];
- int klasa;
- bool velosiped;
- public:
- Patnik(const char *ime="", int klasa=0, bool velosiped=false) {
- strcpy(this->ime,ime);
- this->klasa=klasa;
- this->velosiped=velosiped;
- }
- Patnik(const Patnik &p) {
- strcpy(this->ime,p.ime);
- this->klasa=p.klasa;
- this->velosiped=p.velosiped;
- }
- Patnik &operator=(const Patnik &p) {
- if(this!=&p){
- strcpy(this->ime,p.ime);
- this->klasa=p.klasa;
- this->velosiped=p.velosiped;
- }
- return *this;
- }
- ~Patnik() {}
- void pecati() {
- cout<<ime<<endl<<klasa<<endl<<velosiped<<endl;
- cout<<endl;
- }
- int getKlasa(){
- return klasa;
- }
- bool getVelosiped(){
- return velosiped;
- }
- };
- class Voz {
- private:
- char destinacija[100];
- Patnik *patnici;
- int n;
- int maxvelosipedi;
- public:
- Voz(const char *destinacija="", int n=0, Patnik *patnici=0, int maxvelosipedi=0) {
- strcpy(this->destinacija,destinacija);
- this->maxvelosipedi=maxvelosipedi;
- this->n=n;
- this->patnici = new Patnik [this->n];
- for(int i=0; i<this->n; i++) {
- this->patnici[i]=patnici[i];
- }
- }
- Voz(char *destinacija, int maxvelosipedi) {
- strcpy(this->destinacija, destinacija);
- this->maxvelosipedi = maxvelosipedi;
- patnici = NULL;
- n = 0;
- }
- Voz(const Voz &v) {
- strcpy(this->destinacija,v.destinacija);
- this->maxvelosipedi=v.maxvelosipedi;
- this->n=v.n;
- this->patnici = new Patnik [this->n];
- for(int i=0; i<n; i++) {
- this->patnici[i]=v.patnici[i];
- }
- }
- Voz &operator=(const Voz &v) {
- if(this!=&v) {
- strcpy(this->destinacija,v.destinacija);
- this->maxvelosipedi=v.maxvelosipedi;
- this->n=v.n;
- delete [] patnici;
- for(int i=0; i<n; i++) {
- this->patnici[i]=v.patnici[i];
- }
- this->patnici = new Patnik [this->n];
- }
- return *this;
- }
- ~Voz() {
- delete [] patnici;
- }
- Voz dodadiPatnik(Patnik p) {
- if ((!p.getVelosiped()&&maxvelosipedi == 0) || maxvelosipedi != 0) {
- Patnik *tmp = new Patnik[n + 1];
- for (int i = 0; i < n; i++) {
- tmp[i] = patnici[i];
- }
- delete[]patnici;
- patnici = new Patnik[n + 1];
- for (int i = 0; i < n; i++) {
- patnici[i] = tmp[i];
- }
- patnici[n] = p;
- n++;
- }
- return *this;
- }
- void pecatiVoz(Voz v){
- cout<<v.destinacija<<endl;
- for(int i=0;i<v.n;i++)
- v.patnici[i].pecati();
- }
- void patniciNemaMesto(){
- int brPrva=0,brVtora=0;
- for(int i=0;i<n;i++){
- if(patnici[i].getKlasa()==1 && patnici[i].getVelosiped()==true){
- brPrva++;
- }
- if(patnici[i].getKlasa()==2 && patnici[i].getVelosiped()==true){
- brVtora++;
- }
- }
- if(brPrva>=maxvelosipedi){
- brPrva-=maxvelosipedi;
- }
- else{
- maxvelosipedi-=brPrva;
- brPrva=0;
- if(brVtora>=maxvelosipedi){
- brVtora-=maxvelosipedi;
- }
- else{
- brVtora=0;
- }
- }
- cout<<"Brojot na patnici od 1-va klasa koi ostanale bez mesto e: "<<brPrva<<endl;
- cout<<"Brojot na patnici od 2-ra klasa koi ostanale bez mesto e: "<<brVtora;
- }
- };
- 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.dodadiPatnik(p);
- }
- v.pecatiVoz(v);
- v.patniciNemaMesto();
- return 0;
- }
- 12. Работни часови
- #include <stdio.h>
- #include <string.h>
- #define NEDELI 4
- #define DENOVI 5
- // ovde strukturata RabotnaNedela
- typedef struct RabotnaNedela{
- int casovi[5];
- int nedela;
- }RN;
- // ovde strukturata Rabotnik
- typedef struct Rabotnik{
- char ime[50];
- RN nedeli[4];
- }R;
- // ovde funkciite
- int maxNedela(R *r){
- int vkupnocasovi=0,max=0,maxindex=0;
- for(int i=0;i<4;i++){
- for(int j=0;j<5;j++){
- vkupnocasovi+=r->nedeli[i].casovi[j];
- }
- if(vkupnocasovi>max){
- max=vkupnocasovi;
- maxindex=i;
- }
- vkupnocasovi=0;
- }
- return maxindex+1;
- }
- void table(R *r, int n){
- int vkupnonedela[4]={0},vkupno=0;
- printf("Rab\t1\t2\t3\t4\tVkupno\n");
- for(int i=0;i<n;i++){
- printf("%s\t",r[i].ime);
- for(int j=0;j<4;j++){
- for(int k=0;k<5;k++){
- vkupnonedela[j]+=r[i].nedeli[j].casovi[k];
- }
- }
- vkupno=vkupnonedela[0]+vkupnonedela[1]+vkupnonedela[2]+vkupnonedela[3];
- printf("%d\t%d\t%d\t%d\t%d\n",vkupnonedela[0],vkupnonedela[1],vkupnonedela[2],vkupnonedela[3],vkupno);
- vkupno=0;
- for(int m=0;m<4;m++)
- vkupnonedela[m]=0;
- }
- }
- 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;
- }
- 13. Танчери
- #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(zemja,t[i].niza[j].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;
- }
- 14. Структура во C
- #include<stdio.h>
- #include<string.h>
- typedef struct Pacient{
- char ime[100];
- int zdrastveno;
- int pregledi;
- }Pacient;
- typedef struct doktor{
- char ime[100];
- int br_pac;
- Pacient niza[200];
- float cena;
- }doktor;
- void najuspesen_doktor(doktor *md, int n){
- float vkupno[100]={0.0},maxvkupno=0;
- int maxvkupnop=0,maxindex,maxvkupnopregledi=0,vkupnopregledi[100]={0},vkupnop[100]={0};
- for(int i=0;i<n;i++){
- for(int j=0;j<md[i].br_pac;j++){
- vkupnop[i]+=md[i].niza[j].pregledi;
- if(md[i].niza[j].zdrastveno==0){
- ++vkupnopregledi[i];
- vkupnopregledi[i]*=md[i].niza[j].pregledi;
- vkupno[i]+=md[i].cena*vkupnopregledi[i];
- if(j==n-1){
- if(vkupno[i]>maxvkupno){
- maxvkupno=vkupno[i];
- maxindex=i;
- maxvkupnopregledi=vkupnopregledi[i];
- }
- }
- }
- }
- }
- for(int i=0;i<n;i++){
- if(vkupno[i]==maxvkupno){
- if(vkupnop[i]>vkupnop[maxindex])
- maxindex=i;
- }
- }
- printf("%s %.2f %d", md[maxindex].ime,maxvkupno,vkupnop[maxindex]);
- }
- 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;
- }
- 15. Акции
- #include<iostream>
- #include<cstring>
- using namespace std;
- // vasiot kod za klasite ovde
- class StockRecord{
- private:
- char ID[12];
- char ime[50];
- double cena;
- double momcena;
- int broj;
- public:
- StockRecord(char *ID="",char *ime="",double cena=0,int broj=0){
- strcpy(this->ID,ID);
- strcpy(this->ime,ime);
- this->cena=cena;
- this->broj=broj;
- this->momcena=0;
- }
- StockRecord(const StockRecord &sr){
- strcpy(this->ID,sr.ID);
- strcpy(this->ime,sr.ime);
- this->cena=sr.cena;
- this->broj=sr.broj;
- this->momcena=sr.momcena;
- }
- StockRecord &operator=(const StockRecord &sr){
- if(this!=&sr){
- strcpy(this->ID,sr.ID);
- strcpy(this->ime,sr.ime);
- this->cena=sr.cena;
- this->broj=sr.broj;
- this->momcena=sr.momcena;
- }
- return *this;
- }
- ~StockRecord(){}
- void setNewPrice(double c){
- this->momcena=c;
- }
- double value(){
- return broj*momcena;
- }
- double profit(){
- return broj*(momcena-cena);
- }
- void print(){
- cout<<ime<<" "<<broj<<" "<<cena<<" "<<momcena<<" "<<profit()<<endl;
- }
- };
- class Client{
- private:
- char ime[60];
- int ID;
- StockRecord *comp;
- int n;
- public:
- Client(char *ime="",int ID=0){
- strcpy(this->ime,ime);
- this->ID=ID;
- this->comp=NULL;
- this->n=0;
- }
- Client(const Client &c){
- strcpy(this->ime,c.ime);
- this->ID=c.ID;
- this->n=c.n;
- for(int i=0;i<n;i++)
- this->comp[i]=c.comp[i];
- }
- Client &operator=(const Client &c){
- if(this!=&c){
- strcpy(this->ime,c.ime);
- this->ID=c.ID;
- this->n=c.n;
- for(int i=0;i<n;i++)
- this->comp[i]=c.comp[i];
- }
- return *this;
- }
- ~Client(){
- delete [] comp;
- }
- double totalValue(){
- double vkupno=0;
- for(int i=0;i<n;i++){
- vkupno+=comp[i].value();
- }
- return vkupno;
- }
- void dodadi(StockRecord & sr){
- StockRecord *tmp = new StockRecord[n+1];
- for(int i=0;i<n;i++)
- tmp[i]=comp[i];
- tmp[n++]=sr;
- delete [] comp;
- comp=tmp;
- }
- void print(){
- cout<<ID<<" "<<totalValue()<<endl;
- for(int i=0;i<n;i++){
- comp[i].print();
- }
- }
- };
- // 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;
- sr.print();
- }
- }
- 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.dodadi(sr);
- if(flag){
- cout << "Operator += OK" << endl;
- flag = false;
- }
- }
- c.print();
- cout << "Operator << OK" << endl;
- }
- return 0;
- }
- 16. Забавен парк
- #include <stdio.h>
- #include <string.h>
- typedef struct Vozenje {
- char ime[100];
- int traenje;
- float cena;
- int daliPopust;
- } Vozenje;
- typedef struct ZabavenPark {
- char ime[100];
- char lokacija[100];
- Vozenje niza[100];
- int n;
- } ZabavenPark;
- void pecati(ZabavenPark *niza, int n) {
- for(int i=0; i<n; i++) {
- printf("%s %s\n",niza[i].ime,niza[i].lokacija);
- for(int j=0; j<niza[i].n; j++) {
- printf("%s %d %.2f\n",niza[i].niza[j].ime,niza[i].niza[j].traenje,niza[i].niza[j].cena);
- }
- }
- }
- void najdobar_park(ZabavenPark *niza, int n) {
- int i,j,k,maxi=0,br=0,maxbr=0,vkupno[100]= {0};
- for(i=0; i<n; i++) {
- for(j=0; j<niza[i].n; j++) {
- vkupno[i]+=niza[i].niza[j].traenje;
- if(niza[i].niza[j].daliPopust==1) {
- br++;
- }
- if(br>maxbr) {
- maxbr=br;
- maxi=i;
- }
- }
- }
- for(i=0; i<n; i++) {
- if(br==maxbr) {
- if(vkupno[i]>vkupno[maxi]) {
- maxi=i;
- }
- }
- }
- printf("Najdobar park: %s %s",niza[maxi].ime,niza[maxi].lokacija);
- }
- int main() {
- int i, j, n, broj;
- //kreiraj niza od maksimum 100 zabavni parkovi
- ZabavenPark ff[100];
- scanf("%d", &n);
- //citanje na podatocite
- for (i = 0; i < n; i++) {
- //ime na festivalot
- scanf("%s", ff[i].ime);
- //mesto
- scanf("%s", ff[i].lokacija);
- //broj na filmovi
- scanf("%d", &ff[i].n);
- for (j = 0; j < ff[i].n; j++) {
- scanf("%s", ff[i].niza[j].ime); /* Ime na filmot */
- scanf("%d", &ff[i].niza[j].traenje); /* Vremetraenje */
- scanf("%f", &ff[i].niza[j].cena); /* Cena */
- scanf("%d", &ff[i].niza[j].daliPopust); /* Popust */
- }
- }
- pecati(ff,n);
- najdobar_park(ff,n);
- return 0;
- }
- 17. Гитари
- #include <iostream>
- #include <cstring>
- using namespace std;
- 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