How to Calculate a Student's Total Course Percentage in C++?

In summary, the program is designed to calculate a student's total course percentage based on scores from three different weighted components, homework, midterm exam, and final exam. The suggested steps to complete the program include running it, fixing the midterm calculation, and then fixing the final exam calculation. The program can also be modified to include a quiz score with new weights for each component. To simplify the code, it is recommended to introduce variables for each component and then combine them with their respective weights to calculate the overall course percentage.
  • #1
ineedhelpnow
651
0
The following incomplete program should compute a student's total course percentage based on scores on three items of different weights (%s):
20% Homeworks (out of 80 points)
30% Midterm exam (out of 40 points)
50% Final exam (out of 70 points)


Suggested (incremental) steps to finish the program:
1. First run it.
2. Next, complete the midterm exam calculation and run the program again. Use the constant variables where appropriate.
3. Then, complete the final exam calculation and run the program. Use the constant variables where appropriate.
4. Modify the program to include a quiz score out of 20 points. New weights: 10% homework, 15% quizzes, 30% midterm, 45% final. Run the program again.
5. To avoid having one large expression, introduce variables homeworkPart, quizPart, midtermPart, and finalPart. Compute each part first; each will be a number between 0 and 1. Then combine the parts using the weights into the course value. Run the program again.

Code:
#include <iostream>
using namespace std;

int main() {
   const double HOMEWORK_MAX = 80.0;
   const double MIDTERM_MAX  = 40.0;
   const double FINAL_MAX    = 70.0;
   const double HOMEWORK_WEIGHT = 0.20; // 20%
   const double MIDTERM_WEIGHT  = 0.30;
   const double FINAL_WEIGHT    = 0.50;

   double homeworkScore    = 0.0;
   double midtermScore     = 0.0;
   double finalScore       = 0.0;
   double coursePercentage = 0.0;

   cout << "Enter homework score:" << endl;
   cin  >> homeworkScore;

   cout << "Enter midterm exam score:" << endl;
   cin  >> midtermScore;

   cout << "Enter final exam score: " << endl;
   cin  >> finalScore;

   coursePercentage = ((homeworkScore / HOMEWORK_MAX) * HOMEWORK_WEIGHT)
                    + 0.0  // FIXME for midterm
                    + 0.0; // FIXME for final 
   coursePercentage = coursePercentage * 100; // Convert fraction to %

   cout << endl << "Your course percentage (FIXME): ";
   cout << coursePercentage << endl;

   return 0;
}

i don't understand this question at all! please help!
 
Last edited:
Technology news on Phys.org
  • #2
Were you able to run the program?
 
  • #3
Yes
 
  • #4
Ok, were you able to do the second step, and fix the midterm calculation? (Hint: It's the part in the code that has the first FIXME).
 
  • #5


I can provide a response to the steps given to complete the program for computing a student's total course percentage. The program is written in C++ and it involves calculating the percentage based on scores on three items with different weights: homeworks, midterm exam, and final exam.

Step 1: Running the Incomplete Program
The first step is to run the incomplete program as it is to see how it works and what output it provides. This will give us a better understanding of the program and what needs to be completed.

Step 2: Completing the Midterm Exam Calculation
The second step is to complete the calculation for the midterm exam. This involves using the constant variables for the maximum score and weight, and then calculating the percentage based on the student's score. After completing this step, we can run the program again to see the updated output.

Step 3: Completing the Final Exam Calculation
The third step is to complete the calculation for the final exam. Similar to the previous step, we will use the constant variables for the maximum score and weight, and then calculate the percentage based on the student's score. After completing this step, we can run the program again to see the final output.

Step 4: Modifying the Program to Include Quiz Score
The fourth step is to modify the program to include a quiz score out of 20 points. This will involve changing the weights for each item to 10% for homeworks, 15% for quizzes, 30% for midterm exam, and 45% for final exam. After making these changes, we can run the program again to see the updated output.

Step 5: Introducing Variables to Simplify the Calculation
The final step is to introduce variables for each part of the course (homework, quiz, midterm, and final) and compute them separately. This will help avoid having one large expression and make the calculation easier to understand. After computing each part, we can combine them using the weights to get the final course percentage. Running the program again will give us the final output.

In conclusion, by following these suggested steps, we can successfully complete the program and compute a student's total course percentage based on their scores on different items with different weights. This can be a useful tool for both students and teachers to keep track of academic performance.
 

Related to How to Calculate a Student's Total Course Percentage in C++?

1. What is a C++ function?

A C++ function is a block of code that performs a specific task and can be called from other parts of a program. It can take in parameters, perform operations, and return a value.

2. How do I declare a function in C++?

To declare a function in C++, you need to specify the return type, function name, and any parameters it takes in. For example: int calculateGrade(int grade1, int grade2, int grade3);

3. Can a C++ function have multiple return statements?

Yes, a C++ function can have multiple return statements. However, only one of them will be executed based on the condition specified in the function. Once a return statement is executed, the function will stop running and return the value specified.

4. How do I call a function in C++?

To call a function in C++, you need to use the function name followed by parentheses and any necessary arguments. For example: int result = calculateGrade(90, 85, 95); This will call the calculateGrade function and pass in the arguments 90, 85, and 95.

5. How can I use functions to calculate grades in C++?

To calculate grades in C++ using functions, you can create a function that takes in the necessary parameters (such as test scores) and calculates the grade based on a specific formula. You can then call this function whenever you need to calculate a grade and use the returned value in your program.

Similar threads

  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
17
Views
1K
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
7
Views
3K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
2
Replies
49
Views
10K
Back
Top