Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <math.h>
- using namespace std;
- class Proizvod{
- protected:
- int cena;
- float maslenost;
- char proizvoditel[20];
- public:
- Proizvod(){
- cout<<"Default kaj proizvod"<<endl;
- cena=0;
- maslenost=0;
- strcpy(proizvoditel,"");
- }
- Proizvod(int cena1,float maslenost1, char proizvoditel1[20]){
- cout<<"Konstruktor so argumenti kaj proizvod"<<endl;
- strcpy(proizvoditel,proizvoditel1);
- cena=cena1;
- maslenost=maslenost1;
- }
- void pecati(){
- cout<<proizvoditel<<" "<<cena<<" "<<maslenost<<" ";
- }
- void setCena(int cena1){
- cena=cena1;
- }
- void setMaslenost(float maslenost1){
- maslenost=maslenost1;
- }
- char *getProizvoditel(){
- return proizvoditel;
- }
- int getCena(){
- return cena;
- }
- float getMaslenost(){
- return maslenost;
- }
- void setProizvoditel(char *proizvoditel1){
- strcpy(proizvoditel,proizvoditel1);
- }
- };
- class Mleko:public Proizvod{
- private:
- char poteklo[20];
- public:
- Mleko(){
- cout<<"Default kaj mleko"<<endl;
- strcpy(poteklo,"");
- }
- Mleko(int cena1,float maslenost1, char *proizvoditel1,char *poteklo1)
- :Proizvod(cena1,maslenost1,proizvoditel1){
- cout<<"Konstruktor so argumenti kaj mleko"<<endl;
- strcpy(poteklo,poteklo1);
- }
- void setPoteklo(char *poteklo1){
- strcpy(poteklo,poteklo1);
- }
- char *getPoteklo(){
- return poteklo;
- }
- void pecati(){
- Proizvod::pecati();
- cout<<poteklo<<endl;
- }
- };
- class Jogurt:public Proizvod{
- private:
- char tip[20];
- public:
- Jogurt(){
- cena=0;
- maslenost=0;
- strcpy(proizvoditel,"");
- strcpy(tip,"");
- }
- Jogurt(int cena1,float maslenost1, char *proizvoditel1,char *tip1){
- strcpy(proizvoditel,proizvoditel1);
- cena=cena1;
- maslenost=maslenost1;
- strcpy(tip,tip1);
- }
- void pecati(){
- Proizvod::pecati();
- cout<<tip<<endl;
- }
- };
- int main() {
- Mleko m(50,3,"Proizvoditel1","Kravjo");
- Jogurt j(55,1,"Proizvoditel2","Tip1");
- m.pecati();
- j.pecati();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement