0% found this document useful (0 votes)
2 views

03_function_struct

The document outlines a lab assignment for CSC10012 focusing on functions and structures in programming. It includes tasks such as calculating time differences, adding fractions, managing student information, and handling car and player inventories with specific functionalities. Each problem requires the creation of well-defined functions and structures to achieve the desired outcomes.

Uploaded by

phuctran180406
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

03_function_struct

The document outlines a lab assignment for CSC10012 focusing on functions and structures in programming. It includes tasks such as calculating time differences, adding fractions, managing student information, and handling car and player inventories with specific functionalities. Each problem requires the creation of well-defined functions and structures to achieve the desired outcomes.

Uploaded by

phuctran180406
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSC10012

LAB 03 – FUNCTION & STRUCT


FIT-HCMUS

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)

• Year: An integer representing the year of manufacture (int yearModel)

• Cost: A floating-point number representing the cost of the car (double cost)

• Quantity: An integer representing the number of cars in stock (int quantity)

Example data:
Make Model Year Cost Quantity
Ford Taurus 1997 $21,000 10
Honda Accord 1992 $11,000 5

Write a program to manage cars, including the following functionalities.

1. Display Inventory: Print a list of all cars.

2. Add a new car.

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.

4. Remove Car: Remove a car from the inventory.

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:

• Name: A string representing the player’s name (string name)

• 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:

1. Display Players: Print a list of all players currently in the club.

2. Add Player: Add a new player to the club.

3. Remove Player: Remove a player from the club.

4. Update Player: Update a player’s statistics (goals and assists).

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.

You might also like