Create a class medical shoppe containing
-medicine
-qty
-price
medicine details are stored into file medical.txt. when any medicine
has to be sold it is first searched into file. if found the quantity
is decremented that much quantity to be sold.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<iomanip.h>
#include<stdlib.h>
#include<stdio.h>
class medical
{
public:char med[20];
int qty,price;
public:void accept()
{
cout<<"\nenter the medicine name:-";
cin>>med;
cout<<"\nenter qty:-";
cin>>qty;
cout<<"enter price";
cin>>price;
}
void display()
{
cout<<"\nmedicine name:-"<<med;
flushall();
cout<<"\nquantity:-"<<qty;
cout<<"\nprice:-"<<price;
}
void search(char n[20],int q)
{
int ans=1;
ans=strcmp(med,n);
if (ans==0)
qty=qty-q;
}
};
int main()
{
medical m[3];
int i,q,ans;
char n[20];
clrscr();
fstream f1;
f1.open("a.doc",ios::trunc|ios::in|ios::out);
cout<<"\n\t\tenter the details\n";
for(i=0;i<3;i++)
{
m[i].accept();
f1.write((char *)&m[i],sizeof(m[i]));
}
f1.seekg(0);
cout<<"\nenter the medicine name which is to be sold:-";
cin>>n;
cout<<"\nhow much quantity you want:-";
cin>>q;
for(i=0;i<3;i++)
{
f1.read((char *)&m[i],sizeof(m[i]));
m[i].search(n,q);
f1.write((char *)&m[i],sizeof(m[i]));
}
cout<<"\n\t\tdisplay of all records in a file\n";
for(i=0;i<3;i++)
{
f1.read((char *)&m[i],sizeof(m[i]));
m[i].display();
}
getch();
return 0;
}
--------------------------------------------------------------------
OUTPUT
enter the details
enter the medicine name:-per
enter qty:-34
enter price56
enter the medicine name:-12
enter qty:-76
enter price45
enter the medicine name:-df
enter qty:-34
enter price12
enter the medicine name which is to be sold:-df
how much quantity you want:-12
display of all records in a file
medicine name:-per
quantity:-34
price:-56
medicine name:-12
quantity:-76
price:-45
medicine name:-df
quantity:-22
price:-12
-medicine
-qty
-price
medicine details are stored into file medical.txt. when any medicine
has to be sold it is first searched into file. if found the quantity
is decremented that much quantity to be sold.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<iomanip.h>
#include<stdlib.h>
#include<stdio.h>
class medical
{
public:char med[20];
int qty,price;
public:void accept()
{
cout<<"\nenter the medicine name:-";
cin>>med;
cout<<"\nenter qty:-";
cin>>qty;
cout<<"enter price";
cin>>price;
}
void display()
{
cout<<"\nmedicine name:-"<<med;
flushall();
cout<<"\nquantity:-"<<qty;
cout<<"\nprice:-"<<price;
}
void search(char n[20],int q)
{
int ans=1;
ans=strcmp(med,n);
if (ans==0)
qty=qty-q;
}
};
int main()
{
medical m[3];
int i,q,ans;
char n[20];
clrscr();
fstream f1;
f1.open("a.doc",ios::trunc|ios::in|ios::out);
cout<<"\n\t\tenter the details\n";
for(i=0;i<3;i++)
{
m[i].accept();
f1.write((char *)&m[i],sizeof(m[i]));
}
f1.seekg(0);
cout<<"\nenter the medicine name which is to be sold:-";
cin>>n;
cout<<"\nhow much quantity you want:-";
cin>>q;
for(i=0;i<3;i++)
{
f1.read((char *)&m[i],sizeof(m[i]));
m[i].search(n,q);
f1.write((char *)&m[i],sizeof(m[i]));
}
cout<<"\n\t\tdisplay of all records in a file\n";
for(i=0;i<3;i++)
{
f1.read((char *)&m[i],sizeof(m[i]));
m[i].display();
}
getch();
return 0;
}
--------------------------------------------------------------------
OUTPUT
enter the details
enter the medicine name:-per
enter qty:-34
enter price56
enter the medicine name:-12
enter qty:-76
enter price45
enter the medicine name:-df
enter qty:-34
enter price12
enter the medicine name which is to be sold:-df
how much quantity you want:-12
display of all records in a file
medicine name:-per
quantity:-34
price:-56
medicine name:-12
quantity:-76
price:-45
medicine name:-df
quantity:-22
price:-12