C++ Language and output the following The local PennDOT Office needs a program t
ID: 3770239 • Letter: C
Question
C++ Language and output the following
The local PennDOT Office needs a program to grade the written portion of the driver’s test. Student’s take this test upon completing the classroom portion of driver’s exam. The exam has 20 multiple choice questions. The correct answers are:
1. B 6. A 11. B 16. C
2. D 7. B 12. C 17. C
3. A 8. A 13. D 18. B
4. A 9. C 14. A 19. D
5. C 10. D 15. D 20. A
Your program should
Store the correct answer in an array
Read the answers for a student from a file driving.dat and store them in a parallel array
Compare each entry in the correct array and student array, and store a boolean value (true/false) in a third array. If the answer is correct, store true in the third array. If the answer was incorrect, store false.
Use one or more functions that takes the third array as parameter and find or prints the number of correct answers, the number of incorrect answers, a list of numbers for the questions missed
Use another function to find whether the student passed (15 or more correct)
Write out a table with one line for each student. For each student it should report the number of correct answers, the number of incorrect answers, a list of the numbers for the questions missed and whether or not the student passed. The table should have headings for the columns.
Note:
Student answers can be found in the data file driving.dat. You can copy this file by typing
cp /export/home/public/zhang/driving.dat driving.dat
Each line contains the 20 answers a student gave. You do not know how many students so you must process until the end of the file.
Name your program driverExam_YourName.cpp.
Expected output
-bash-4.1$ ./a.out
Passed Correct Wrong Numbers Wrong
----------------------------------------------
No 14 6 2 6 9 10 19 20
Yes 20 0
Yes 17 3 2 6 15
Yes 15 5 1 2 7 10 15
No 1 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20
Yes 19 1 7
Yes 18 2 9 10
Grading guide
Please make sure your program compiles.
(1 pt) The program is named correctly (driverExam_YourName.cpp).
(1 pt) The program is well documented
(6 pts) The program reads from the file “driving.dat” and output the table correctly
(2 pts) The program uses functions to find out or return the number of correct and wrong answers, whether the student passed, the questions that the student answered wrong
Explanation / Answer
#include <iostream>
#include <string>
#include<fstream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
void printStats(int stdNo, char answers[], char answerKey[], int noOfAnswers) {
string passed = "No";
int correct = 0;
int wrong = 0;
string wrongans = "";
int missed = 0;
int i = 0;
for(i = 0; i <noOfAnswers; i++) {
if(answers[i] == ' ')
missed++;
else {
if(answers[i] == answerKey[i])
correct++;
else {
wrong++;
//wrongans += itoa(i+1)+" ";
}
}
}
if(correct >=15)
passed = "Yes";
cout << passed<< " " << correct << " " << wrong << " " << missed << " " << wrongans <<endl;
}
int main()
{
char answerKey[] = {'B', 'D','A', 'A', 'C', 'A','B','A','C','D',
'B', 'C', 'D', 'A', 'D', 'C', 'C','B','D', 'A'};
char stdAns[1024][1024];
char file[] = "D:/ravi/cheg/driving.txt";
ifstream fin;
fin.open(file, ios::in);
char ch;
char temp;
int noOfstudent = 0;
int answers = 0;
//Read till end of file
cout << "Passed"<< " " << "correct" << " " << "wrong" << " " << "missed" << " " << "Numbers Wrong" <<endl;
while (!fin.eof()) {
//get character by character
fin.get(ch);
if(ch == ' ') {
//now display the sats for each Student
printStats(noOfstudent, stdAns[noOfstudent],answerKey, answers);
noOfstudent++;
answers = 0;
}
//printStats(noOfstudent, stdAns[noOfstudent],answerKey, answers);
//assuming each line contains answers with missed answers represented by space AAAAB CDAA DDD
stdAns[noOfstudent][answers++] = ch;
}
return 0;
}
---------------outputut------------
Passed correct wrong missed Numbers Wrong
No 1 19 0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.