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;
}

Code For Printing ASCII Table in C++

#include<iostream>
using namespace std;
void main()
{
for(int b=0;b<=255;b++)
{
cout<<"<<< Character >>> "<<(char)b<<" <<<No In Ascii Table >>> "<<b<<endl;
}
system("pause");
}

Student Database Software Code For C++

#include<iostream>
#include<fstream>
#include<conio.h>
using namespace std;
class student
{
private:
int id;
char name[30];
char age[20];
char address[150];
char phone[20];
char qual[100];
char db[100];
public:
void getdata()
{
cout<<"Enter Student ID: ";
cin>>id;
cin.ignore();
cout<<"\nEnter Student Name: ";
gets_s(name);
cin.ignore();
cout<<"Enter Student Address: ";
gets_s(address);
cin.ignore();
cout<<"Enter Student Ph#: ";
gets_s(phone);
cin.ignore();
cout<<"Enter Student Age: ";
gets_s(age);
cin.ignore();
cout<<"Enter Student Qualification: ";
gets_s(qual);
cin.ignore();
cout<<"Enter Student Date Of Birth: ";
gets_s(db);
cin.ignore();
}
void showdata()
{
cout<<"\nID: "<<id<<endl;
cout<<"\nName: "<<name<<endl;
cout<<"\nAddress :"<<address<<endl;
cout<<"\nPh#: "<<phone<<endl;
cout<<"\nAge: "<<age<<endl;
cout<<"\nQualification: "<<qual<<endl;
cout<<"\nDate Of Birth: "<<db<<endl;
cout<<""<<endl;
}
int rtrnid()
{
return id;
}
};
void write_data()
{
          student a;
          ofstream fout;
 fout.open("d:\\student.dat",ios::binary|ios::app);
          a.getdata();
          fout.write((char*)&a,sizeof(a));
          fout.close();
}
void search (int n)
{
          student a;
          ifstream fin;
 fin.open("D:\\student.dat",ios::binary);
          while(fin.read((char*)&a,sizeof(a)))
          {
                     if(a.rtrnid()==n)
{
cout<<"\nRecord For ID "<<n<<" Is Given Below\n ";
a.showdata();
break;
}
          }
          fin.close();
}
void del(int n)
{
          student a;
          ifstream fin;
 fin.open("D:\\student.dat",ios::in|ios::binary);
          ofstream fout;
 fout.open("D:\\temp.dat",ios::out|ios::binary);
          while(fin.read((char*)&a,sizeof(a)))
          {
                      if(a.rtrnid()!=n)
 {
                      fout.write((char*)&a,sizeof(a));
 break;
 }
 fin.read((char*)&a,sizeof(a));
          }
          fin.close();
          fout.close();
 remove("D:\\student.dat");
 rename("D:\\temp.dat","D:\\student.dat");
}
void modify(int n)
{
          fstream fout;
          student a;
          int found=0,cnt=0;
 fout.open("d:\\student.dat",ios::ate|ios::in|ios::out|ios::binary);
 fout.seekg(0,ios::beg);
          while( fout.read((char*)&a,sizeof(a)))
          {cnt++;
                if(a.rtrnid()==n)
                     {
                             found=1;
a.showdata();break;
                    }
 }
 if(found)
 {
 cout<<"\nModify Above Record: "<<endl;

 fout.seekp((cnt-1)* sizeof(a));
  a.getdata();
                              fout.write((char*)&a,sizeof(a));
 cout<<"\nRecord Has Been Successfully Updated\n";
                             
 }
 else  cout<<"Record Not found";
          fout.close();
}
void main()
{
int opt;
while(1)
{
system("CLS");
cout<<"====================="<<endl;
cout<<": Students Database :"<<endl;
cout<<"====================="<<endl;
cout<<""<<endl;
cout<<"<<<<< MAIN MENU >>>>>"<<endl;
cout<<""<<endl;
cout<<"1.Enter New Student Data"<<endl;
cout<<"2.Search Student Data"<<endl;
cout<<"3.Delete Student Data"<<endl;
cout<<"4.Modify Student Data"<<endl;
cout<<"0.Exit"<<endl;
cout<<"Enter your Option : ";
cin>>opt;
switch(opt)
{
case 1:
{
system("CLS");
cout<<"<<< NEW STUDENT ENTRY >>>"<<endl;
cout<<""<<endl;
write_data();
cout<<"\nYour Data Has Been Recoded\n";
cout<<"\nPress Any Key For Main Menu";
getch();
break;
}
case 2:
{
system("CLS");
cout<<"<<< STUDNET SEARCH >>>"<<endl;
cout<<""<<endl;
int n;
cout<<"Enter Student ID to Search Record: ";
cin>>n;
search(n);
cout<<"\nPress Any Key For Main Menu";
getch();
break;
}
case 3:
{
system("CLS");
cout<<"DELETE STUDENT RECORD"<<endl;
cout<<""<<endl;
int b;
cout<<"Enter Student ID You Want To Delete: "<<endl;
cin>>b;
del(b);
cout<<"\nRecord of "<<b<<" Has been Deleted"<<endl;
cout<<"\nPress Any Key For Main Menu";
getch();
break;
}
case 4:
{
system("CLS");
cout<<"MODIFY STUDENT RECORD"<<endl;
cout<<""<<endl;
int b;
cout<<"Enter Student ID To Modify RECORD: "<<endl;
cin>>b;
modify(b);
cout<<"\nPress Any Key For Main Menu";
getch();
break;
}
case 0:
{
exit(0);
}
default:
{
cout<<""<<endl;
cout<<"Invalid Input"<<endl;
cout<<""<<endl;
}
}
}
system ("pause");
}