include<iostream>
#include<string.h>
using namespace std;
class Item
{
private:
int barcode;
char *item_name;
public:
Item(int code=0,char *name= "not given"): barcode(code)
{
item_name=new char[strlen(name)+1];
strcpy(item_name,name);
}
setcode(int code)
{barcode=code;
}
int getcode()
{return barcode;
}
void scanner(int x)
{
if(x=barcode)
cout<<"\n code is matched item is ="<<item_name;
else
cout<<"\n code is not matched item is ="<<item_name;
}
printer()
{
if(barcode!=0)
cout<<"\n code="<<barcode<<"\tItem name is ="<<item_name;
else
cout<<"\n code="<<barcode<<"\t\tItem name is ="<<item_name;
}
~Item()
{delete []item_name;
}
};
class PackedFood: public Item
{
private:
int price_per_piece;
public:
PackedFood(int p=0,int c=0,char *n="not given"):price_per_piece(p),Item(c,n)
{
}
int getprice(void)
{return price_per_piece;}
setprice(int x)
{price_per_piece=x;}
void scanner(int x)
{
Item::scanner(x);
cout<<"\t price per item="<<price_per_piece;
}
void printer(void)
{
Item::printer();
cout<<"\t price per item="<<price_per_piece;
}
};
class FreshFood: public Item
{
private:
int weight;
int price_per_ruppe;
public:
FreshFood(int w=0,int p=0,int c=0,char *n="not given"):weight(w),price_per_ruppe(p),Item(c,n)
{
}
setweight(int x)
{weight+x;
}
int getweight(void)
{return weight;
}
printer()
{Item::printer();
cout<<"\t price per weight="<<price_per_ruppe*weight;
}
scanner(int x)
{Item::scanner(x);
cout<<"\t price per weight="<<price_per_ruppe*weight;
}
};
int main()
{
Item a(37,"Iron");
PackedFood c(23,34,"bulb");
FreshFood e(10,20,30,"carrot");
a.printer();
c.printer();
e.printer();
cout<<endl;
Item b;
PackedFood d;
FreshFood f;
b.printer();
d.printer();
f.printer();
return 0;
}