C++ program for medical shop store
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<<"\n enter the medicine name:-";
cin>>med;
cout<<"\n enter qty:-";
cin>>qty;
cout<<"enter price";
cin>>price;
}
void display()
{
cout<<"\n medicine name:-"<<med;
flushall();
cout<<"\n quantity:-"<<qty;
cout<<"\n price:-"<<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<<"\n enter the medicine name which is to be sold:-";
cin>>n;
cout<<"\n how 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\t display 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 price 56
enter the medicine name:-12
enter qty:-76
enter price 45
enter the medicine name:-df
enter qty:-34
enter price 12
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