Monday 18 January 2016

MINIPROJECT C++ (CLINIC)


#include <iostream>
#include <cstdio>
#include <windows.h>



using namespace std;
int lulus=0;
void med();
struct student {
        char name1[100];
        char name2[100];
        char id[100];
        char phone[100];
        int number[100];
        string medicine[100];
        float price[100];
        int check(int);
        };

    struct student data;
    char xname2[1000];
    int doct;
    int w8num=0;
    long int recsize;


       struct med {
        int quantity;
        char namaubat[100];
        float price;
        };
    struct med data2;
    char medicine1[100];
    char another;


        struct payment {
         float pay;
         char med2[100];
         float harga;
         char name[100];
            };
    struct payment data3;


    FILE *f1,*f2,*f4;
int main()
{

    int a;
    int b;
    char another;


     f1=fopen("senarai.txt","rb+");

    if (f1 == NULL) {
        f1 = fopen("senarai.txt","wb+");

        if (f1==NULL)
        {
             puts("Cannot open file");
             return 0;
        }
        }
    f2=fopen("ubat.txt","rb+");

    if (f2 == NULL) {
        f2 = fopen("ubat.txt","wb+");

        if (f2==NULL)
        {
             puts("Cannot open file");
             return 0;
        }
        }
        f4=fopen("payment.txt","rb+");

    if (f4 == NULL) {
        f4 = fopen("payment.txt","wb+");

        if (f4==NULL)
        {
             puts("Cannot open file");
             return 0;
        }
        }
recsize = sizeof(data);
recsize = sizeof(data2);
recsize = sizeof(data3);
while(1) {
        system("cls");

                cout<<" *******************************************************************************\n";
                cout<<" \n\n\t\t\tWELCOME TO CLINIC ABDUL RAHMAN\n\n\n";
                cout<<" *******************************************************************************\n";
                cout<<" ===============================================================================\n";
                cout<<"\n                         1.>>>> NEW REGISTRATION <<<<\a"<<endl;
                _sleep(100);
                cout<<"\n                         2.>>>> EXISTING PATIENT <<<<\a"<<endl;
                _sleep(100);
                cout<<"\n                         3.>>>>>>>>> STAFF <<<<<<<<<<\a\n"<<endl;
                _sleep(100);
                cout<<"                         4.>>>>>>>> PHARMACY <<<<<<<<\a"<<endl;
                _sleep(100);
                cout<<"\n                         0.           EXIT         \a\n"<<endl;
                _sleep(100);
                cout<<" ===============================================================================\n";
                cout<<"                                please select: ";
                cin>>a;
    switch(a)
     {
    case 1 :
        system("cls");
                cout<<" *******************************************************************************\n";
                cout<<" \n\n\t\t\tCreate New Patient Database\n\n\n";
                cout<<" *******************************************************************************\n";
                fseek(f1,0,SEEK_END);
                w8num++;
                cout << "\t\t\t   REGISTERATION\n\n";
                cout << "First Name          : ";
                cin >> data.name1;
                cout << "Second Name         : ";
                cin >> data.name2;
                cout << "id Number           :";
                cin >> data.id;
                cout << "phone number        : ";
                cin >> data.phone;
                fwrite(&data,recsize,1,f1);
                cout<< "your number is :  "<<w8num<<endl;
                system("pause");
                system("cls");
                for(int i=0;i<4;i++)
                {
                cout<< "\n\n please waiting for your turn";
                for(int j=0;j<5;j++)
                {
                    cout<< ".";
                    _sleep(200);
                }
                cout<<endl;
                _sleep(200);
                system("cls");
                }


                break;



        case 2 :
                system("cls");
                int ceklist;
                cout << "\t\tVIEW RECORD DATA,ENTER 1 FOR CHECK LIST : ";
                cin  >> ceklist;
                if (ceklist==1)
                {
                system("cls");
                rewind(f1);
                cout <<"\t\t\t ALL PATIENT DATA \n\n";
                while (fread(&data,recsize,1,f1) == 1)
                {
                cout << "\n";
                cout <<"\nName          : " << data.name1 ;
                cout <<"\t"<<data.name2;
                cout <<"\nno. id        : "<<data.id;
                cout <<"\nphone number  : " <<data.phone;
                cout <<"\n\n";
                cout << "\n";
                }
                cout << "\n\n";
                system("pause");
                }
                system("cls");
                fseek(f1,0,SEEK_END);

                cout << "Enter Name of Patient : ";
                cin  >> data3.name;

                rewind(f1);
                while(fread(&data,recsize,1,f1) == 1)
                if (strcmp(data3.name,data.name1) == 0)
                    {
                    lulus=1;
                    w8num++;

                    cout << "Your Number is       : "<<w8num<<endl;
                    cout << "\n\n\n";
                    system ("pause");
                    system("cls");
                     for(int i=0;i<4;i++)
                {
                cout<< "\n\n please waiting for your turn";
                for(int j=0;j<5;j++)
                {
                    cout<< ".";
                    _sleep(200);
                }
                cout<<endl;
                _sleep(200);
                system("cls");
                }

                    }


                break;

    case 3:
            system("cls");
                int id2;
                    cout <<"CLICNIC ABDUL RAHMAN MANAGEMENT\n\n";
                    cout << "STAFF ID : ";
                    cin >> doct;
                    if(doct==1234){
                        med();
                    }
                    else{
                        break;
                    }
                        break;
    case 4:

            system("cls");
            int listubat,bilangan;

            float price;
            cout << "\t\t\t Press 1 For List of Medicine : ";
            cin  >> listubat;
            if (listubat==1)
                {
                cout <<"\t\t\t ALL RECORDED OF MEDICINE \n\n";

                system("cls");
                rewind(f2);
                while (fread(&data2,recsize,1,f2) == 1)
                {
                        cout << "\n";
                        cout <<"\n>medicine         : " << data2.namaubat;
                        cout <<"\n>quantity         : " << data2.quantity ;
                        cout <<"\n>myr per each     : " << data2.price;
                }
                cout << "\n\n";
                system("pause");
                }
                system("cls");
                fseek(f4,0,SEEK_END);

                cout << "Enter Name of Patient : ";
                cin  >> data3.name;

                rewind(f1);
                while(fread(&data,recsize,1,f1) == 1)
                {
                if (strcmp(data3.name,data.name1) == 0)
                    {
                    lulus=1;

                        cout << "Enter The Name of Medecine : ";
                        cin >> data3.med2;
                        rewind(f2);
                        while(fread(&data2,recsize,1,f2) == 1)
                            {
                            if (strcmp(data3.med2,data2.namaubat) == 0)
                                {
                                fseek(f2, - recsize, SEEK_CUR);
                                cout << "How many do you want? : ";
                                cin  >> bilangan;
                                price = data2.price*bilangan;
                                data3.harga = price + data3.harga;

                                data2.quantity -= bilangan;
                                fwrite(&data2,recsize,1,f2);
                                cout << "Balance of Medecine   : " <<data2.quantity<< endl;

                                break;
                                }
                            }
                    break;
                    }
                }
                if(lulus == 1)
                {
                cout <<"\nTotal Price        :RM " <<data3.harga;
                cout <<"\nCustomer's Payment :RM " ;
                cin >> data3.pay;
                cout<<"Balance               :RM" <<data3.pay-price;
                float bayaran=data3.pay-price;
                fwrite(&data3,recsize,1,f4);
                data3.harga -= data3.harga;
                cout << "\nTHANK YOU PLEASE COME AGAIN\n ";
                system("pause");
                }
                else
                {
                cout << "\t\t\t Name is Not in List. Please register first" ;
                }
                        system("cls");
                        cout<<" *******************************************************************************\n";
                        cout<<" \n\n\t\t\t            RECEIPT\n\n\n";
                        cout<<" *******************************************************************************\n";
                        cout<< "                       NAME             : "<<data3.name<<endl;
                        cout<< "                       TYPE OF MEDICINE : "<<data3.med2<<endl;
                        cout<< "                       PAYMENT          : MYR "<<data3.pay<<endl;
                        cout<< "                       BALANCE          : "<<data3.pay-price<<endl;
                        cout<<" *******************************************************************************\n";
                        cout<<"                                 tq"<<endl;
                        system ("pause");

              break;


    case 0 :
              system("cls");
              cout << "\n\n";
              cout << "\t\t         THANK YOU FOR USING THIS SYSTEM";
        Beep(1568, 200);
        Beep(1568, 200);
        Beep(1568, 200);
        Beep(1245, 1000);
        Beep(1397, 200);
        Beep(1397, 200);
        Beep(1397, 200);
        Beep(1175, 1000);
        _sleep(500);
        cout << "\n\n\n\n";
        system("pause");
        fclose(f1);
        fclose(f4);
        exit(0);
        break;
                }

            }
}

void med(void){
    system("cls");
    int c;

    cout<< "DR. ABDUL RAHMAN BIN LIMBONG"<<endl;
    cout<< "999999999999"<<endl;

    cout<<"\n\n          1 - Add MEDICINE                ";
    cout<<"\n\n          2 - List MEDICINE               ";
    cout<<"\n\n          3 - Record Payment Patient      ";
    cout<<"               \n\nChoose : ";
    cin >> c;
    switch(c){
        case 1 :    system ("cls");
                    fseek(f2,0,SEEK_END);
                    cout << "ADDING MEDICINE\n\n";
                    cout << "types of medecine       : ";
                    cin >> data2.namaubat;
                    cout << "QUANTITY                : ";
                    cin >> data2.quantity;
                    cout << "MYR  ";
                    cin >> data2.price;
                    fwrite(&data2,recsize,1,f2);
                    break;


        case 2 :
                    cout <<"ALL RECORDED MEDICINE\n\n";

                    system("cls");
                    rewind(f2);
                    while (fread(&data2,recsize,1,f2) == 1){
                    cout << "\n";
                    cout <<"\nmedicine         : " << data2.namaubat;
                    cout <<"\nquantity         : " << data2.quantity ;
                    cout <<"\nmyr              : " << data2.price;
                    }
                    cout << "\n";
                    system("pause");
                    break;

        case 3:
              system("cls");
                rewind(f4);
                cout << "=== View the Records Payment Patient ===";
                cout << "\n";
                while (fread(&data3,recsize,1,f4) == 1){
                    cout << "\n";
                    cout <<"\nName     : "<<data3.name ;
                    cout <<"\nmedicine : "<<data3.med2;
                    cout<< "\nPAYMENT  : "<<data3.pay;
                    cout <<"\nBALANCE  : "<<data3.harga;
                    cout <<"\n\n";
                }
                system("pause");
                break;

    }

}