03_function_struct
03_function_struct
Part 1 – Function
Create a function or multiple functions for each problem in Lab 02 (Control Flow Statements). Structure these
functions to have a single, well-defined purpose. Avoid combining input and output operations within the same
function. Functions that compute results should return these results, which can then be printed in the main function.
Part 2 – Struct
Problem 1
Write a program that inputs two time points, each represented by hours, minutes, and seconds (integers). The
program then calculates and prints the time difference/interval between two given time points.
Problem 2
Write a program that inputs two fractions, each represented by its numerator and denominator. The program then
adds two fractions and prints the result.
Problem 3
Write a program that inputs a list of n fractions. The program then finds and prints the smallest fraction (after
simplification).
1
The following problems should be completed after you have finished
Lab 04 - Array & String
Problem 4
Write a program to manage a class list based on student information (ID, name, Math, Physics, Chemistry scores).
The program should find and print the details of the students with the highest and lowest average scores. If multiple
students share the same highest or lowest average, list all of them.
Problem 5
Assume a car is represented by the following information:
• Make: A string representing the car manufacturer (e.g., Ford, Honda) (string carMake)
• Model: A string representing the car model (e.g., Taurus, Accord) (string carModel)
• Cost: A floating-point number representing the cost of the car (double cost)
Example data:
Make Model Year Cost Quantity
Ford Taurus 1997 $21,000 10
Honda Accord 1992 $11,000 5
3. Sell Car: If the requested car is available in sufficient quantity, sell it and update the inventory. Otherwise,
inform the user that either the car is not available or there’s an insufficient quantity.
5. Track Sales: Record all sold cars. Create a function to calculate total sales for a specific month.
Problem 6
Assume a player is represented by the following information:
• Number of assists: An integer representing the number of assists the player has made (int numAssists)
• Number of goals: An integer representing the number of goals the player has scored (int numGoals)
2
Example data (Manchester City Scoring Stats - 2023-24):
Name numGoals numAssists
Erling Haaland 27 5
Phil Foden 19 8
Write a program to manage players in a football club, including the following functionalities:
5. Find Best Player: Determine the best player for the season based on a calculated score. The best player score
is calculated using the formula: best player score = 0.4 × number of assists + 0.6 × number of goals.