Simple Blood Donation System using C++

Simple Blood Donation System using C++ (With Source Code)

Simple Blood Donation System using C++ (With Source Code)

Hello, coders. Welcome to the codewithrandom blog. In this article, we will learn how to create a Simple  Blood Donation System using C++ (With Source Code).

A Simple Blood Donation System is a console-based software application that enables admins to view blood group quantities, donors to donate blood and show their information, and patients to seek for and get appropriate blood. This system is easy to create and has a basic interface. This project stores the availability of the blood groups and checks for compatibility when required by the patient. This system is convenient to use and saves the data temporarily in an efficient manner.

Simple Blood Donation System using C++

In this project, we will use the concept of classes (Object-oriented programming) in C++. The system does not use any external files to permanently store the data. Simple Blood Donation System is created utilizing the C++ Programming Language, as well as various variables and strings.

Prison Management System using C++ (With Source Code)

Functionality of the system:

In terms of the Simple Blood Bank Management System’s functionality, a user may be a donor or a patient and they can quickly and easily add their information.

  • To add a donor’s information, the user must provide the donor’s name, gender, date of birth, blood group, number of packets for blood donation. After inputting donor information, the user may examine the whole donor list, which includes all of the given information.
  • To add patient’s information, the user must provide the patient’s name, blood group they are looking for. The available compatible blood groups with the the entered blood group will be displayed. They will receive 1 packet of blood and for more they will need to login again.

Features of the system:

  1. Add Donors Information
  2. Add Patient’s information
  3. Checking of blood availability and compatibility
  4. Exit from the program

Overview of the UI:

  • Enter 1 if you are the admin
    2 if you are a donor
    3 if you are a patient
    4 if you want to exit:”;
     
On selecting option 2 : The user will enter the donor information
  • welcome donor!!!
                    Please enter 1 if you want to enter your information:

On selecting option 3: The user will enter the patients information

  • Welcome patient!!!
     

Simple Blood Donation System using C++Source code:

You can directly use this code by copying it in your IDE to understand the working and then can create it by understanding the project.

//IMPLEMENTATION OF BLOOD MANAGEMENT SYSTEM WITHIN A SMALL AREA

#include <iostream>
#include<string.h>
using namespace std;
class blood_bank
{
public:
    static int bloodgroup[8];
    
};
int blood_bank::bloodgroup[]={0,0,0,0,0,0,0,0};

class admin
{
    
public:
    
    void display();
    
    admin()
    {
        char s[20]="suraj";
        char str[20];
        cout<<"Enter password:";
        cin>>str;
        if(  strcmp(s,str)==0)
        {cout<<"welcome!!!"<<endl;
            display();}
        else
            cout<<"Please contact Suraj to become an admin"<<endl;
        
    }
};
// A, O+, B+, AB+, A-, O-, B-, AB-

void admin::display()
{
    cout<<"A +ve:"<<blood_bank::bloodgroup[0]<<endl;
    cout<<"O +ve:"<<blood_bank::bloodgroup[1]<<endl;
    cout<<"B +ve:"<<blood_bank::bloodgroup[2]<<endl;
    cout<<"AB +ve:"<<blood_bank::bloodgroup[3]<<endl;
    
    cout<<"A -ve:"<<blood_bank::bloodgroup[4]<<endl;
    cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
    cout<<"B -ve:"<<blood_bank::bloodgroup[6]<<endl;
    cout<<"AB -ve:"<<blood_bank::bloodgroup[7]<<endl;
}

class patient
{
    char name[50];
    char blood_group[20];
    
    
public:
    
    int save();
    void show(int);
    
};
// A+, O+, B+, AB+, A-, O-, B-, AB-

int patient::save()
{
    int c,n;
    
    cout<<"Enter your name:";
    cin>>name;
    
    cout<<"Enter type of blood group you are looking for:"<<endl;
    
    cout<<"0 = A positive"<<endl<<"1 = O positive"<<endl<<"2 = B positive"<<endl<<
    "3 = AB positive"<<endl<<"4 = A negative"<<endl<<"5 = O negative"<<endl<<
    "6 = B negative"<<endl<<"7 = AB negative"<<endl;
    
    
    cin>>c;
    
    cout<<"you will be donated with 1 blood packet"<<endl<<"Please login again to get 1 more blood packet"<<endl;
    
    show(c);
}

void patient::show(int c)
{
    cout<<"Available blood groups compatible with the entered blood group:"<<endl;
    if(c==0)
    {
        cout<<"A +ve:"<<blood_bank::bloodgroup[0]<<endl;
        cout<<"A -ve:"<<blood_bank::bloodgroup[4]<<endl;
        cout<<"O +ve:"<<blood_bank::bloodgroup[1]<<endl;
        cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
        
        if(blood_bank::bloodgroup[0]>0)
            blood_bank::bloodgroup[0]--;
        else if(blood_bank::bloodgroup[4]>0)
            blood_bank::bloodgroup[4]--;
        else if(blood_bank::bloodgroup[1]>0)
            blood_bank::bloodgroup[2]--;
        else if(blood_bank::bloodgroup[5]>0)
            blood_bank::bloodgroup[6]--;
        else
            cout<<"Compatible blood group not available";
        
    }
    
    else if(c==1)
    {
        cout<<"O +ve:"<<blood_bank::bloodgroup[1]<<endl;
        cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
        
        
        if(blood_bank::bloodgroup[1]>0)
            blood_bank::bloodgroup[1]--;
        else if(blood_bank::bloodgroup[5]>0)
            blood_bank::bloodgroup[5]--;
        else
            cout<<"Compatible blood group not available";
        
        
    }
    
    else if (c==2)
    {
        cout<<"B +ve:"<<blood_bank::bloodgroup[2]<<endl;
        cout<<"B -ve:"<<blood_bank::bloodgroup[6]<<endl;
        cout<<"O +ve:"<<blood_bank::bloodgroup[1]<<endl;
        cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
        
        if(blood_bank::bloodgroup[2]>0)
            blood_bank::bloodgroup[2]--;
        else if(blood_bank::bloodgroup[6]>0)
            blood_bank::bloodgroup[6]--;
        
        else if(blood_bank::bloodgroup[1]>0)
            blood_bank::bloodgroup[1]--;
        else if(blood_bank::bloodgroup[5]>0)
            blood_bank::bloodgroup[5]--;
        else
            cout<<"Compatible blood group not available";
        
    }
    
    else if (c==3)
    {
        cout<<"A +ve:"<<blood_bank::bloodgroup[0]<<endl;
        cout<<"A -ve:"<<blood_bank::bloodgroup[4]<<endl;
        cout<<"B +ve:"<<blood_bank::bloodgroup[2]<<endl;
        cout<<"B -ve:"<<blood_bank::bloodgroup[6]<<endl;
        cout<<"AB +ve:"<<blood_bank::bloodgroup[3]<<endl;
        cout<<"AB -ve:"<<blood_bank::bloodgroup[7]<<endl;
        cout<<"O +ve:"<<blood_bank::bloodgroup[1]<<endl;
        cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
        
        if(blood_bank::bloodgroup[0]>0)
            blood_bank::bloodgroup[0]--;
        else if(blood_bank::bloodgroup[4]>0)
            blood_bank::bloodgroup[4]--;
        else if(blood_bank::bloodgroup[2]>0)
            blood_bank::bloodgroup[2]--;
        else if(blood_bank::bloodgroup[6]>0)
            blood_bank::bloodgroup[6]--;
        else if(blood_bank::bloodgroup[3]>0)
            blood_bank::bloodgroup[3]--;
        else if(blood_bank::bloodgroup[7]>0)
            blood_bank::bloodgroup[7]--;
        else if(blood_bank::bloodgroup[1]>0)
            blood_bank::bloodgroup[1]--;
        else if(blood_bank::bloodgroup[5]>0)
            blood_bank::bloodgroup[5]--;
        else
            cout<<"Compatible blood group not available";
        
        
    }
    else if (c==4)
    {
        cout<<"A -ve:"<<blood_bank::bloodgroup[4]<<endl;
        cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
        
        if(blood_bank::bloodgroup[4]>0)
            blood_bank::bloodgroup[4]--;
        
        else if(blood_bank::bloodgroup[5]>0)
            blood_bank::bloodgroup[5]--;
        
        else
            cout<<"Compatible blood group not available";
        
    }
    
    else if (c==5)
    {
        cout<<"B -ve:"<<blood_bank::bloodgroup[6]<<endl;
        cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
        
        if(blood_bank::bloodgroup[6]>0)
            blood_bank::bloodgroup[6]--;
        else if(blood_bank::bloodgroup[5]>0)
            blood_bank::bloodgroup[5]--;
        else
            cout<<"Compatible blood group not available";
        
        
    }
    
    else if (c==6)
    {
        cout<<"A +ve:"<<blood_bank::bloodgroup[0]<<endl;
        cout<<"A -ve:"<<blood_bank::bloodgroup[4]<<endl;
        cout<<"B +ve:"<<blood_bank::bloodgroup[2]<<endl;
        cout<<"B -ve:"<<blood_bank::bloodgroup[6]<<endl;
        cout<<"AB +ve:"<<blood_bank::bloodgroup[3]<<endl;
        cout<<"AB -ve:"<<blood_bank::bloodgroup[7]<<endl;
        cout<<"O +ve:"<<blood_bank::bloodgroup[1]<<endl;
        cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
        
        
        if(blood_bank::bloodgroup[0]>0)
            blood_bank::bloodgroup[0]--;
        else if(blood_bank::bloodgroup[4]>0)
            blood_bank::bloodgroup[4]--;
        else if(blood_bank::bloodgroup[2]>0)
            blood_bank::bloodgroup[2]--;
        else if(blood_bank::bloodgroup[6]>0)
            blood_bank::bloodgroup[6]--;
        else if(blood_bank::bloodgroup[3]>0)
            blood_bank::bloodgroup[3]--;
        else if(blood_bank::bloodgroup[7]!=0)
            blood_bank::bloodgroup[7]--;
        else if(blood_bank::bloodgroup[1]>0)
            blood_bank::bloodgroup[1]--;
        else if(blood_bank::bloodgroup[5]>0)
            blood_bank::bloodgroup[5]--;
        else
            cout<<"Compatible blood group not available";
        
    }
    
    else if(c==7)
    {
        cout<<"A -ve:"<<blood_bank::bloodgroup[4]<<endl;
        cout<<"B -ve:"<<blood_bank::bloodgroup[6]<<endl;
        cout<<"O -ve:"<<blood_bank::bloodgroup[5]<<endl;
        cout<<"AB -ve:"<<blood_bank::bloodgroup[7]<<endl;
        
        
        if(blood_bank::bloodgroup[4]>0)
            blood_bank::bloodgroup[4]--;
        
        else if(blood_bank::bloodgroup[6]>0)
            blood_bank::bloodgroup[6]--;
        
        else if(blood_bank::bloodgroup[5]>0)
            blood_bank::bloodgroup[5]--;
        
        else if(blood_bank::bloodgroup[7]>0)
            blood_bank::bloodgroup[7]--;
        else
            cout<<"Compatible blood group not available";
        
        
    }
    
    
}

class donor
{
    char name[50];
    char sex[15];
    
    struct date
    {
        int day;
        int month;
        int year;
    }date;
    
    char blood_group[20];
    //DONOR DETAILS
    int phone_no[15];
public:
    
    int save();
    int display();
    
    int x,c;
    
    
};


int donor::save()
{
    cout<<"Enter your name:";
    cin>>name;
    
    cout<<"Enter your sex:";
    cin>>sex;
    
    cout<<"Enter date(DD MM YY):";
    cin>>date.day;
    cin>>date.month;
    cin>>date.year;
    
    
    // A, O+, B+, AB+, A-, O-, B-, AB-
    
    cout<<"Enter type of blood group you are donating:"<<endl;
    
    cout<<"0 = A positive"<<endl<<"1 = O positive"<<endl<<"2 = B positive"<<endl<<
    "3 = AB positive"<<endl<<"4 = A negative"<<endl<<"5 = O negative"<<endl<<
    "6 = B negative"<<endl<<"7 = AB negative"<<endl;
    
    cin>>c;
    
    cout<<"how many packets of blood are you donating:";
    cin>>x;
    
    blood_bank::bloodgroup[c]+=x;
    char ch;
    cout<<"Do you want your information to be displayed now(Y/N)";
    cin>>ch;
    
    if(ch=='Y'||ch=='y')
        donor::display();
    
}


int donor::display()
{
    cout<<"name:";
    cout<<name<<endl;
    
    cout<<"Date(DD MM YY):";
    cout<<date.day<<" ";
    cout<<date.month<<" ";
    cout<<date.year<<endl;
    
    cout<<"Blood group:";
    
    switch(c)
    {
            // A, O+, B+, AB+, A-, O-, B-, AB-
        case 0:
            cout<<"0 = A positive"<<endl;
            break;
        case 1:
            cout<<"1 = O positive"<<endl;
            break;
        case 2:
            cout<<"2 = B positive"<<endl;
            break;
        case 3:
            cout<<"3 = AB positive"<<endl;
            break;
        case 4:
            cout<<"4 = A negative"<<endl;
            break;
        case 5:
            cout<<"5 = O negative"<<endl;
            break;
        case 6:
            cout<<"6 = B negative"<<endl;
            break;
        case 7:
            cout<<"7 = AB negative"<<endl;
    }
    
    cout<<"Packets of blood:"<<x<<endl;
    
}

int main()
{
    int i=0,j=0;
    donor a[100];
    patient b[50];
    
    int c=0;
    
    while(c!=4)
    {
        
        
        cout<<"Enter 1 if you are the admin , \n 2 if you are a donor ,\n 3 if you are a patient or \n 4 if you want to exit:";
        cin>>c;
        switch(c)
        {
                
                
            case 4:
                break;
                
            case 1:
            {
                admin t;
                char c;
                break;
            }
                
            case 2:
            {
                int k;
                static int i=0;
                cout<<"welcome donor!!!"<<endl;
                cout<<"Please enter 1 if you want to enter your information:";
                cin>>k;
                if(k==1)
                    a[i++].save();
                else if (k==2)
                    a[i].display();
                
                break;
            }
                
            case 3:
            {
                static int i=0;
                cout<<"Welcome patient!!!"<<endl;
                b[i++].save();
                break;
            }
        }
    }
    return 0;
}

Now let us understand the code:-

  • We will start by writing the header of the code with the required libraries – iostream  (input and output stream), string.h (string manipulation).
  • Now we will create a class called blood_bank which will have a public static integer type of array called bloodgroup[8]. It indicates the amount of blood available for certain blood groups.
  • We will create a class called admin, which will represent an administrator of the blood management system. We will declare a display function and a constructor. The constructor will ask the user to enter a password and grants access if the correct password is provided.
  • The display function will be defined outside the class using a scope resolution operator. It will display the available quantity of blood for each blood group. The available blood groups in this system are as follows – A +ve, O +ve, B +ve, AB +ve, A -ve, O -ve, B -ve, AB -ve.
  • Now we will create a class called patient which will store all the details of the patient. It will contain private member variables name and blood-group. The public member functions – save() and show() created, will be defined outside the class using a scope resolution operator.
  • The save() function asks the patient to enter their name and the type of blood group they are looking for.
  • The show() function will be used to present the compatible blood groups with the inputted blood group and decreases the quantity of the relevant blood group by 1. We will use if else if control statement to check compatibility.
  • Creating another class called donor which will store all the information related to the blood donor in the system. It will have private member variables – name, sex, blood_group, phone_no. We will create a structure called date for date information and it will have variables – day, month and year. Creating public member functions – save() and diplay().
  • Defining functions outside the class using scope resolution operator.
  • The save() function will ask the donor to provide their personal information, such as their name, gender, date of donation, and blood group. It also asks how many blood packets they are donating and increases the quantity of the respective blood group by the number of packets entered.
  • The display() function will display the donor’s information. And it uses switch case statements for the blood group selection.
  • The main() function will begin the program. We will first create arrays of objects of the donor and patient classes. Then we will create the menu of options to be displayed when the program begins. The selection of options will be done using a switch case. The corresponding functions will be called according to the selection made by the user to perform an operation.
  • Option 1 – The system will ask for a password to access the admin portal.
  • Option 2 – The system will ask the donor to enter their information and save it. It will also provides an option to display the donor’s information.
  • Option 3 – The system will ask the patient to give their name and the blood group they seek. It displays the compatible blood groups that are available and decreases the quantity of the relevant blood type by one.
  • Option 4 – Program will exit.
  • This sums up our project of Blood Donation System using C++ (With Source Code).

Canteen Management System using C++ (With Source Code)

Final Output:-

Here is an example to show how this project works.

Simple Blood Donation System using C++

Selecting option 2:

Simple Blood Donation System using C++Simple Blood Donation System using C++

Simple Blood Donation System using C++

Simple Blood Donation System using C++

Selecting option 3:

Simple Blood Donation System using C++

Conclusion

We have reached the end of this article and have a lot more projects in C++ coming so stay tuned. We have started with awesome and fun projects for you all to understand C++. Learning C++ by creating fun projects makes learning easy and interesting.

If you enjoyed the article and learned something new today, let us know in the comments.

Thank you.

Happy Reading! 🙂

Follow: CodeWithRandom

FAQ on Simple Blood Donation System Using C++

What is a Blood Donation System?

A blood donation system is a console-based piece of software that is used to handle all the data related to blood donation. In the blood donation system, we keep track of the availability of blood from different groups and also manage the data of the donors, so in the future, if they require blood, they can contact the hospital and get the blood.

ADVERTISEMENT

What are the features of the blood donation system?

1. Add Donors Information
2. Add Patient’s information
3. Checking of blood availability and compatibility
4. Exit from the program

ADVERTISEMENT



Leave a Reply