▾ Part 2: Course Registration The time has come to register for courses at Stony Brook University. Complete the function register, which takes three arguments: a dictionary that maps a course's name to its number of credits (course_credits); a list of courses a student wants to take (courses); and a maximum number of credits the student is willing to take (max_credits). The function iterates over the courses list and attempts to register the student for each course, in sequence (use a for-loop, not a while-loop). "Registering" for a course means to add the number of credits of a course to a running total. If registering for a course would bring the total number of credits over max_credits, skip that course and continue on to the next one in the courses list. The function returns the total number of credits the students successfully registered for. Example #1: register ({'MAT 131': 4, 'PHY 131': 3, 'AST 200': 1, 'WRT 102": 3, "PHY 133': 1}, ['MAT 131', 'WRT 102'], 12)) Return value: 7 Example #2: register ({'MAT 131': 4. 'PHY 131': 3, 'WRT 102': 3, 'PHY 133': 1, 'AST 203": 4}. ['MAT 131', 'WRT 102'. 'PHY 131', 'PHY 133'], 9) Return value: 8
▾ Part 2: Course Registration The time has come to register for courses at Stony Brook University. Complete the function register, which takes three arguments: a dictionary that maps a course's name to its number of credits (course_credits); a list of courses a student wants to take (courses); and a maximum number of credits the student is willing to take (max_credits). The function iterates over the courses list and attempts to register the student for each course, in sequence (use a for-loop, not a while-loop). "Registering" for a course means to add the number of credits of a course to a running total. If registering for a course would bring the total number of credits over max_credits, skip that course and continue on to the next one in the courses list. The function returns the total number of credits the students successfully registered for. Example #1: register ({'MAT 131': 4, 'PHY 131': 3, 'AST 200': 1, 'WRT 102": 3, "PHY 133': 1}, ['MAT 131', 'WRT 102'], 12)) Return value: 7 Example #2: register ({'MAT 131': 4. 'PHY 131': 3, 'WRT 102': 3, 'PHY 133': 1, 'AST 203": 4}. ['MAT 131', 'WRT 102'. 'PHY 131', 'PHY 133'], 9) Return value: 8
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images
Knowledge Booster
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.Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr