Problem #11

Solution Source Code

Code Overview

1. Header Files and Namespace:

  • <iostream> is included for input and output operations.
  • <string> is included for potential future use (not used in this program).
  • using namespace std; allows the use of standard functions without prefixing them with std::.

2. Enumeration Definition (enPassFail)

  • Defines:
    • Pass = 1 (for an average 50 or above)
    • Fail = 2 (for an average below 50)

3. User Input Function (ReadNumbers)

  • Uses reference parameters (int &Mark1, int &Mark2, int &Mark3) to modify the values directly.
  • Prompts the user to enter three exam marks and stores them in the provided reference variables.

4. Sum Calculation Function (SumOf3Marks)

  • Takes three integer values as input.
  • Returns the sum of the three marks.

5. Average Calculation Function (CalculateAverage)

  • Calls SumOf3Marks() to compute the total sum.
  • Divides the sum by 3 to calculate the average.
  • Returns the computed average as a float.

6. Average Evaluation Function (CheckAverage)

  • Takes the computed average as input.
  • Returns:
    • enPassFail::Pass if the average is 50 or greater.
    • enPassFail::Fail if the average is below 50.

7. Output Function (PrintResults)

  • Receives the computed average as a parameter.
  • Prints "Your Average is: [Average]".
  • Calls CheckAverage() to determine whether the student has passed or failed.
  • Prints "You Passed" if the student qualifies, otherwise prints "You Failed".

8. Program Execution (main())

  • Declares three integer variables (Mark1, Mark2, Mark3).
  • Calls ReadNumbers() to get user input.
  • Calls CalculateAverage() to compute the average.
  • Calls PrintResults() to display the average and pass/fail result.
  • Returns 0 to indicate successful execution.

This structured explanation ensures clarity and ease of understanding.

Complete and Continue  
Discussion

0 comments