Can someone help me with this C program for Code Blocks as w
Can someone help me with this C++ program (for Code Blocks) as well as the Function analysis, preconditions, and postconditions after each function prototype:
The history teacher at your school needs help in grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains answers to the test in the form:
TFFTFFTTTTFFTFTFTFTT
Every other entry in the file is the student ID, followed by a blank, followed by the student’s responses. For example, the entry:
ABC54301 TFTFTFTT TFTFTFFTTFT
indicates that the student ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is False, and so on.This student did not answer question 9. The exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points. Write a program that processes the test data. The output should be the student’s ID, followed by the answers, followed by the test score, followed by the test grade. Assume the following grade scale: 90%–100%, A; 80%–89.99%, B; 70%–79.99%, C; 60%–69.99%, D; and 0%–59.99%, F. A data file, Ch8_Ex6Data.txt has been provided for testing.
Turn in your source code which should be commented as follows:
Analysis at the top of the file
Function analysis, preconditions, and postconditions after each function prototype
Major tasks identified as comments in main function
Comments in functions as needed
Solution
// C++ code determine score and letter grade
#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
*/


