Vous êtes sur la page 1sur 11

Name: Ahmad Abdullah.

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;

for(int i=lastsize ; i<medsize ; i++)


{

cout<<"Enter Name of Medicine = ";


cin>>quantity[i].name;
cout<<"Enter Potency = ";
cin>>quantity[i].potency;
cout<<"Is it Tablet or Syrup?\nPress 0 for Syrup\nPress 1 for Tablet\n";
cin>>quantity[i].istablet;
cout<<"Enter Quantity = ";
cin>>quantity[i].available_quantity;
cout<<"Enter Price OF medicine = ";
cin>>quantity[i].price;
cout<<"Enter Code = ";
againcode:
cin>>quantity[i].code;
for(int j=0;j<i;j++)
{
if(quantity[i].code == quantity[j].code)
{
cout<<"This code is used for another Medicine\nplease Use
Another Code\nEnter code Again = ";
goto againcode;
}
}
mfg:
cout<<"Enter Manufacture dd/mm/yyyy = ";

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;

for(int i=0 ; i<medsize ; i++)


{
int len1=getlength(name);
int len2=getlength(quantity[i].name);
if(len1!=len2)
{
if(i==medsize-1)
{
menu();
cin>>choice;
if(choice=='P'||choice=='p')
goto again;
if(choice=='A'||choice=='a')
goto again;
if(choice=='E'||choice=='e')
goto end;
continue;
}
else
continue;
}
int x=0;
while(x<len1)
{
if(name[x]!=quantity[i].name[x])
break;
x++;
}
if(x!=len1)
{
if(i==medsize-1)
{
menu();
cin>>choice;
if(choice=='P'||choice=='p')
goto again;
if(choice=='A'||choice=='a')
goto again;
if(choice=='E'||choice=='e')
goto end;
continue;
}
else
continue;
}
else
{

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)
{

cout<<"\n\nQuantity Not Available\n Total


Quantity Available = "<<quantity[i].available_quantity<<endl<<endl;
char againquantity;

cout<<"Press P to Purchase Another Medicine\n";


cout<<"Press Q to Enter Quantity Again\n";
cout<<"Press E to exit\n";
cin>>againquantity;
system("CLS");
if(againquantity=='P'||againquantity=='p')
goto again;
if(againquantity=='Q'||againquantity=='q')
goto againquantity;
if(againquantity=='E'||againquantity=='e')
goto end;
goto againquantity;
}
else
{
cout<<"Invalid Quantity\n Quantity Cannot be
zero\n\n";
cout<<"Quantity Not Available\n Total Quantity
Available = "<<quantity[i].available_quantity;
goto againquantity;
}
}
}
}
}
end:
system("pause");
}
In below Picture of output we are taking input for Medicines that we want to add in
Medical Stock Management…

In below Picture of output we are giving inputs for two medicines…


In following Screenshot of output we show menu (in which we can add, Purchase and check
medicines that are out of stock) and wants to search medicines that are going out of
stock (Quantity less than 15)…

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).

Now asking to us for purchasing more medicines or to exit…

I pressed “E” to Exit and Here it ends…

Vous aimerez peut-être aussi