Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Задача 1:
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Ekipa{
- private:
- char ime[15];
- int pobedi, porazi;
- public:
- Ekipa(char im[15]="", int pob=0, int por=0){
- strcpy(ime, im);
- pobedi=pob;
- porazi=por;
- }
- char* getime(){return ime;}
- int getpobedi(){return pobedi;}
- int getporazi(){return porazi;}
- virtual void pecati(){}
- };
- class FudbalskaEkipa:public Ekipa{
- private:
- int crveni, zuti, nereseni;
- public:
- FudbalskaEkipa(char ime[15], int pobe, int pord, int cr,int zu,int ner):Ekipa(ime, pobe, pord){
- crveni=cr;
- zuti=zu;
- nereseni=ner;
- }
- void pecati(){
- int poeni=0;
- poeni+=getpobedi()*3 + nereseni;
- cout<<"Ime: "<<getime()<<"\tPobedi: "<<getpobedi()<<"\tPorazi: "<<getporazi()<<"\tNereseni: "<<nereseni<< "\t" <<"\tCrveni: "<<crveni<<"\tZolti: "<<zuti<<"\tPoeni: "<<poeni<<endl;
- }
- };
- class KosarkarskaEkipa:public Ekipa{
- private:
- int greski, obidi;
- public:
- KosarkarskaEkipa(char ime[15], int pobe, int pord, int gr,int obi):Ekipa(ime, pobe, pord){
- greski=gr;
- obidi=obi;
- }
- void pecati(){
- double procent;
- procent=getpobedi()*1.0/(getpobedi() + getporazi());
- procent*=100;
- cout<<"Ime: "<<getime()<<"\tPobedi: "<<getpobedi()<<"\tPorazi: "<<getporazi()<<"\tLicni: "<<greski<<"\tObidi: "<<obidi<<"\tProcent: "<<procent<<endl;
- }
- };
- void statistika(Ekipa** ekipi,int vkupno)
- {
- int i;
- for(i=0;i<vkupno;i++)
- {
- (*ekipi[i]).pecati();
- }
- }
- int main(){
- KosarkarskaEkipa gele("Kometal",10,2,1,2);
- KosarkarskaEkipa *kp=&gele;
- Ekipa** Sp;
- Sp = new Ekipa*[3];
- Sp[0]=kp;
- statistika(Sp, 1);
- delete [] Sp;
- return 0;
- }
- ---
- Задача 2:
- #include <iostream>
- #include <cstring>
- using namespace std;
- class ZicanInstrument{
- private:
- int brnazici,cena;
- char ime[20];
- public:
- ZicanInstrument(char im[20],int brzic, int cen){
- strcpy(ime, im);
- brnazici=brzic;
- cena=cen;
- }
- int getcena(){return cena;}
- char* getime(){return ime;}
- int getzici(){return brnazici;}
- friend bool operator==(ZicanInstrument &z1, ZicanInstrument &z2){
- if (z1.brnazici != z2.brnazici) return 0;
- return 1;
- }
- virtual void pecati(){}
- virtual float presmetajcena(){}
- };
- class Violina:public ZicanInstrument{
- private:
- char forma[20];
- public:
- Violina(char ime[20], int brzici, int cena, char formaa[20]):ZicanInstrument(ime, brzici, cena){
- strcpy(forma, formaa);
- }
- float presmetajcena(){
- if (!strcmp(forma, "Neapolitan"))return getcena()*1.15;
- return getcena();
- }
- void pecati(){
- cout<<"Ime: "<<getime()<<" Zici: "<<getzici()<<" Cena: "<<presmetajcena()<<" Forma: "<<forma<<endl;
- }
- };
- class Mandolina:public ZicanInstrument{
- private:
- float golemina;
- public:
- Mandolina(char ime[20], int brzici, int cena, float gol):ZicanInstrument(ime, brzici, cena){
- golemina = gol;
- }
- float presmetajcena(){
- if (golemina==0.25)return getcena()*1.1;
- if (golemina==1.00)return getcena()*1.2;
- return getcena();
- }
- void pecati(){
- cout<<"Ime: "<<getime()<<" Zici: "<<getzici()<<" Cena: "<<presmetajcena()<<" Golemina: "<<golemina<<endl;
- }
- };
- void pecatenje(ZicanInstrument z1, ZicanInstrument** zicani,int vkupno)
- {
- int i;
- for(i=0;i<vkupno;i++)
- {
- if (z1.getzici() == (*zicani[i]).getzici()){
- cout<<"Ime: "<< (*zicani[i]).getime()<<" Cena: "<<(*zicani[i]).presmetajcena() << endl;
- }
- }
- }
- int main(){
- Violina v3("Zele", 30, 10, "Neapolitan");
- Violina v1("Gele", 30, 10, "Neapolitan");
- Mandolina v2("Gele", 30, 10, 1);
- Violina *vp1 = &v1;
- Mandolina *vp2 = &v2;
- ZicanInstrument** Pointer;
- Pointer = new ZicanInstrument*[3];
- Pointer[0]=vp1;
- Pointer[1]=vp2;
- pecatenje(v3, Pointer, 2);
- delete [] Pointer;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement