A teacher needs help grading a True/False test. The students’ IDs and test answe
ID: 3712677 • Letter: A
Question
A teacher needs help grading a True/False test. The students’ IDs and test answers will be provided by the teacher. Write a program that accepts an ID number from the teacher and then evaluates their answers. Luckily, there are only 20 questions and all the correct answers are true. Assume each question is worth 2 points for a total of 40 points. Your task is to evaluate each student and output their individual score based out of 100%. You must store each students score in an array of doubles and then at the end of your program print out the scores from smallest to largest.
Sample Output:
Enter how many students took the test
3
Enter in Student ID #
104
Enter in their answers
TTTTTTTTFTTTTTFFFTTT
Student: 104 Grade: 80.0%
Enter in Student ID #
102
Enter in their answers
FFFFFTTTTTFFFFFTTTTT
Student: 102 Grade: 50.0%
Enter in Student ID #
119
Enter in their answers
TTTTTTTTTTTTTTTTTTTT
Student: 119 Grade: 100.0%
Student scores are 50.0, 80.0, and 100.0.
Write in java and write the code at a simple level
Explanation / Answer
Solution:
code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <vector>
using namespace std;
const int MAXQUESTIONS = 20;
const int TOTAL_STUDENTS = 151;
char letterGrade(int totalScore)
{
double scorePercent = static_cast<double>(totalScore) / (MAXQUESTIONS*2);
cout << "Score: " << scorePercent*100 << "%" << endl;
if (scorePercent >= 0.9)
return 'A';
else if (scorePercent >= 0.8)
return 'B';
else if (scorePercent >= 0.7)
return 'C';
else if (scorePercent >= 0.6)
return 'D';
else
return 'F';
}
int main()
{
char grade;
string ID[TOTAL_STUDENTS];
char answerCorrect[MAXQUESTIONS+1];
char answersGiven[TOTAL_STUDENTS][MAXQUESTIONS];
ifstream inputFile;
inputFile.open("Ch8_Ex6Data.txt");
if (!inputFile)
{
cout << "Error opening the input file" << endl;
exit(1);
}
// get the correct answers
inputFile.getline(answerCorrect, '/n');
int i = 0;
while(true)
{
inputFile >> ID[i];
inputFile.get();
for (int j = 0; j < MAXQUESTIONS; j++)
answersGiven[i][j] = inputFile.get();
if(inputFile.eof())
break;
i++;
}
int totalStudents = i;
for (int i = 0; i < totalStudents; i++)
{
cout << " Student ID: " << ID[i] << endl;
int totalScore = 0;
cout << "Answers: ";
for (int j = 0; j < MAXQUESTIONS; j++)
{
cout << answersGiven[i][j];
if (answersGiven[i][j] == answerCorrect[j])
totalScore = totalScore + 2;
else if (answersGiven[i][j] != answerCorrect[j] && answersGiven[i][j] != ' ')
totalScore = totalScore - 1;
}
if (totalScore < 0)
totalScore = 0;
cout << endl;
grade = letterGrade(totalScore);
cout << "Grade: " << grade << endl << endl;
}
return 0;
}
/*
Ch8_Ex6Data.txt
TFFTFFTTTTFFTFTFTFTT
ABC54301 TFTFTFTT TFTFTFFTTFT
ABC59310 TFFTFFTTTTFFTFTFFTFF
ABC39583 TFFFTTFFFTFFTFTFTFTT
ABC38493 FTFTTFTFTFTTF TFFTTT
ABC10394 FTTFTFTFFTFTFTTFTTFT
ABC10006 FTFTFFFTFFTFTFTFFTFT
ABC10007 FTFTFFTFTFTTTTFFTTFT
ABC38558 TFFTFFTTTTFFTFTFTFTT
output:
Student ID: ABC54301
Answers: TFTFTFTT TFTFTFFTTFT
Score: 27.5%
Grade: F
Student ID: ABC59310
Answers: TFFTFFTTTTFFTFTFFTFF
Score: 70%
Grade: C
Student ID: ABC39583
Answers: TFFFTTFFFTFFTFTFTFTT
Score: 55%
Grade: F
Student ID: ABC38493
Answers: FTFTTFTFTFTTF TFFTTT
Score: 20%
Grade: F
Student ID: ABC10394
Answers: FTTFTFTFFTFTFTTFTTFT
Score: 10%
Grade: F
Student ID: ABC10006
Answers: FTFTFFFTFFTFTFTFFTFT
Score: 32.5%
Grade: F
Student ID: ABC10007
Answers: FTFTFFTFTFTTTTFFTTFT
Score: 25%
Grade: F
Student ID: ABC38558
Answers: TFFTFFTTTTFFTFTFTFTT
Score: 100%
Grade: A
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.