daily pastebin goal
60%
SHARE
TWEET

apothecary.cpp

a guest Jan 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<fstream>
  3. #include<stdlib.h>
  4. #include<vector>
  5. using namespace std;
  6. struct Date{
  7.     int year;
  8.     int month;
  9.     int day;
  10. };
  11. struct Drug{
  12.     char drugName[100];
  13.     char drugManufacturer[100];
  14.     int drugAmountDelivered;
  15.     int drugAmountInStock;
  16.     Date drugExpirationDate;
  17.     bool drugPrescriptionRequired;
  18.     Date drugManufacturedDate;
  19.     char drugShipment[100];
  20. };
  21. vector<Drug> drugs;
  22. static int drugMinAmount= 5;
  23.  
  24. void clearConsole(){
  25.     system("CLS");
  26. }
  27. void menu();
  28. void printDrugList();
  29. void viewDrugs();
  30. void createNewDrug(){
  31.     cin.clear();
  32.     cin.sync();
  33.     clearConsole();
  34.     Drug drugTemporaryInput;
  35.     string drugTemporaryPrescription;
  36.     cout<<"\t\t## CREATE NEW DRUG ##"<<endl;
  37.     cout<<"Please enter the required information. You can exit at any time by inputting 'exit' or 'quit'\n\n"<<endl;
  38.     cout<<"Drug name (100 characters limit):"<<endl;
  39.     cin.getline(drugTemporaryInput.drugName, 100);
  40.     cout<<"Drug manufacturer (100 characters limit):"<<endl;
  41.     cin.getline(drugTemporaryInput.drugManufacturer, 100);
  42.     cout<<"Amount delivered:"<<endl;
  43.     cin>>drugTemporaryInput.drugAmountDelivered;
  44.     cout<<"Amount currently in stock:"<<endl;
  45.     cin>>drugTemporaryInput.drugAmountInStock;
  46.  
  47.     cout<<"Expiration date YEAR:"<<endl;
  48.     cin>>drugTemporaryInput.drugExpirationDate.year;
  49.         while(drugTemporaryInput.drugExpirationDate.year<2018 || drugTemporaryInput.drugExpirationDate.year>3000){
  50.             cout<<"Invalid year, try again:"<<endl;
  51.             cin>>drugTemporaryInput.drugExpirationDate.year;
  52.         }
  53.  
  54.     cout<<"Expiration date MONTH:"<<endl;
  55.     cin>>drugTemporaryInput.drugExpirationDate.month;
  56.         while(drugTemporaryInput.drugExpirationDate.month<1 || drugTemporaryInput.drugExpirationDate.month>12){
  57.             cout<<"Invalid month, try again:"<<endl;
  58.             cin>>drugTemporaryInput.drugExpirationDate.month;
  59.         }
  60.     cout<<"Expiration date DAY:"<<endl;
  61.     cin>>drugTemporaryInput.drugExpirationDate.day;
  62.         while(drugTemporaryInput.drugExpirationDate.day<1 || drugTemporaryInput.drugExpirationDate.day>31){
  63.             cout<<"Invalid day, try again:"<<endl;
  64.             cin>>drugTemporaryInput.drugExpirationDate.day;
  65.         }
  66.     cin.clear();
  67.     cin.sync();
  68.     cout<<"Prescription required? Input 'yes' or 'no':"<<endl;
  69.     cin>>drugTemporaryPrescription;
  70.     while(drugTemporaryPrescription!="yes" && drugTemporaryPrescription!="no")
  71.     {
  72.         cout<<drugTemporaryPrescription;
  73.         cout<<"Invalid input, please try again. Input 'yes' or 'no':"<<endl;
  74.         cin>>drugTemporaryPrescription;
  75.     }
  76.     if(drugTemporaryPrescription=="yes"){
  77.         drugTemporaryInput.drugPrescriptionRequired=true;
  78.     }else if(drugTemporaryPrescription=="no"){
  79.         drugTemporaryInput.drugPrescriptionRequired=false;
  80.     }else{
  81.         cout<<"Something went wrong..."<<endl;
  82.     }
  83.  
  84.  
  85.        cout<<"Date manufactured, YEAR:"<<endl;
  86.     cin>>drugTemporaryInput.drugManufacturedDate.year;
  87.         while(drugTemporaryInput.drugManufacturedDate.year<2010 || drugTemporaryInput.drugManufacturedDate.year>3000){
  88.             cout<<"Invalid year, try again:"<<endl;
  89.             cin>>drugTemporaryInput.drugManufacturedDate.year;
  90.         }
  91.  
  92.     cout<<"Date manufactured, MONTH:"<<endl;
  93.     cin>>drugTemporaryInput.drugManufacturedDate.month;
  94.         while(drugTemporaryInput.drugManufacturedDate.month<1 || drugTemporaryInput.drugManufacturedDate.month>12){
  95.             cout<<"Invalid month, try again:"<<endl;
  96.             cin>>drugTemporaryInput.drugManufacturedDate.month;
  97.         }
  98.     cout<<"Date manufactured, DAY:"<<endl;
  99.     cin>>drugTemporaryInput.drugManufacturedDate.day;
  100.         while(drugTemporaryInput.drugManufacturedDate.day<1 || drugTemporaryInput.drugManufacturedDate.day>31){
  101.             cout<<"Invalid day, try again:"<<endl;
  102.             cin>>drugTemporaryInput.drugManufacturedDate.day;
  103.         }
  104.     cin.clear();
  105.     cin.sync();
  106.     cout<<"Drug shipment (100 characters limit):"<<endl;
  107.     cin.getline(drugTemporaryInput.drugShipment, 100);
  108.  
  109.     drugs.push_back(drugTemporaryInput);
  110.     clearConsole();
  111.     cout<<"Drug successfully added to database!\n\n"<<endl;
  112.     menu();
  113. }
  114. void deleteDrug(){
  115.     int drugDeletionID;
  116.     printDrugList();
  117.     cout<<"Please enter the ID of the drug you would like to delete from the database:"<<endl;
  118.     cin.clear();
  119.     cin.sync();
  120.     cin>>drugDeletionID;
  121.     while(drugDeletionID<0||drugDeletionID>drugs.size())
  122.     {
  123.         cout<<"Invalid input, ID out of range, please try again..."<<endl;
  124.         cin>>drugDeletionID;
  125.     }
  126.     drugs.erase (drugs.begin() + drugDeletionID - 1);
  127.     clearConsole();
  128.     cout<<"Drug #"<<drugDeletionID<<" has been successfully deleted."<<endl;
  129.     menu();
  130. }
  131. void printDrugList(){
  132.     for(int i=0;i<drugs.size(); i++){
  133.         cout<<"DRUG #"<<i+1<<endl;
  134.         cout<<"Name: "<<drugs[i].drugName<<endl;
  135.         cout<<"Manufacturer: "<<drugs[i].drugManufacturer<<endl;
  136.         cout<<"Amount delivered: "<<drugs[i].drugAmountDelivered<<endl;
  137.         cout<<"Amount in stock: "<<drugs[i].drugAmountInStock<<endl;
  138.         cout<<"Expiration date: "<<drugs[i].drugExpirationDate.day<<"."<<drugs[i].drugExpirationDate.month<<"."<<drugs[i].drugExpirationDate.year<<endl;
  139.         cout<<"Requires prescription?: "<<drugs[i].drugPrescriptionRequired<<endl;
  140.         cout<<"Date of manufacture: "<<drugs[i].drugManufacturedDate.day<<"."<<drugs[i].drugManufacturedDate.month<<"."<<drugs[i].drugManufacturedDate.year<<endl;
  141.         cout<<"Shipment: "<<drugs[i]. drugShipment<<endl;
  142.         cout<<endl;
  143.     }
  144. }
  145. void viewDrugs(){
  146.     string userResponseViewDrugs;
  147.     cout<<"###Drugs currently in database: "<<drugs.size()<<endl;
  148.     printDrugList();
  149.     cout<<"Input 'menu' to return to the main menu or 'exit' to quit"<<endl;
  150.     while(userResponseViewDrugs!="menu"&&userResponseViewDrugs!="exit"){
  151.         cin>>userResponseViewDrugs;
  152.         if(userResponseViewDrugs=="menu"){
  153.             menu();
  154.         }else if(userResponseViewDrugs=="exit"){
  155.             exit(0);
  156.         }else{
  157.         cout<<"Invalid input, enter 'menu' to return to the main menu or 'exit' to quit"<<endl;
  158.         }
  159.     }
  160. }
  161. void menu(){
  162.     int userResponseMenu;
  163.     cout<<"\t\t## MENU ##"<<endl;
  164.     cout<<"1. Create new drug profile..."<<endl;
  165.     cout<<"2. Delete drug profile..."<<endl;
  166.     cout<<"3. View all drug profiles..."<<endl;
  167.     cout<<"4. View all drug profiles between two manufacture dates..."<<endl;
  168.     cout<<"5. View drug profiles by manufacturer..."<<endl;
  169.     cout<<"6. View drugs with less than " <<drugMinAmount<< " in stock..."<<endl;
  170.     cout<<"7. View total amount of drug profiles in system..."<<endl;
  171.     cout<<"To access the option of your choosing, simply input its number and press ENTER"<<endl;
  172.     cout<<"To exit, please enter 0."<<endl;
  173.     while(true){
  174.         cin>>userResponseMenu;
  175.         switch(userResponseMenu)
  176.         {
  177.             case 0:
  178.                 exit(0);
  179.             case 1:
  180.                 createNewDrug();
  181.                 break;
  182.             case 2:
  183.                 deleteDrug();
  184.                 break;
  185.             case 3:
  186.                 viewDrugs();
  187.                 break;
  188.             default:
  189.                 cout<<"Invalid input..."<<endl;
  190.  
  191.         }
  192.     }
  193. }
  194. int main(){
  195.     cout<<"Welcome to the world worst apothecary stock management software!!"<<endl;
  196.     menu();
  197. }
  198. /*Тема 4: Да се състави програма на C++ за нуждите
  199. на аптека, която поддържа следната информация:
  200. Наименование на медикамент;
  201. Производител;
  202. Брой доставени;
  203. Брой в наличност;
  204. Срок на годност на медикамент;
  205. Отпуска се с рецепта;
  206. Дата на производство;
  207. Партида;
  208. Програмата извършва следните операции:
  209. 1.Създава масив от медикаменти;
  210. 2.Добавя нов медикамент;
  211. 3.Изтрива медикамент;
  212. 4.Извежда списък с имената на всички медикаменти
  213. между две въведени дати на производство;
  214. 5.Извежда списък на медикаментите, чиито
  215. производители започват с дадена дума;
  216. 6.Извежда списък на медикаментите, чиято
  217. наличност е под 5 към момента на ревизията;
  218. 7.Извежда общ брой медикаменти в аптеката.*/
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top