ABC Blood bank wanted to fix the cost for all types of Blood group according to the availability of them. They planned to fix the cost in such a way that the rarely available Bloodgroups are charged high compared to the others. Write a program to get the Blood group and the cost for all blood groups, help them to display the blood group with the lowest cost using a parameterized constructor.
ABC Blood bank wanted to fix the cost for all types of Blood group according to the availability of them. They planned to fix the cost in such a way that the rarely available Bloodgroups are charged high compared to the others. Write a program to get the Blood group and the cost for all blood groups, help them to display the blood group with the lowest cost using a parameterized constructor.
The class Blood has the following private data members.
Data Type | Variable Name |
string | blood_group |
int | cost |
Include appropriate default and parameterized constructors for the above class.
Include the following method in the Blood class
Method | Member Functions |
void display(Blood obj[], int n) | This method is used to display the details of the blood group with the lowest cost. Display the statement ‘Blood group details:’ also inside this method. |
Create a driver class called Main. In the main method, obtain input from the user in the console and display the details of the blood group with the lowest cost by calling the display method present in the Blood class.
Input and Output format:
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds to output]
Sample Input and Output 1:
Enter the Number of Blood groups:
2
Enter the Blood group:
A+
Enter the cost per unit:
150
Enter the Blood group:
B+
Enter the cost per unit:
100
Blood group details:
Blood group with lowest cost: B+
Sample Input and Output 2 :
Enter the Number of Blood groups:
5
Enter the Blood group:
AB-
Enter the cost per unit:
300
Enter the Blood group:
A-
Enter the cost per unit:
250
Enter the Blood group:
A+
Enter the cost per unit:
340
Enter the Blood group:
B+
Enter the cost per unit:
100
Enter the Blood group:
B-
Enter the cost per unit:
100
Blood group details:
Blood group with lowest cost: B+
B-
Step by step
Solved in 2 steps with 1 images