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

Program has to be done in C++ language and by only using #include <iostream> #in

ID: 3815839 • Letter: P

Question

Program has to be done in C++ language and by only using

#include <iostream>
#include <fstream>

libraries and nothing more

Program has to be done in C++ language and by only using

#include <iostream>
#include <fstream>

libraries and nothing more

70% ooo T-Mobile 9:12 PM The program will grade a series of exams and then print a grade report for students in a Course input: An instructor has a class of students each of whom takes a multiple-choice exam with 10 questions. For each student in the class, there is one line in the input file The line contains the answers that student gave for the exam. The input file named "grade data.txt" will have the following format: line 1: the key for the exam (e.g.) bccbbadbca lines 2 bccbbbdbbb bccbbadbca bccbbadbbb etc a set of answers. You know you are done when you get to a line with no data Note: You will not know in advance how many exams you have to grade and you DO NOT need to store the exam answers in your program. Processing: The program is to read the input file and grade each exam and print out the score for that exam. You will also keep track of how many students earned each score (0-10) and print a report after the grading. output: Here is an example of how the output might appear. You will write the report to an output file named "grade report.txt student 1 8 student 2 10 student 3 1 etC Final Report 10 high score 10 low score mean score 6.25 NOTES: The program must be modular, with significant work done by functions. Each function should perform a single, well-defined task. When possible, create re usable functions. Do not write trivial functions such as a function to read a single value from an input file o e.g. you should have a function that grades the exam and returns the score when passed the key and and one set of answers o u should probably have functions that take an array and number of questions as parameters and find the high low, and mean Don't calculate the mean. high. and low as vou grade the exams.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;

void findHLM(vector<int> &arr, int numQ) // find and pring high low and mean 5 4 6 1 4 10 9 14 18 52 20
{
   int studCount = arr.size();
   ofstream out;
   int highscore = INT_MIN, lowscore = INT_MAX;
   int meanscore=0;
   int sum = 0;
   double mean;
   int *CountArr = new int[numQ];
   memset(CountArr, 0, (numQ+1)*sizeof(*CountArr));
   //cout << "init 0 array" << endl;
  
   for (vector<int>::const_iterator itr = arr.begin(); itr != arr.end(); ++itr)
   {
       CountArr[*itr]++;
   }

   out.open("E:grade_report.txt");
   cout << endl;
   for (int i = 0; i <studCount; i++)
   {
       out << "student " << i + 1 << " - " << arr.at(i)<<endl;
       sum = sum + arr.at(i);
   }
   mean = sum / studCount;

   // CountArr
   out << "Final Report" << endl;
   out << "------------" << endl;
   for (int i = numQ; i >= 0; i--)
   {
       out << i << " - " << CountArr[i]<<endl;
       if (CountArr[i]>0 && i > highscore)
           highscore = i;
       else if (CountArr[i] > 0 && i < lowscore)
           lowscore = i;
   }

   // write output
   out << "output" << endl;
   out << "high score - " << highscore<<endl;
   out << "low score - " << lowscore << endl;
   out << "mean score - " << mean<<endl;
   out.close();
}


int gradeExam(string answerKey, string answer) // key and set of answers passed
{
   int score = 0;
   int wrong = 0;
   for (int i = 0; i <answer.length(); i++)
   {
       if (answerKey.at(i) == answer.at(i))
           score++;
       else
           wrong++;
   }
   return score;
}

void readData(string filename, string &answerKey, vector<string> &answerArr)// read input file
{
   string line = "";
   ifstream ins;
   int i = 0;
   ins.open(filename);
   std::getline(ins, answerKey);
   //cout << "Answer line is: " << answerKey << endl;

   while (std::getline(ins, line))
   {
       //std::cout << "line: " << line << endl;
       answerArr.push_back(line);
   }
   ins.close();
}


int main()
{
   string filename = "grade_data.txt";
   string answerKey = "";
   vector<string>answerArr;
   vector<int>scoreArr;
   readData(filename, answerKey, answerArr);
   //cout << "Asnwer key is: " << answerKey << endl;
   int i = 1;
   // print vector of strings
   //cout << "Now printing string array ..." << endl;

   for (vector<string>::const_iterator itr = answerArr.begin(); itr != answerArr.end(); ++itr)
   {
       int ans = gradeExam(answerKey, *itr);
       scoreArr.push_back(ans);
       //cout << "Student " << i << " Answer is: " << *itr <<" and correct answers are: "<< ans << endl;
       i++;
   }
   //cout << "scores are as below" << endl;
   /*
   for (vector<int>::const_iterator itr = scoreArr.begin(); itr != scoreArr.end(); ++itr)
   {
       cout << "Score are :" << *itr << endl;
   }
   */
   findHLM(scoreArr, answerKey.length());
  
}

Dr Jack
Hire Me For All Your Tutoring Needs
Quick quotes • Clear explanations • Study support
Chat Now And Get Quote