Re: comp.language, c++
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class prdcts;
void detail(prdcts *ptr2); //function recieving adress as an argument for run-time polymorphism
class prdcts
{
protected :
char c,*cptr;
char name[25];
char brndnme[25],*tag;
float price;
long artno;
char splr_nme[25], splr_adrs[30],splr_wbadrs[30];
double splr_cntcno;
int qty;
public :
virtual void enter() =0;
virtual void disp()=0;
prdcts()
{
c='@';
}
};
class b: public prdcts
{
char tg[10];
char flavr[30];
float wt;
public:
b()
{}
void enter()
{
clrscr();
cout<<"\nEnter the Product name :";
gets(name);
cout<<"\nEnter the Brand name :";
gets(brndnme);
cout<<"\nEnter the flavour :";
gets(flavr) ;
cout<<"\nEnter the wt (ml) :" ;
cin>>wt;
cout<<"\nEnter the Tag : ";
gets(tag);
cout<<"\nEnter the Price :";
cin>>price;
cout<<"\nEnter the Article no. :" ;
cin>>artno;
cout<<"\nEnter the Supplier Name : ";
gets(splr_nme);
cout<<"\nEnter the Supplier Adress : ";
gets(splr_adrs);
cout<<"\nEnter the Supplier contact no :";
cin>>splr_cntcno;
cout<<"\nEnter the Web contact :";
agn: //label
gets(splr_wbadrs);
cptr=strchr(splr_wbadrs,c);
if(!cptr)
{
getch();
gotoxy(24,22);
clreol();
goto agn;
}
}
void disp()
{
clrscr();
cout<<"\nProduct Name :"<<name;
cout<<"\nBrand Name\t:"<<brndnme ;
cout<<"\nTag\t :"<<tag;
cout<<"\nFlavour\t :"<<flavr;
cout<<"\nWeight (gm) :"<<wt;
cout<<"\nPrice\t : "<<price;
cout<<"\nArticle No. :"<<artno;
}
void modify()
{
}
~b()
{}
} ;
class cosmetics: public prdcts
{
char tg1[10];
float wght;
public:
void enter()
{
clrscr();
cout<<"\nEnter the Product name :";
gets(name);
cout<<"\nEnter the Brand name :";
gets(brndnme);
cout<<"\nEnter the wt (ml) :" ;
cin>>wght;
cout<<"\nEnter the Tag : ";
gets(tg1);
strcpy(tag,tg1);
cout<<"\nEnter the Price :";
cin>>price;
cout<<"\nEnter the Article no. :" ;
cin>>artno;
cout<<"\nEnter the Supplier Name : ";
gets(splr_nme);
cout<<"\nEnter the Supplier Adress : ";
gets(splr_adrs);
cout<<"\nEnter the Supplier contact no :";
cin>>splr_cntcno;
cout<<"\nEnter the Web contact :";
agn1: //label
gets(splr_wbadrs);
cptr=strchr(splr_wbadrs,c);
if(!cptr)
{
getch();
gotoxy(24,22);
clreol();
goto agn1;
}
}
void disp()
{
clrscr();
cout<<"\nProduct Name :"<<name;
cout<<"\nBrand Name\t:"<<brndnme ;
cout<<"\nTag\t :"<<tag;
//cout<<"\nFlavour\t :"<<flavr;
cout<<"\nWeight (gm) :"<<wght;
cout<<"\nPrice\t : "<<price;
cout<<"\nArticle No. :"<<artno;
}
void modify()
{
cout<<"modify";
}
} ;
class kirana :public prdcts
{ char tg1[10];
float wght;
public:
void enter()
{
clrscr();
cout<<"\nEnter the Product name :";
gets(name);
cout<<"\nEnter the Brand name :";
gets(brndnme);
cout<<"\nEnter the wt (ml) :" ;
cin>>wght;
cout<<"\nEnter the Tag : ";
gets(tg1);
strcpy(tag,tg1);
cout<<"\nEnter the Price :";
cin>>price;
cout<<"\nEnter the Article no. :" ;
cin>>artno;
cout<<"\nEnter the Supplier Name : ";
gets(splr_nme);
cout<<"\nEnter the Supplier Adress : ";
gets(splr_adrs);
cout<<"\nEnter the Supplier contact no :";
cin>>splr_cntcno;
cout<<"\nEnter the Web contact :";
agn: //label
gets(splr_wbadrs);
cptr=strchr(splr_wbadrs,c);
if(!cptr)
{
getch();
gotoxy(24,22);
clreol();
goto agn;
}
}
void disp()
{
clrscr();
cout<<"\nProduct Name :"<<name;
cout<<"\nBrand Name\t:"<<brndnme ;
cout<<"\nTag\t :"<<tag;
// cout<<"\nFlavour\t :"<<flavr;
cout<<"\nWeight (gm) :"<<wght;
cout<<"\nPrice\t : "<<price;
cout<<"\nArticle No. :"<<artno;
}
void modify()
{
}
};
class stationary : public prdcts
{ char tg1[10];
float wght;
public:
void enter()
{
clrscr();
cout<<"\nEnter the Product name :";
gets(name);
cout<<"\nEnter the Brand name :";
gets(brndnme);
cout<<"\nEnter the wt (ml) :" ;
cin>>wght;
cout<<"\nEnter the Tag : ";
gets(tg1);
strcpy(tag,tg1);
cout<<"\nEnter the Price :";
cin>>price;
cout<<"\nEnter the Article no. :" ;
cin>>artno;
cout<<"\nEnter the Supplier Name : ";
gets(splr_nme);
cout<<"\nEnter the Supplier Adress : ";
gets(splr_adrs);
cout<<"\nEnter the Supplier contact no :";
cin>>splr_cntcno;
cout<<"\nEnter the Web contact :";
agn: //label
gets(splr_wbadrs);
cptr=strchr(splr_wbadrs,c);
if(!cptr)
{
getch();
gotoxy(24,22);
clreol();
goto agn;
}
}
void disp()
{
clrscr();
cout<<"\nProduct Name :"<<name;
cout<<"\nBrand Name\t:"<<brndnme ;
cout<<"\nTag\t :"<<tag;
// cout<<"\nFlavour\t :"<<flavr;
cout<<"\nWeight (gm) :"<<wght;
cout<<"\nPrice\t : "<<price;
cout<<"\nArticle No. :"<<artno;
}
void modify()
{
}
} ;
void main()
{
clrscr();
prdcts *p1;
int z,chc;
char ch='y' ;
do
{
cout<<endl<<endl<<"1. Brevages ";
cout<<endl<<"2. Cosmetics";
cout<<endl<<"3. Kirana" ;
cout<<endl<<"4. Stationary " ;
cout<<endl<<"Enter your choice :";
cin>>z;
if(z==1)
{
b b1;
p1=&b1;
detail(p1);
}
if(z==2)
{
cosmetics c;
p1=&c;
detail(p1);
}
if(z==3)
{
kirana k;
p1=&k;
detail(p1);
}
if(z==4)
{
stationary s;
p1=&s;
detail(p1);
}
gotoxy(40,23);
cout<<"\nDo you wish to continue :" ;
cin>>ch;
}while(ch!='n');
getch();
}
void detail(prdcts *p2)
{
int chc;
fstream fi;
clrscr();
gotoxy(5,5);
cout<<"1.Add Record ";
gotoxy(23,5);
cout<<"2.Delete Record ";
gotoxy(43,5);
cout<<"3.Modify Reord ";
gotoxy(63,5);
cout<<"4.View Record";
gotoxy(28,21);
cout<<"Enter your choice :";
cin>>chc;
if(chc==1)
{ fi.open("dexter.txt",ios::out|ios::app|ios::binary);
p2->enter();
fi.write((char *)&p2,sizeof(*p2));
fi.close();
}
if(chc==3)
{
gotoxy(43,7);
cout<<"Modify 'N'ame ";
gotoxy(43,8);
cout<<"Modify 'P'rice ";
gotoxy(43,9);
cout<<"Modify 'Q'ty ";
gotoxy(43,10);
cout<<"Modify 'T'ag ";
}
if(chc==4)
{
gotoxy(63,7);
cout<<"'S'earch a Record ";
gotoxy(63,8);
cout<<"'L'ook all Record ";
gotoxy(63,9);
cout<<" Your Choice : ";
cin>>chc;
if(chc==2)
{
fi.open("dexter.txt",ios::in);
fi.seekg(0);
while(!fi.eof())
{
fi.read((char *)&p2,sizeof(*p2));
p2->disp();
cout<<"Hello";
}
fi.close();
}
}
}
now check this, and tell