1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
int main()
{
ifstream file;
char determine, answers[qMAX], key[qMAX] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C',
'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
int countRt, findWrng, qWrng;
bool check[qMAX];
readAnswers(answers, qMAX);
fillCheck(key, answers, check, qMAX);
countRt = countRight(check, qMAX);
findWrng = findWrong(countRt, qMAX);
determine = determinePass(check, qMAX);
displayResults(determine, countRt, findWrng, qWrng);
file.close();
return (0);
}
void readAnswers(char raAnswers[], int raSize)
{
ifstream file;
file.open("driving.dat");
if (file.fail())
{
cout << "Open Failed." << endl;
exit(0);
}
else
cout << "Open Successful." <<endl;
for(int i=0; i<raSize; i++)
file >> raAnswers[i];
}
void fillCheck(char fcKey[], char fcAnswers[], bool fcCheck[], int fcSize)
{
for(int w=0; w<fcSize; w++)
{
if(fcKey[w] == fcAnswers[w])
fcCheck[w] = "T";
else
fcCheck[w] = "F";
}
}
int countRight(bool crCheck[], int crSize)
{
int countRt = 0;
for(int r=0; r<crSize; r++)
if(crCheck[r] == 'T')
countRt++;
return countRt;
}
int findWrong(int fwCountRight, int fwSize)
{
int findWrng;
findWrng = fwCountRight - fwSize;
return findWrng;
}
void questionsWrong(bool qwCheck[], int qwSize)
{
for(int w=0; w<qwSize; w++)
if(qwCheck[w] == 'F')
cout <<(w + 1) <<" ";
}
char determinePass(bool dpCheck[], int dpSize)
{
int pCount = 0;
char determine;
for(int p=0; p<dpSize; p++)
if(dpCheck[p] == 'T')
pCount++;
if(pCount >= 15)
determine = 'P';
else
determine = 'F';
return determine;
}
void displayResults(char drDeterminePass, int drCountRight, int drFindWrong, int drQuestionsWrong)
{
bool check[qMAX];
cout << "Pass(P)/Fail(F)" <<" " <<"NumberCorrect" <<" " <<"NumberWrong" <<" " <<"QuestionsWrong" <<endl;
cout << "------------------------------------------------------------------------" <<endl;
cout << drDeterminePass <<setw(20) <<drCountRight <<setw(20) <<drFindWrong <<setw(20);
questionsWrong(check, qMAX);
cout <<endl;
|