Medical Store Managment System in C++

#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>
#include <string.h>
using namespace std;
int main();
class Medicine{
public:
    string name;
    string weight;
    string type;
    string expiryDate;
};
void DisplyMed(Medicine m){
    cout << endl;
    cout << "\tMedicine : " << m.name << endl;
    cout << "\tType : " << m.type << endl;
    cout << "\tWeight : " << m.weight << endl;
    cout << "\tExpiry Date : " << m.expiryDate << endl;
}
// Node for Linked list
class mNode{
public:
    Medicine m;
    mNode *next;
    mNode(){
        next = NULL;
    }
};
//Linked List class for Medicine
class mList{
    mNode *head;
public:
    mList(){
        head = NULL;
    }
    bool isEmpty();
    void addMedicine(Medicine newMedicine);
    void searchMedicine(string mName);
    void DisplayMed(string mType);
    void removeMedicine(string mName);
    void showM_List();
    void countMedicine();
}newList;
// to check list is empty or not
bool mList::isEmpty(){
    return(head == NULL);
}
// to add medicine at end
void mList::addMedicine(Medicine newMedicine){
    if (head == NULL){
        head = new mNode;
        head->m = newMedicine;
        head->next = NULL;
    }
    else if (head->next == NULL){
        head->next = new mNode;
        head->next->m = newMedicine;
        head->next->next = NULL;
    }
    else{
        mNode *temp = head;
        while (temp->next != NULL){
            temp = temp->next;
        }
        temp->next = new mNode;
        temp->next->m = newMedicine;
        temp->next->next = NULL;
    }
}
// searching medicine by name
void mList::searchMedicine(const string mName){
    if (isEmpty()){
        cout << "/tEmpty List!" << endl;
    }
    else{
        mNode *temp = head;
        bool found = false;
        while (temp != NULL && !found){
            if (temp->m.name.compare(mName) == 0){
                found = true;
            }
            else{
                temp = temp->next;
            }
        }
        if (found){
            DisplyMed(temp->m);
        }
        else{
            cout << "/tMedicine not Found!" << endl;
        }
        delete temp;
    }

}
// to display medicine of same type
void mList::DisplayMed(string mType){
    if (isEmpty()){
        cout << "\tEmpty List!" << endl;
    }
    else{
        mNode *temp = head; bool c = false;
        while (temp != NULL){
            if (temp->m.type.compare(mType) == 0){
                c = true;
                DisplyMed(temp->m);
                cout << endl;
            }
            temp = temp->next;
        }
        delete temp;
        if (!c){
            system("cls");;
            cout << "\tNo Medicines found of " << mType << " Type."
                << endl;
            Sleep(1000);
        }

    }
}
// to display all Medicines in the list
void mList::showM_List(){
    if (isEmpty()){
        cout << "Empty List!" << endl;
    }
    else{
        mNode *temp = head;
        while (temp != NULL){
            DisplyMed(temp->m);
            temp = temp->next;
        }
        delete temp;
    }

}
void mList::removeMedicine(string mName){
    if (isEmpty()){
        cout << "\tEmpty List!" << endl;
    }
    else if (head->next == NULL){
        head == NULL;
        cout << "\tMedicine Deleted!" << endl;
    }
    else if (head->m.name.compare(mName) == 0){
        head = head->next;
        cout << "\tMedicine Deleted!" << endl;
    }
    else{
        mNode *temp = head->next;
        mNode *prev = head;
        bool found = false;
        while (temp != NULL){
            if (temp->m.name.compare(mName) == 0){
                found = true;
                break;
            }
            prev = temp;
            temp = temp->next;
        }
        if (found){
            prev = temp->next;
            cout << "\tMedicine Deleted!" << endl;
        }
        else{
            cout << "Medicine not Found!" << endl;
        }
        delete temp;
        delete prev;
    }
}
void mList::countMedicine(){
    int count = 0;
    mNode *temp = head;
    while (temp != NULL){
        count++;
        temp = temp->next;
    }
    cout << "\tNumber of Medicine(s) in the "
        << "List is " << count << endl;
    delete temp;

}
void displayNote(){
    cout << "Note : You can only Add 3 types of Medicines." << endl;
    cout << "\t1.Liquid\n\t2.Tablet\n\t3.Capsules\n";
    cout << "\tYour Choice : ";
}
void displayMenu(){
    cout << "\t1.To ADD new Medicine." << endl;
    cout << "\t2.To REMOVE Medicine." << endl;
    cout << "\t3.To FIND Medicine by Name." << endl;
    cout << "\t4.To SHOW Medicines of same Type." << endl;
    cout << "\t5.To DISPLAY all Medicines." << endl;
    cout << "\t0. To EXIT. " << endl;
    cout << "\tYour Choice : ";
}
void case0(){
}
void case1(){
    system("cls");
    displayNote();
    Medicine nM;
    char c;
    cin >> c;
    if ((c < '1') || (c > '3')){
        case1();
    }
    system("cls");
    cout << "Enter Med's Name: ";
    cin >> nM.name;
    if (c == '1'){
        nM.type = "Liquid";
    }
    if (c == '2')
        nM.type = "Tablet";
    if (c == '3')
        nM.type = "Capsules";
    if (c == '1'){
        cout << "Enter Med's Quantity(ml) : ";
        cin >> nM.weight;
    }
    else{
        cout << "Enter Med's Weight(mg) : ";
        cin >> nM.weight;
    }
    cout << "Enter Expiry Date (dd/mm/yyyy) : ";
    cin >> nM.expiryDate;

    newList.addMedicine(nM);
    system("cls");
    cout << "\tMedicine Added!";
    Sleep(1000);
    system("cls");
    main();
}
void case2(){
    system("cls");
    if (newList.isEmpty()){
        cout << "Empty List! Nothing to Remove." << endl;
    }
    else{
        string name;
        cout << "\tEnter Med's Name to Delete : ";
        cin >> name;
        newList.removeMedicine(name);
    }
    Sleep(2000);
    system("cls");
    main();
}
void case3(){
    system("cls");
    string name;
    cout << "Enter Medicine Name to Find : ";
    cin >> name;
    newList.searchMedicine(name);
    system("pause");
    system("cls");
    main();
}
void case4(){
    system("cls");
    if (newList.isEmpty()){
        cout << "\tNo Medicines in the List!" << endl;
        Sleep(2000);
    }
    else{
        cout << "Note.Following Med's type could in the List\n";
        cout << "\t1.Liquid\n\t2.Tablet\n\t3.Capsules\n";
        cout << "\tYour Choice : "; char c;
        cin >> c;
        system("cls");
        if (c <'1' || c > '3'){
            case4();
        }
        if (c == '1')
            newList.DisplayMed("Liquid");
        if (c == '2')
            newList.DisplayMed("Tablet");
        if (c == '3')
            newList.DisplayMed("Capsules");
        system("pause");
    }
    system("cls");
    main();
}
void case5(){
    system("cls");
    if (!newList.isEmpty()){
        newList.countMedicine();
    }
    Sleep(2000);
    newList.showM_List();
    system("pause");
    system("cls");
    main();
}
void caseD(){
    system("cls");
    system("color 40");
    cout << "\t\tInvalid Input!" << endl;
    Sleep(1000);
    system("color F0");
    system("cls");
    main();
}
int main(){

    char choice;
    displayMenu();
    cin >> choice;
    switch (choice){
    case '0':
        exit(0);
        break;
    case '1':
        case1();
        break;
    case '2':
        case2();
        break;
    case '3':
        case3();
        break;
    case '4':
        case4();
        break;
    case '5':
        case5();
        break;
    default:
        caseD();
    }
    return 0;
}

No comments:

Post a Comment