Average Calculator
A function made to calculate Student's average and log his modules info to his file
1. average()
function:
average()
function:1.1 Description:
This function calculates the average by dividing the total value by the count value. If the count is zero, the function returns 0.0 to avoid division by zero errors.
1.2 Syntax:
Short Form:
Full Form:
1.3 Parameters:
1.4 Return Value:
The function returns the calculated average as a float
value.
1.5 Usage:
This function is typically used in scenarios where you need to calculate an average, such as in the calculateAverage()
function.
2. calculateAverage()
function:
calculateAverage()
function:2.1 Description:
This function allows the user to calculate the average score for a student and gather module information. It prompts the user for the student's first name, last name, and the number of modules. Then, it prompts the user to enter the name, coefficient, and score for each module. The function calculates the average score and writes the module information and average to the student's file.
2.2 Syntax:
Short Form
Full Form
2.3 Function Tasks:
Prompt the user to enter the student's first name and last name.
Create a file path using the student's name by calling the
findStudent()
function.Open the file for reading and writing.
If the file path is
NULL
, display an error message and return from the function.If the file cannot be opened, display an error message and return from the function.
Prompt the user to enter the number of modules.
Iterate over the number of modules and for each module:
Prompt the user to enter the module name.
Prompt the user to enter the coefficient for the module.
Prompt the user to enter the score for the module.
Calculate the total and coefficient sum for the average calculation.
Write the module information to the file.
Calculate the average score by calling the
average()
function with the total and coefficient sum.Write the average score to the file.
Close the file.
Display the calculated average score and success message to the user.
Refresh the screen.
Please note that the explanations in the Return Value section of average()
and the Function Tasks section of calculateAverage()
are placeholders and should be replaced with the actual information about the return value and function tasks, respectively.
Last updated