Question #54613

Exams.cpp) Suppose a teacher weights the four
exams he gives 10%, 25%, 30%, and 35%. Write a
program that reads ten sets of four grades, prints the
weighted average of each set, and prints the unweighted
average of each test. The number of students should be
in a global constant
1

Expert's answer

2015-09-12T00:00:46-0400

Answer on Question# 54613, Programming / C++

Exams.cpp) Suppose a teacher weights the four exams he gives 10%, 25%, 30%, and 35%. Write a program that reads ten sets of four grades, prints the weighted average of each set, and prints the unweighted average of each test. The number of students should be in a global constant

Solve


#include <iostream>
#include <string>
#define NUM_STUD 2
#define NUM_EXAM 4
using namespace std;
int main()
{
    float weight[NUM_EXAM]={0.1,0.25,0.3,0.35};
    string students[NUM_STUD];
    int grades[NUM_STUD][NUM_EXAM];
    float avg[NUM_STUD]={0},avg_weight[NUM_STUD]={0};
    int i,j;
    //input
    for(i=0;i<NUM_STUD;i++)
    {
        cout << i+1 << " name: ";
        cin >> students[i];
        for(j=0;j<NUM_EXAM;j++)
        {
            cout << i+1 << " for " << j+1 << ": ";
            cin >> grades[i][j];
        }
    }
    //calculate weighted average
    for(i=0;i<NUM_STUD;i++)
    {
        for(j=0;j<NUM_EXAM;j++)
        {
            avg_weight[i] += grades[i][j] * weight[j];
        }
    }
    //calculate unweighted average
    for(i=0;i<NUM_STUD;i++)
    {
        for(j=0;j<NUM_EXAM;j++)
        {
            avg[i] += grades[i][j];
        }
        avg[i] /= NUM_EXAM;
    }
    //print results
    for(i=0;i<NUM_STUD;i++)
    {
        cout << "Student " << students[i] << " weighted average: " << avg_weight[i] << endl;
        cout << "Student " << students[i] << " unweighted average: " << avg[i] << endl;
    }
    return 0;
}


http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS