Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Key Concept: Functions, Arrays, Objects and Classes Computing grades can be a te

ID: 3718196 • Letter: K

Question

Key Concept: Functions, Arrays, Objects and Classes

Computing grades can be a tedious task. For this lab, you will generate code that will compute a student’s grade for a class. You will create several functions to help you compute a student’s final grade. For this Lab, we will read in the scores from an input file. Use the previous lab as your base and convert out

We will restrict the types of grades to six:

Homework

Quiz

Lab

Project

Exam

Final Exam

Part I: Create Score Class

Write a new class for the Score. The Score should store the following:

Score

Max points for assignment

Grade type

Part II: Input Function

Write a function that will read in the data from a text file to store in the array of Scores. This function will have four parameters passed by reference:

Array of Scores

Size of the arrays

Part III: Average Function

Write a function that will compute the average of a specific grade type. This function will have four parameters passed by value and return the average.

Array of Scores

Size of the arrays

Part IV: Calculate Final Grade Function

Write a function that will compute the student’s final grade based on the grade type averages and their weight (you can define these in the main) towards the final grade. The input parameters will be up to you determine/customize. Just make sure the function returns the final grade (numerical).

Part V: Output Final Grade Function

Write a function that will output the numeric and letter grade for the student.

*Need one sample run using the numbers below*

Explanation / Answer

#include <iostream>
#include <fstream>

using namespace std;


// Creating Score Class
class Score{
   public:
       float score;
       int gradeType;
       float maxScore;
};


// read data from file in score, grade, max_score format
void inputData(Score score[], int &size){
  
   std::ifstream infile("thefile.txt");
   float s, m;
   int g;
   int index = 0;
   while (infile >> s >> g >> m)
   {
   Score s;
       s.score = s;
       s.gradeType = g;
       s.maxScore = m;
       score[index] = s;
       index++;
   }
}

// Calculate average score of a specific type of grade
float averageOfGrade(Score score[], int size, int gradeType){
   float sum = 0;
   int count = 0;
  
   for(int i=0; i< size; i++){
       Score s = score[index];
       if(s.gradeType == gradeType){
           sum += s.score;
           count++;
       }
   }
  
   return (float)(sum)/count;
}

// Calcuate final score based on weights to each gradetype
float finalGrade(Score score[], int scoreSize, int grades[], float weights[], int sizeGrades){
  
   float sumEachGrade[sizeGrades];
   int countEachGrade[sizeGrades];
  
   for(int i=0; i< sizeGrades; i++){
       sumEachGrade[i] = 0.0;
       countEachGrade[i] = 0;
   }
  
  
   for(int i=0; i< sizeGrades; i++){
      
       for(int j=0; j<scoreSize; j++){
           Score s = score[j];
          
           if(s.gradeType == grades[i]){
               sumEachGrade[i] += sumEachGrade[i] + s.score;
               countEachGrade[i] += 1;
           }
       }
   }
  
   float final_grade = 0.0;
  
   for(int i=0; i< sizeGrades; i++){
      
       final_grade += (float)(sumEachGrade[i]/countEachGrade[i]) * weights[i];
  
   }
  
   return final_grade;
  
}

void print_grade(float final_grade) {
char limit[][4] = { { 90,80,70,60 },{ 'A','B','C','D' } };


char grade = 'F';
for (int i = 0; i < 4; i++) {
if (score >= limit[0][i])
   grade = limit[1][i];
}

cout << "Grade is: " << grade << " and grade numeric is " << final_grade ;
}

int main(){
  
   Score score[50];
   int size = 50;
   int grade[] = {1,2,3,4,5,6};
   int gradeSize = 6;
   float weight[] = {0.1, 0.2, 0.15, 0.15, 0.2, 0.2};
  
   inputData(score, size);
  
   cout<<"Average is: " << averageOfGrade(score, size, 1);
  
   print_grade(finalGrade(score, size, grade, weights, gradeSize ));
}