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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question
100%

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.

Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.
 

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-

 

O VALIDATE
O RESET
e File (Ctrl+S)
Blood.cpp
Main.cpp/
1 #include <iostream>
2 using namespace std;
3 class Blood {
private:
string blood_group;
int cost;
public:
string bg;
int c;
4.
6.
7
8.
9.
10
11
//Fill your code here
12
void display(Blood obj[],int n){
//Fill your code here
cout<<Blood group with lowest cost:<<bg;
}
13
14
15
16
17
18
};
19
II
Transcribed Image Text:O VALIDATE O RESET e File (Ctrl+S) Blood.cpp Main.cpp/ 1 #include <iostream> 2 using namespace std; 3 class Blood { private: string blood_group; int cost; public: string bg; int c; 4. 6. 7 8. 9. 10 11 //Fill your code here 12 void display(Blood obj[],int n){ //Fill your code here cout<<Blood group with lowest cost:<<bg; } 13 14 15 16 17 18 }; 19 II
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning