-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bed849d
Showing
41 changed files
with
1,532 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
A | ||
A | ||
A | ||
A | ||
B | ||
B | ||
B | ||
B | ||
C | ||
C | ||
C | ||
C | ||
D | ||
D | ||
D | ||
D | ||
A | ||
B | ||
C | ||
D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
A | ||
A | ||
A | ||
A | ||
B | ||
B | ||
B | ||
B | ||
C | ||
C | ||
C | ||
C | ||
D | ||
D | ||
D | ||
D | ||
A | ||
B | ||
C | ||
D | ||
A | ||
B | ||
B | ||
A | ||
C | ||
D | ||
C | ||
D | ||
A | ||
D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
#include <iomanip> | ||
|
||
|
||
using namespace std; | ||
|
||
//our prototypes | ||
int read(char[30], string inputFileName); | ||
void workDisplay(char[30], char[30], int, int); | ||
|
||
|
||
int main() { | ||
char studentAnswers[30], correctAnswers[30]; //initializes our arrays with 30 default elements | ||
int numOfStudentAnswers, numOfCorrectAnswers; //declares our variables that will store the number of answers in each file | ||
string studentAnswersFileName, correctAnswersFileName; //these will hold our file names | ||
|
||
cout << "Enter student answers file name\n"; //gets the file name that contains our student's answers | ||
cin >> studentAnswersFileName; | ||
|
||
if (read(studentAnswers, studentAnswersFileName) != -1) //checks that studentAnswersFileName was properly opened | ||
{ | ||
numOfStudentAnswers = read(studentAnswers, studentAnswersFileName); //sets our number of student answers | ||
|
||
cout << "Enter correct answer file name\n"; //gets the file name that contains our correct answers | ||
cin >> correctAnswersFileName; | ||
|
||
if (read(correctAnswers, correctAnswersFileName) != -1) //checks that correctAnswersFileName was properly opened | ||
numOfCorrectAnswers = read(correctAnswers, correctAnswersFileName); //sets our number of correct answers | ||
else //error message if correctAnswersFileName wasn't properly opened | ||
{ | ||
cout << "File \"" << correctAnswersFileName << "\" could not be opened\n"; | ||
return 0; | ||
} | ||
} | ||
else //error message if studentAnswersFileName wasn't properly opened | ||
{ | ||
cout << "File \"" << studentAnswersFileName << "\" could not be opened\n"; | ||
return 0; | ||
} | ||
|
||
if (numOfStudentAnswers == numOfCorrectAnswers) //verifies the number of student answers is equal to the number of correct answers | ||
if (numOfStudentAnswers == 0) //if both of these are zero, we can't calculate a grade | ||
{ | ||
cout << "The number of student answers and correct answers are both 0\n"; | ||
cout << "No grade can be calculated\n"; | ||
return 0; | ||
} | ||
else //this condition is for when there have been no errors in opening files, and the number of student answers is equal to the number of correct answers and is greater than zero | ||
{ | ||
workDisplay(studentAnswers, correctAnswers, numOfStudentAnswers, numOfCorrectAnswers); //will print out all missed questions (incorrect and correct answers), the student's grade, and the pass/fail status | ||
return 0; | ||
} | ||
else //prints out eror messages if the number of student answers isn't the same as the number of correct answers | ||
{ | ||
cout << "The student answers file has " << numOfStudentAnswers << " entries and the correct answers "; | ||
cout << "file has " << numOfCorrectAnswers << " entries\n"; | ||
cout << "Grading cannot be done if they are not the same\n"; | ||
return 0; | ||
} | ||
|
||
|
||
} | ||
|
||
int read(char arrayName[30], string inputFileName) | ||
{ | ||
int numOfInputs = 0; //will act as our loop control variable and our counter to store the number of answers in inputFileName | ||
ifstream inputFrom; | ||
inputFrom.open(inputFileName.c_str()); | ||
if (inputFrom) | ||
{ | ||
while (inputFrom >> arrayName[numOfInputs]) //cycles through inputFileName and stores data in arrayName | ||
{ | ||
++numOfInputs; //counts how many answers we have | ||
} | ||
inputFrom.close(); //close statement is only necessary if the open worked ( inputFrom = True ) | ||
|
||
if (numOfInputs >= 30) //30 answers is the max | ||
return 30; | ||
else //returns the number of answers when the value is less than 30 | ||
return numOfInputs; | ||
} | ||
else | ||
return -1; //this indicates the inputFileName file does not exist or didn't open properly | ||
|
||
} | ||
|
||
|
||
void workDisplay(char studentAnswersArray[30], char correctAnswersArray[30], int numOfStudentAnswers, int numOfCorrectAnswers) //this assumes numOfStudentAnswers == numOfCorrectAnswers | ||
{ | ||
int numMissed = 0; //The total number of questions missed by the student | ||
double percentage; //The percentage of the questions answered correctly. | ||
for (int i = 0, j = 0; i < numOfStudentAnswers && j < numOfCorrectAnswers; ++i, ++j) //built to be dynamic, in case numOfStudentAnswers != numOfCorrectAnswers | ||
{ | ||
if (studentAnswersArray[i] != correctAnswersArray[j]) | ||
{ | ||
++numMissed; //increments the number of missed problems | ||
cout << "Question " << j + 1 << " has incorrect answer '" << studentAnswersArray[i] << "', the correct answer is '" << correctAnswersArray[j] << "'\n"; //outputs missed problems' numbers, the incorrect answer, and the correct answer | ||
} | ||
} | ||
percentage = ((numOfCorrectAnswers - numMissed) / static_cast<double>(numOfCorrectAnswers)) * 100; //percentage can be a double thanks to static_cast | ||
|
||
//these last print statements print out the number of missed problems, the student's grade as a percentage, and their pass/fail status | ||
cout << numMissed << " questions were missed out of " << numOfCorrectAnswers << endl; | ||
cout << "The student grade is " << fixed << setprecision(1) << percentage << "%" << endl; | ||
cout << "The student "; | ||
if (percentage >= 70) | ||
cout << "passed\n"; | ||
else | ||
cout << "failed\n"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
A | ||
B | ||
C | ||
D | ||
A | ||
B | ||
C | ||
D | ||
A | ||
B | ||
C | ||
D | ||
A | ||
B | ||
C | ||
D | ||
A | ||
B | ||
C | ||
D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
A | ||
A | ||
A | ||
A | ||
B | ||
B | ||
B | ||
B | ||
C | ||
C | ||
C | ||
C | ||
D | ||
D | ||
D | ||
D | ||
A | ||
B | ||
C | ||
D | ||
A | ||
B | ||
B | ||
A | ||
C | ||
D | ||
C | ||
D | ||
A | ||
D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
E | ||
A | ||
A | ||
B | ||
B | ||
B | ||
B | ||
A | ||
C | ||
C | ||
C | ||
D | ||
D | ||
D | ||
D | ||
C | ||
A | ||
B | ||
D | ||
E | ||
A | ||
B | ||
B | ||
C | ||
C | ||
D | ||
E | ||
D | ||
A | ||
D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
10.0 20.0 30.0 40.0 50.0 | ||
100.0 90.0 80.0 70.0 60.0 | ||
95.0 85.0 75.0 65.0 55.0 | ||
25.2 27.2 29.3 31.2 33.2 | ||
88.9 78.8 68.7 58.6 48.5 | ||
10.1 20.1 30.1 40.1 50.1 | ||
100.1 90.1 80.1 70.1 60.1 | ||
95.1 85.1 75.1 65.1 55.1 | ||
25.2 27.3 29.4 31.3 33.3 | ||
88.0 78.9 68.8 58.7 48.6 | ||
10.9 20.8 30.7 40.6 50.5 | ||
100.9 90.8 80.7 70.6 60.5 | ||
95.9 85.8 75.7 65.6 55.5 | ||
25.8 27.7 29.6 31.5 33.4 | ||
88.7 78.6 68.5 58.4 48.3 | ||
20.0 30.0 40.0 50.0 60.0 | ||
90.0 80.0 70.0 60.0 50.0 | ||
85.0 75.0 65.0 55.0 45.0 | ||
45.2 47.2 49.3 51.2 53.2 | ||
48.9 58.8 68.7 78.6 88.5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
90.0 80.0 70.0 60.0 50.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
10.0 20.0 30.0 40.0 50.0 | ||
100.0 90.0 80.0 70.0 60.0 | ||
95.0 85.0 75.0 65.0 55.0 | ||
25.2 27.2 29.3 31.2 33.2 | ||
88.9 78.8 68.7 58.6 48.5 | ||
10.1 20.1 30.1 40.1 50.1 | ||
100.1 90.1 80.1 70.1 60.1 | ||
95.1 85.1 75.1 65.1 55.1 | ||
25.2 27.3 29.4 31.3 33.3 | ||
88.0 78.9 68.8 58.7 48.6 | ||
10.9 20.8 30.7 40.6 50.5 | ||
100.9 90.8 80.7 70.6 60.5 | ||
95.9 85.8 75.7 65.6 55.5 | ||
25.8 27.7 29.6 31.5 33.4 | ||
88.7 78.6 68.5 58.4 48.3 | ||
20.0 30.0 40.0 50.0 60.0 | ||
90.0 80.0 70.0 60.0 50.0 | ||
85.0 75.0 65.0 55.0 45.0 | ||
45.2 47.2 49.3 51.2 53.2 | ||
48.9 58.8 68.7 78.6 88.5 | ||
62.5 32.5 65.7 83.5 98.3 | ||
99.5 42.0 97.2 74.9 88.8 | ||
77.7 88.8 99.9 100.0 49.4 | ||
60.0 65.0 70.0 75.5 80.0 | ||
99.9 98.9 99.0 97.5 96.5 | ||
98.0 88.0 86.3 81.0 82.3 | ||
|
||
77.8 79.9 81.9 94.5 87.0 | ||
20.0 30.0 40.0 50.0 70.0 | ||
90.0 80.0 70.0 70.0 50.0 | ||
85.0 75.0 75.0 55.0 45.0 |
Oops, something went wrong.