Using user define functions C++ Program to take a value from the to take a value from the user as input marks of five subjects Physics, Chemistry, Biology, Mathematics, and Computer. Calculate percentage and grade according to the following: Percentage >= 90% : Grade A, Percentage >= 80% : Grade B, Percentage >= 70% : Grade C, Percentage >= 60% : Grade D, Percentage >= 40% : Grade E, Percentage < 40% : Grade F, Write this program with the help of  user define functions. Grade and Percentage Program

Explanation:

  1. Pass-by-Value (calculatePercentageByValue and determineGradeByValue):
    • Function calculatePercentageByValue:
      • Takes individual subject marks as parameters.
      • Calculates the total marks and percentage.
      • Returns the percentage.
    • Function determineGradeByValue:
      • Takes the calculated percentage as a parameter.
      • Determines the grade based on the percentage and returns it.
  2. Pass-by-Reference (calculatePercentageByReference and determineGradeByReference):
    • Function calculatePercentageByReference:
      • Takes individual subject marks as parameters and a reference to a float for the percentage.
      • Calculates the total marks and percentage and updates the reference variable.
    • Function determineGradeByReference:
      • Takes the calculated percentage and a reference to a char for the grade.
      • Determines the grade based on the percentage and updates the reference variable.
  3. Main Function (main):
    • Prompts the user to input marks for the five subjects.
    • Uses both pass-by-value and pass-by-reference methods to calculate the percentage and determine the grade.
    • Displays the results.

Example Outputs:

Example 1:

Input:

  • Physics: 85
  • Chemistry: 90
  • Biology: 80
  • Mathematics: 88
  • Computer: 92

Output:

Example 2:

Input:

  • Physics: 50
  • Chemistry: 60
  • Biology: 55
  • Mathematics: 70
  • Computer: 65

Output: