Académique Documents
Professionnel Documents
Culture Documents
Class/Section: BS(CS)-1A.
Submitted to: Sir Umar.
Arid No.: 2019-ARID-2938.
Project Name: Medical Stock Management.
#include<iostream>
using namespace std;
struct Date
{
int day,month,year;
};
struct medicine
{
int code;
char name[10];
int available_quantity;
char potency[6];
int price;
bool istablet; // true it means it is a tablet false means it is syrup
Date expdate,mfgdate;
};
int arraysize()
{
int size;
cout<<"How much Medicines you want to add = ";
cin>>size;
return size;
}
void menu()
{
cout<<"Invalid Or Not Available\n";
cout<<"Press P to Purchase Another Medicine\n";
cout<<"Press A to Again Enter Previous Option\n";
cout<<"Press E to Exit\n";
cout<<"Choice = ";
}
int getlength(char ch[])
{
int i=0;
while(ch[i]!='\0')
i++;
return i;
}
int count(medicine m[],int total,int criteria)
{
int c=0;
for(int i=0;i<total;i++)
{
if(m[i].available_quantity<criteria)
c++;
}
return c;
}
void sort(medicine m[],int total)
{
for(int i=0;i<total;i++)
{
int ind=i;
for(int j=i+1;j<total;j++)
{
if(m[ind].available_quantity>m[j].available_quantity)
ind=j;
}
medicine x=m[i];
m[i]=m[ind];
m[ind]=x;
cout<<"Medicine Name = "<<m[i].name<<"\tQuantity =
"<<m[i].available_quantity<<endl;
}
}
void lowstock(medicine m[],int total,int criteria)
{
int c=count(m,total,criteria);
if(c==0)
cout<<"No medicine out of stock ";
else
{
medicine *lowmed=new medicine[c]; // place values from m into lowmed whose
qty is less than criteria
for(int i=0;i<total;i++)
{
if(m[i].available_quantity<criteria)
{
lowmed=m;
}
}
sort(lowmed,c);
}
}
void main()
{
char choice;
int medsize=arraysize(),lastsize=0,newsize=0,check;
medicine *quantity = new medicine [medsize];
add:
medsize = medsize + newsize;
cin>>quantity[i].mfgdate.day>>quantity[i].mfgdate.month>>quantity[i].mfgdate.year;
exp:
cout<<"Enter Expiry dd/mm/yyyy = ";
cin>>quantity[i].expdate.day>>quantity[i].expdate.month>>quantity[i].expdate.year;
if(quantity[i].expdate.year<quantity[i].mfgdate.year)
{
char expmfg;
cout<<"Invalid input\nExpiry Date Can't be less than manufacture
Date\n";
cout<<"Press E to Again Enter Expriy Date\n";
cout<<"Press M to Again Enter Manufacture Date\n";
cin>>expmfg;
if(expmfg=='E'||expmfg=='e')
goto exp;
if(expmfg=='M'||expmfg=='m')
goto mfg;
}
}
system("CLS");
invalid:
cout<<"Press S to search out of stock Medicines\n";
cout<<"Press A to Add Medicines\n";
cout<<"Press P to Purchase Medicines\n";
cout<<"Choice = ";
cin>>choice;
if(choice=='A'||choice=='a')
{
cout<<"How Much Medicines You Want to add = ";
cin>>newsize;
lastsize = medsize;
goto add;
}
else if(choice=='S'||choice=='s')
{
int criteria;
cout<<"Enter Criteria = ";
cin>>criteria;
lowstock(quantity,medsize,criteria);
}
else if(choice=='P'||choice=='p')
{
again:
char name[10];
cout<<"Name Of Medicine = ";
cin>>name;
if(quantity[i].available_quantity==0)
{
menu();
cin>>choice;
if(choice=='P'||choice=='p')
goto again;
if(choice=='A'||choice=='a')
goto again;
if(choice=='E'||choice=='e')
goto end;
}
tabagain:
bool istablet;
cout<<"Tablet or Syrup?\nPress 0 for Syrup\nPress1 for
Tablet\n";
cin>>istablet;
if(!(istablet==quantity[i].istablet))
{
menu();
cin>>choice;
if(choice=='P'||choice=='p')
goto again;
if(choice=='A'||choice=='a')
goto tabagain;
if(choice=='E'||choice=='e')
goto end;
}
againpotency:
int flag=0;
char potency;
cout<<"Potency = ";
cin>>potency;
for(int j=0 ; j<6 ; j++)
if(potency == quantity[i].potency[j])
{
flag=1;
break;
}
}
if(flag==0)
{
cout<<"\nAvailable Potencies =
"<<quantity[i].potency<<endl;
menu();
cin>>choice;
if(choice=='P'||choice=='p')
goto again;
if(choice=='A'||choice=='a')
goto againpotency;
if(choice=='E'||choice=='e')
goto end;
}
if(flag==1)
{
againquantity:
int quantitymed=0;
cin.ignore();
cin.clear();
cout<<"Quantity = ";
cin>>quantitymed;
if(quantitymed>=0&&quantitymed<=quantity[i].available_quantity)
{
system("CLS");
cout<<"Price Of this Medicine =
"<<quantity[i].price<<"\n";
cout<<"Manufacture Date dd/mm/yyyy =
"<<quantity[i].mfgdate.day<<"/"<<quantity[i].mfgdate.month<<"/"<<quantity[i].mfgdate.year
<<"\n";
cout<<"Exipry Date dd/mm/yyyy =
"<<quantity[i].expdate.day<<"/"<<quantity[i].expdate.month<<"/"<<quantity[i].expdate.year
<<"\n\n\n";
cout<<"Do You Want to buy It?\n\n";
cout<<"Press b for buy\n";
cout<<"Press e to Exit\n";
cout<<"Press p to purchase another Medicine\n";
cout<<"Choice = ";
cin>>choice;
if(choice=='P'||choice=='p')
goto again;
if(choice=='E'||choice=='e')
goto end;
if(choice=='B'||choice=='b')
{
system("CLS");
cout<<"Remaining Quantity of "<<name<<" =
"<<quantity[i].available_quantity-quantitymed<<endl;
quantity[i].available_quantity=quantity[i].available_quantity-quantitymed;
cout<<"Press M to buy more Medicines\n";
cout<<"Press E to Exit\n";
cin>>choice;
system("CLS");
if(choice=='M'||choice=='m')
goto again;
if(choice=='E'||choice=='e')
goto end;
}
}
else if(quantitymed>quantity[i].available_quantity)
{
In below Picture we entered Medicine name to Purchase and program shows us the Price of
Medicine and tells us the expiry date of medicine. Now we are going to buy it…
Now program shows us the remaining quantity of Panadol (Medicine).