Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. bool read(char stu[20]) {
  8. //Input file stream
  9. ifstream inFS;
  10. //Output file stream
  11. ofstream outFS;
  12. //Opening for input
  13. string filename = "";
  14. cin >> filename;
  15. inFS.open(filename);
  16. if (!inFS.is_open()) {
  17. cout << "File \"" << filename << "\" could not be opened" << endl;
  18. return false; // 1 indicates error
  19. }
  20. int a = 0;
  21. while (!inFS.eof()) {
  22. inFS >> stu[a];
  23. a++;
  24. }
  25. inFS.seekg(0, ios::beg);
  26. return true;
  27. }
  28.  
  29. void display(char stu[20], char ans[20]) {
  30. int position = 0;
  31. int wrong = 0;
  32. while (position <= 20) {
  33. if (stu[position] != ans[position]) {
  34. cout << "Question " << position + 1 << " has incorrect answer '" << stu[position] << "', the correct answer is '" << ans[position] << "'" << endl;
  35. wrong++;
  36. }
  37. position++;
  38. }
  39. cout << wrong << " questions were missed" << endl;
  40. if ((20 - wrong) < 14) {
  41. cout << "The student failed" << endl;
  42. }
  43. else {
  44. cout << "The student passed" << endl;
  45. }
  46. return;
  47. }
  48.  
  49. int main()
  50. {
  51. char stu[20];
  52. if (read(stu) == false) {
  53. return 0;
  54. }
  55. char ans[20];
  56. if (read(ans) == false) {
  57. return 0;
  58. }
  59. display(stu, ans);
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement