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

Please write a program using c++ that does the following using Arrays and pointe

ID: 3775464 • Letter: P

Question

Please write a program using c++ that does the following using Arrays and pointers

You are to write a program that can be used to grade a True/False test. The user is to be prompted for how many questions are on the exam. The input to the program is a file where the first record contains the answer key and the remaining records contain a student ID and the student responses. The first record contains answers in the form :

TFFTFFTTTTFFTFTFTFTT

The other records are formatted as :

17236 TFTFTF TTFTFFTTTTFTF

where the srudent ID is 17236 and the student's responses follow the space after the student ID. Note that on this example, the student did not answer question 7. Each correct answer is awarded 2 points, each wrong answer gets 1 point deducted and no answer gets zero points.

The output should be the student's ID, followed by the correct answers, follwed by the test score, followed by the grade. The test grading scale is as follows : 90 % - 100 % = A, 80 % - 89.99 % = B, 70 % - 79.99 % = C, 60 % - 69.99 % = D; and 0 % - 69.99 % = F.

A test file is attached.

Input.txt

Explanation / Answer

#include <iostream> // library that contain basic input/output functions
#include <fstream> // library that contains file input/output functions
using namespace std;

int main()
{
   char * answer = new char[20]; // Allocating an array of size 20 because there are 20 answers
   int po = 0, i, t, tot = 0;
   float per;
char * regno = new char[5]; // Allocating memory for registration number which is of size 5
char * Sanswer = new char[20]; //Students answers are 20 if not answered space
string line;
   ifstream fr("input.txt"); //Opening an input stream for file input.txt

   //Checking whether file could be opened or not.
   //If file does not exist or don't have read permissions, displays an error message
if(fr.is_open())
{
//Reads one line from the file
while (getline (fr, line))
{
//First line contains answers only so po is checked with zero
if(po == 0)
{
//Reads 20 answers and stores it in answer array
for(t = 0; t < 20; t++)
answer[t] = line[t];
answer[t] = ''; //Placing character array terminating character
po++;
//Displays the correct answer sequence
cout<<" Correct Answers: "<<answer;
}
//From next line onwards
else
{
//Reads registration number and stores it in the regno array
for(i = 0; i <= 5; i++)
regno[i] = line[i];
regno[i] = ''; //Placing character array terminating character

//Reads Student answers and stores it in the Sanswer array
for(t = 0; t < 20; t++, i++)
Sanswer[t] = line[i];
Sanswer[t] = ''; //Placing character array terminating character

//Displays the answer given by the student
cout<<" Student Answered: "<<Sanswer;

//Calculates the percent and grade
for(t = 0; t < 20; t++)
{
//Checks for the correct answer
if(answer[t] == Sanswer[t])
tot += 2; //Adds 2 mark for correct answer
//Checks for the Wrong answer
else if (answer[t] != Sanswer[t])
tot -= 1; //Subtracts 1 mark for the wrong answer
else //For not answered
tot += 0;
}
//Calculates percentage
per = tot/.40;
//Checks for the grade
if(per >= 90)
cout<<" Student Id: "<<regno<<" Grade: A";
else if(per >= 80)
cout<<" Student Id: "<<regno<<" Grade: B";
else if(per >= 70)
cout<<" Student Id: "<<regno<<" Grade: C";
else if(per >= 60)
cout<<" Student Id: "<<regno<<" Grade: D";
else
cout<<" Student Id: "<<regno<<" Grade: F";
tot = 0;
}
}
}
//Error If file not found
   else
   {
       cout << " ERROR: File could not be opened." << endl;
   }
   return 0;
}

Output:


Correct Answers: TTFTFTTTFTFTFFTTFTTF

Student Answered: T FTFTFTTTFTTFTTF TF
Student Id: 54102 Grade: D

Student Answered: TTFTFTTTFTFTFFTTFTTF
Student Id: 56278 Grade: A

Student Answered: TTFTFTTTFTFTFFTTF
Student Id: 42366 Grade: C

Student Answered: TTTTFTTT TFTFFFTF
Student Id: 42586 Grade: F

Student Answered: TTFTFTTTFFFTFFTTTTTF
Student Id: 12345 Grade: B