CMSC104 Spring 2014
Programming Project 1
Grade Calculator
Out: Wednesday, March 12
Due: Tuesday, March 25, before 11:59 p.m.
The Objective
This project is designed to give you practice writing a C program on your own.
The Task
- Your job is to write a grade calculating program for CMSC104.
In addition to printing the average, you should also determine the letter grade
that corresponds to the numerical average based on the following scale:
90% <= A <= 100% 80% <= B < 90% 70% <= C < 80% 60% <= D < 70% 0% <= F < 60%
- When figuring the letter grade, give the next highest grade if the decimal portion is .5 or above. For example, an average of 89.51 is an A.
- Print the average to two decimal places. We will discuss how to print a specific number of decimal places in class.
- Use
scanf()
to get the user's input and read it into type "int" variables; remember the proper format string for doing that. Don't forget the '&' (ampersand) before the variable arguments in the call toscanf()
. - The file must be named
proj1.c
Tips and Hints
- Make sure you create the file in the correct directory. You should cd into your cs104/proj1 directory before you create the file.
- Make sure your indentation and your opening and closing curly-braces match up.
- Work incrementally. It is much easier to debug 3-4 lines than it is to debug 40-50 lines. After each increment, make sure the program compiles without errors and runs.
- Start with the basic elements of every C program: the #include, main(), etc.
- Add the variable declarations.
- Start adding the rest of the code, only doing 2-4 lines at a time. You might want to prompt the user for the first variable and then display the value with printf() to make sure you read it in correctly.
- You should test your program with other sets of numbers to make sure you get the correct average for multiple sets of input.
Sample Output
linux2[14]% gcc -ansi -Wall proj1.c linux2[15]% ./a.out Welcome to the CMSC104 grade calculation program. This program will calculate the final average and course grade for a student in CMSC104. Each homework is worth 4%, each project is worth 10%, each mid-term exam is worth 15%, and the final exam is worth 20%. Enter the homework 1 score: 67 Enter the homework 2 score: 78 Enter the homework 3 score: 88 Enter the homework 4 score: 85 Enter the homework 5 score: 90 Enter the project 1 score: 76 Enter the project 2 score: 82 Enter the project 3 score: 84 Enter the mid-term exam 1 score: 80 Enter the mid-term exam 2 score: 75 Enter the final exam score: 90 With an average of 81.77, your course grade is B. Thank you for using the grade calculator. linux2[16]% ./a.out Welcome to the CMSC104 grade calculation program. This program will calculate the final average and course grade for a student in CMSC104. Each homework is worth 4%, each project is worth 10%, each mid-term exam is worth 15%, and the final exam is worth 20%. Enter the homework 1 score: 95 Enter the homework 2 score: 92 Enter the homework 3 score: 0 Enter the homework 4 score: 84 Enter the homework 5 score: 90 Enter the project 1 score: 75 Enter the project 2 score: 95 Enter the project 3 score: 90 Enter the mid-term exam 1 score: 70 Enter the mid-term exam 2 score: 85 Enter the final exam score: 90 With an average of 81.69, your course grade is B. Thank you for using the grade calculator. linux2[17]%
Submitting the Program
For this assignment, you just submit your source code file, proj1.c
(make sure you use this name). To submit your project, type the following at the
Unix prompt: