Advertisement
Guest User

PrimerNasleduvanje

a guest
May 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. class Proizvod{
  7. protected:
  8.     int cena;
  9.     float maslenost;
  10.     char proizvoditel[20];
  11. public:
  12.     Proizvod(){
  13.         cout<<"Default kaj proizvod"<<endl;
  14.      cena=0;
  15.      maslenost=0;
  16.      strcpy(proizvoditel,"");
  17.     }
  18.      Proizvod(int cena1,float maslenost1, char proizvoditel1[20]){
  19.          cout<<"Konstruktor so argumenti kaj proizvod"<<endl;
  20.     strcpy(proizvoditel,proizvoditel1);
  21.     cena=cena1;
  22.     maslenost=maslenost1;
  23.      }
  24.  
  25.       void pecati(){
  26.     cout<<proizvoditel<<" "<<cena<<" "<<maslenost<<" ";
  27.     }
  28.     void setCena(int cena1){
  29.      cena=cena1;
  30.     }
  31.     void setMaslenost(float maslenost1){
  32.       maslenost=maslenost1;
  33.     }
  34.     char *getProizvoditel(){
  35.      return proizvoditel;
  36.     }
  37.  
  38.     int getCena(){
  39.     return cena;
  40.     }
  41.     float getMaslenost(){
  42.     return maslenost;
  43.     }
  44.     void setProizvoditel(char *proizvoditel1){
  45.       strcpy(proizvoditel,proizvoditel1);
  46.     }
  47.  
  48. };
  49.  
  50. class Mleko:public Proizvod{
  51. private:
  52.     char poteklo[20];
  53. public:
  54.     Mleko(){
  55.         cout<<"Default kaj mleko"<<endl;
  56.      strcpy(poteklo,"");
  57.     }
  58.     Mleko(int cena1,float maslenost1, char *proizvoditel1,char *poteklo1)
  59.     :Proizvod(cena1,maslenost1,proizvoditel1){
  60.            cout<<"Konstruktor so argumenti kaj mleko"<<endl;
  61.         strcpy(poteklo,poteklo1);
  62.     }
  63.  
  64.       void setPoteklo(char *poteklo1){
  65.        strcpy(poteklo,poteklo1);
  66.       }
  67.       char *getPoteklo(){
  68.       return poteklo;
  69.       }
  70.  
  71.       void pecati(){
  72.           Proizvod::pecati();
  73.        cout<<poteklo<<endl;
  74.       }
  75.  
  76.  
  77. };
  78.  
  79. class Jogurt:public Proizvod{
  80. private:
  81.     char tip[20];
  82. public:
  83.        Jogurt(){
  84.      cena=0;
  85.      maslenost=0;
  86.      strcpy(proizvoditel,"");
  87.      strcpy(tip,"");
  88.     }
  89.     Jogurt(int cena1,float maslenost1, char *proizvoditel1,char *tip1){
  90.     strcpy(proizvoditel,proizvoditel1);
  91.     cena=cena1;
  92.     maslenost=maslenost1;
  93.     strcpy(tip,tip1);
  94.     }
  95.     void pecati(){
  96.      Proizvod::pecati();
  97.      cout<<tip<<endl;
  98.     }
  99.  
  100. };
  101.  
  102.  
  103. int main() {
  104. Mleko m(50,3,"Proizvoditel1","Kravjo");
  105. Jogurt j(55,1,"Proizvoditel2","Tip1");
  106. m.pecati();
  107. j.pecati();
  108.  
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement