Advertisement
jovanovski

НРС Лаб.5

Mar 18th, 2012
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.59 KB | None | 0 0
  1. Задача 1:
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5. class Ekipa{
  6. private:
  7. char ime[15];
  8. int pobedi, porazi;
  9. public:
  10. Ekipa(char im[15]="", int pob=0, int por=0){
  11. strcpy(ime, im);
  12. pobedi=pob;
  13. porazi=por;
  14. }
  15. char* getime(){return ime;}
  16. int getpobedi(){return pobedi;}
  17. int getporazi(){return porazi;}
  18. virtual void pecati(){}
  19. };
  20.  
  21. class FudbalskaEkipa:public Ekipa{
  22. private:
  23. int crveni, zuti, nereseni;
  24. public:
  25. FudbalskaEkipa(char ime[15], int pobe, int pord, int cr,int zu,int ner):Ekipa(ime, pobe, pord){
  26. crveni=cr;
  27. zuti=zu;
  28. nereseni=ner;
  29. }
  30. void pecati(){
  31.     int poeni=0;
  32.     poeni+=getpobedi()*3 + nereseni;
  33. cout<<"Ime: "<<getime()<<"\tPobedi: "<<getpobedi()<<"\tPorazi: "<<getporazi()<<"\tNereseni: "<<nereseni<< "\t" <<"\tCrveni: "<<crveni<<"\tZolti: "<<zuti<<"\tPoeni: "<<poeni<<endl;
  34. }
  35. };
  36.  
  37. class KosarkarskaEkipa:public Ekipa{
  38. private:
  39. int greski, obidi;
  40. public:
  41. KosarkarskaEkipa(char ime[15], int pobe, int pord, int gr,int obi):Ekipa(ime, pobe, pord){
  42. greski=gr;
  43. obidi=obi;
  44. }
  45. void pecati(){
  46.     double procent;
  47.     procent=getpobedi()*1.0/(getpobedi() + getporazi());
  48.     procent*=100;
  49. cout<<"Ime: "<<getime()<<"\tPobedi: "<<getpobedi()<<"\tPorazi: "<<getporazi()<<"\tLicni: "<<greski<<"\tObidi: "<<obidi<<"\tProcent: "<<procent<<endl;
  50. }
  51. };
  52.  
  53. void statistika(Ekipa** ekipi,int vkupno)
  54. {
  55. int i;
  56. for(i=0;i<vkupno;i++)
  57. {
  58. (*ekipi[i]).pecati();
  59. }
  60. }
  61.  
  62. int main(){
  63. KosarkarskaEkipa gele("Kometal",10,2,1,2);
  64. KosarkarskaEkipa *kp=&gele;
  65. Ekipa** Sp;
  66. Sp = new Ekipa*[3];
  67. Sp[0]=kp;
  68. statistika(Sp, 1);
  69. delete [] Sp;
  70. return 0;
  71. }
  72.  
  73.  
  74. ---
  75. Задача 2:
  76. #include <iostream>
  77. #include <cstring>
  78. using namespace std;
  79.  
  80. class ZicanInstrument{
  81. private:
  82. int brnazici,cena;
  83. char ime[20];
  84. public:
  85. ZicanInstrument(char im[20],int brzic, int cen){
  86. strcpy(ime, im);
  87. brnazici=brzic;
  88. cena=cen;
  89. }
  90. int getcena(){return cena;}
  91. char* getime(){return ime;}
  92. int getzici(){return brnazici;}
  93. friend bool operator==(ZicanInstrument &z1, ZicanInstrument &z2){
  94. if (z1.brnazici != z2.brnazici) return 0;
  95. return 1;
  96. }
  97. virtual void pecati(){}
  98. virtual float presmetajcena(){}
  99. };
  100.  
  101. class Violina:public ZicanInstrument{
  102. private:
  103. char forma[20];
  104. public:
  105. Violina(char ime[20], int brzici, int cena, char formaa[20]):ZicanInstrument(ime, brzici, cena){
  106. strcpy(forma, formaa);
  107. }
  108.  
  109. float presmetajcena(){
  110.     if (!strcmp(forma, "Neapolitan"))return getcena()*1.15;
  111.     return getcena();
  112. }
  113. void pecati(){
  114. cout<<"Ime: "<<getime()<<" Zici: "<<getzici()<<" Cena: "<<presmetajcena()<<" Forma: "<<forma<<endl;
  115. }
  116. };
  117.  
  118. class Mandolina:public ZicanInstrument{
  119. private:
  120. float golemina;
  121. public:
  122. Mandolina(char ime[20], int brzici, int cena, float gol):ZicanInstrument(ime, brzici, cena){
  123. golemina = gol;
  124. }
  125.  
  126. float presmetajcena(){
  127.     if (golemina==0.25)return getcena()*1.1;
  128.     if (golemina==1.00)return getcena()*1.2;
  129.     return getcena();
  130. }
  131. void pecati(){
  132. cout<<"Ime: "<<getime()<<" Zici: "<<getzici()<<" Cena: "<<presmetajcena()<<" Golemina: "<<golemina<<endl;
  133. }
  134. };
  135.  
  136. void pecatenje(ZicanInstrument z1, ZicanInstrument** zicani,int vkupno)
  137. {
  138. int i;
  139. for(i=0;i<vkupno;i++)
  140. {
  141.     if (z1.getzici() == (*zicani[i]).getzici()){
  142.         cout<<"Ime: "<< (*zicani[i]).getime()<<" Cena: "<<(*zicani[i]).presmetajcena() << endl;
  143.     }
  144. }
  145. }
  146.  
  147.  
  148. int main(){
  149. Violina v3("Zele", 30, 10, "Neapolitan");
  150. Violina v1("Gele", 30, 10, "Neapolitan");
  151. Mandolina v2("Gele", 30, 10, 1);
  152. Violina *vp1 = &v1;
  153. Mandolina *vp2 = &v2;
  154. ZicanInstrument** Pointer;
  155. Pointer = new ZicanInstrument*[3];
  156. Pointer[0]=vp1;
  157. Pointer[1]=vp2;
  158. pecatenje(v3, Pointer, 2);
  159. delete [] Pointer;
  160. return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement