Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- bool read(char stu[20]) {
- //Input file stream
- ifstream inFS;
- //Output file stream
- ofstream outFS;
- //Opening for input
- string filename = "";
- cin >> filename;
- inFS.open(filename);
- if (!inFS.is_open()) {
- cout << "File \"" << filename << "\" could not be opened" << endl;
- return false; // 1 indicates error
- }
- int a = 0;
- while (!inFS.eof()) {
- inFS >> stu[a];
- a++;
- }
- inFS.seekg(0, ios::beg);
- return true;
- }
- void display(char stu[20], char ans[20]) {
- int position = 0;
- int wrong = 0;
- while (position <= 20) {
- if (stu[position] != ans[position]) {
- cout << "Question " << position + 1 << " has incorrect answer '" << stu[position] << "', the correct answer is '" << ans[position] << "'" << endl;
- wrong++;
- }
- position++;
- }
- cout << wrong << " questions were missed" << endl;
- if ((20 - wrong) < 14) {
- cout << "The student failed" << endl;
- }
- else {
- cout << "The student passed" << endl;
- }
- return;
- }
- int main()
- {
- char stu[20];
- if (read(stu) == false) {
- return 0;
- }
- char ans[20];
- if (read(ans) == false) {
- return 0;
- }
- display(stu, ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement