Complete the function blood_donor, which determines whether a person is able to donate blood. A per age is 18 or over and his/her mass ("weight") is greater than 48 kilograms. The function takes four arguments: age, which gives the prospective donor's age mass, which gives the prospective donor's mass in kilograms requested_blood_type, which gives the requested blood type donor_blood_type, which gives the prospective donor's blood type The function returns one of several strings, depending on the inputs. If the donor's eligibility is satisfied a

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section: Chapter Questions
Problem 6PP
icon
Related questions
Question
Complete the function blood_donor, which determines whether a person is able to donate blood. A person is eligible to donate blood if his/her
age is 18 or over and his/her mass ("weight") is greater than 48 kilograms.
The function takes four arguments:
• age, which gives the prospective donor's age
mass, which gives the prospective donor's mass in kilograms
requested_blood_type, which gives the requested blood type
• donor_blood_type, which gives the prospective donor's blood type
The function returns one of several strings, depending on the inputs. If the donor's eligibility is satisfied and his/her blood type matches the
requested blood type, return 'match' . Otherwise, check for ineligibility in the following order and return the first reason for ineligibility, if any:
'too young, too light' (both the age and the mass are too low)
'too young' (age is too low)
'too light' (mass is too low)
'mismatch' (requested_blood_type and donor_blood_type don't match)
Examples:
Function Call
Return Value
blood_donor (21, 50, 'A', 'A')]
blood_donor (16, 50, 'A', 'B')
blood_donor (20, 48, '0', 'A')
blood donor (17, 47, 'B', 'B')
blood_donor (21, 70, 'A', 'B') mismatch
match
too young
too light
too young, too light
1 def blood_donor (age, mass, requested_blood_type, donor_blood_type):
2
return 'Error' # DELETE THIS LINE and start coding here.
3
# Remember: end all of your functions with a return statement, not a print statement!
4
5
6 # Test cases
7 print (blood_donor (21, 50, 'A', 'A'))
8 print (blood_donor (16, 50, 'A',
9 print (blood_donor (20, 48, '0', 'A'))
10 print (blood_donor (17, 47, 'B', 'B'))
11 print (blood_donor (21, 70, 'A', 'B'))
Transcribed Image Text:Complete the function blood_donor, which determines whether a person is able to donate blood. A person is eligible to donate blood if his/her age is 18 or over and his/her mass ("weight") is greater than 48 kilograms. The function takes four arguments: • age, which gives the prospective donor's age mass, which gives the prospective donor's mass in kilograms requested_blood_type, which gives the requested blood type • donor_blood_type, which gives the prospective donor's blood type The function returns one of several strings, depending on the inputs. If the donor's eligibility is satisfied and his/her blood type matches the requested blood type, return 'match' . Otherwise, check for ineligibility in the following order and return the first reason for ineligibility, if any: 'too young, too light' (both the age and the mass are too low) 'too young' (age is too low) 'too light' (mass is too low) 'mismatch' (requested_blood_type and donor_blood_type don't match) Examples: Function Call Return Value blood_donor (21, 50, 'A', 'A')] blood_donor (16, 50, 'A', 'B') blood_donor (20, 48, '0', 'A') blood donor (17, 47, 'B', 'B') blood_donor (21, 70, 'A', 'B') mismatch match too young too light too young, too light 1 def blood_donor (age, mass, requested_blood_type, donor_blood_type): 2 return 'Error' # DELETE THIS LINE and start coding here. 3 # Remember: end all of your functions with a return statement, not a print statement! 4 5 6 # Test cases 7 print (blood_donor (21, 50, 'A', 'A')) 8 print (blood_donor (16, 50, 'A', 9 print (blood_donor (20, 48, '0', 'A')) 10 print (blood_donor (17, 47, 'B', 'B')) 11 print (blood_donor (21, 70, 'A', 'B'))
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Types of Function
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++ 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