Homework 4: Functions

Thursday, July 19, 2012     


[Previous Homework] [Next Homework]


Complete the following:

  1. Create a new file called hw04.c
  2. Create a program that contains the following functions:
    • A function called "calc_grade" that
      • Accepts four doubles representing the average of classwork for a student, the average of homework for a student, the average of quizzes for a student, and the final test grade for a student (all values are between 0 and 100)
      • Calculates the student's class grade if classwork is worth 16% of their class grade, homework is worth 24% of their class grade, quizzes are worth 30% of their class grade, and the final is worth 30% of their grade
    • A function called "display_grade" that
      • Accepts a single double
      • Prints "CLASS GRADE IS: " followed by the class grade for the student
  3. Write main so that it will call whichever functions are necessary to:
    1. Ask the user for the classwork, homework, quiz, and final averages for a student
    2. Get the values from the user
    3. Calculate the class grade based on supplied input
    4. Display the class grade based on supplied input
    5. Get input and calculate the class grades for three students without running the program multiple times
    6. It is recommended you write your own function(s) to minimize writing the same code multiple times
  4. Example of expected output:

    linux3[1]% ./hw04
    Please input classwork total (0-100): 50
    Please input homework total (0-100): 50
    Please input quiz total (0-100): 80
    Please input final exam total (0-100): 90
    CLASS GRADE IS: 71.000000
    Please input classwork total (0-100): 85
    Please input homework total (0-100): 85
    Please input quiz total (0-100): 90
    Please input final exam total (0-100): 95
    CLASS GRADE IS: 89.500000
    Please input classwork total (0-100): 95
    Please input homework total (0-100): 100
    Please input quiz total (0-100): 80
    Please input final exam total (0-100): 92
    CLASS GRADE IS: 90.800000
    linux3[2]%
    

  5. Create a script of you compiling and then running your program once (running multiple times is not required)
  6. Once you are done, use submit to submit two files, hw04.c and typescript

    linux3[1]% submit cs104 hw04 hw04.c typescript