Write a C++ program to check for the not-eligible donor by throwing a custom exception. 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 Donor has the following protected variables.  Data Type Variable string name int age int weight string bloodGroup   In the Donor class, define the following function. Method Description bool validateDonor(Donor donor) This method validates donor eligibility. Validate the donor details with the following conditions. 1.Age must be greater than 30 then the donor is eligible. 2.If the age is less than 30 then throw an exception and check the weight should be greater than 44 kg in catch block, If the weight is also less than 44 then the donor is not eligible and rethrow the exception to the main method. If the weight is greater than 44 then the donor is eligible.   In the Main method, read the donor details from the user and create corresponding objects. Validate the donor to check the donor is eligible or not. Input and Output Format: Refer sample input and output for formatting specifications.  All text in bold corresponds to the input and the rest corresponds to output. Sample Input and Output 1: Enter donor details Enter the name John Enter the age 34 Enter the weight 46 Enter the blood group O+ve Donor is eligible   Sample Input and Output 2: Enter donor details Enter the name Daniel Enter the age 25 Enter the weight 50 Enter the blood group O+ve InvalidDonorException:Age is not valid Donor is eligible   Sample Input and Output 3: Enter donor details Enter the name Harry Enter the age 28 Enter the weight 42 Enter the blood group B+ve InvalidDonorException:Both age and weight is not valid Donor is not eligible   --------STRICTLY USE BELOW TEMPLATES ONLY WHILE MAKING SOLUTION-------- MAIN.CPP #include #include #include "Donor.cpp" using namespace std; int main() { //Fill your code here try { //Fill your code here } catch(const char* c) { //Fill your code here } return 0; }   DONOR.CPP #include #include using namespace std; class Donor{ protected: string name; int age; int weight; string bloodGroup; public: Donor(){} Donor(string name, int age, int weight,string bloodGroup) { this->name = name; this->age = age; this->weight = weight; this->bloodGroup = bloodGroup; } bool validateDonor(Donor donor) { //Fill your code here } };

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.2: Providing Class Conversion Capabilities
Problem 6E
icon
Related questions
Question

Write a C++ program to check for the not-eligible donor by throwing a custom exception.

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 Donor has the following protected variables. 

Data Type Variable
string name
int age
int weight
string bloodGroup

 

In the Donor class, define the following function.

Method Description
bool validateDonor(Donor donor)

This method validates donor eligibility. Validate the donor details with the following conditions.

1.Age must be greater than 30 then the donor is eligible.

2.If the age is less than 30 then throw an exception and check the weight should be greater than 44 kg in catch block,

If the weight is also less than 44 then the donor is not eligible and rethrow the exception to the main method.

If the weight is greater than 44 then the donor is eligible.

 

In the Main method, read the donor details from the user and create corresponding objects.
Validate the donor to check the donor is eligible or not.

Input and Output Format:
Refer sample input and output for formatting specifications. 
All text in bold corresponds to the input and the rest corresponds to output.


Sample Input and Output 1:

Enter donor details
Enter the name
John
Enter the age
34
Enter the weight
46
Enter the blood group
O+ve
Donor is eligible

 

Sample Input and Output 2:

Enter donor details
Enter the name
Daniel
Enter the age
25
Enter the weight
50
Enter the blood group
O+ve
InvalidDonorException:Age is not valid
Donor is eligible

 

Sample Input and Output 3:

Enter donor details
Enter the name
Harry
Enter the age
28
Enter the weight
42
Enter the blood group
B+ve
InvalidDonorException:Both age and weight is not valid
Donor is not eligible

 

--------STRICTLY USE BELOW TEMPLATES ONLY WHILE MAKING SOLUTION--------

MAIN.CPP

#include <iostream>
#include <sstream>
#include "Donor.cpp"
using namespace std;
int main()
{

//Fill your code here
try
{
//Fill your code here
}
catch(const char* c)
{
//Fill your code here
}
return 0;
}

 

DONOR.CPP

#include <iostream>
#include <sstream>
using namespace std;
class Donor{
protected:
string name;
int age;
int weight;
string bloodGroup;
public:
Donor(){}

Donor(string name, int age, int weight,string bloodGroup) {
this->name = name;
this->age = age;
this->weight = weight;
this->bloodGroup = bloodGroup;
}
bool validateDonor(Donor donor)
{
//Fill your code here
}
};
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
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