fork download
  1. /*
  2.   This program will take a file
  3.   with the answers to a test
  4.   and compare them to the
  5.   answers a student got in
  6.   another file.
  7. */
  8. #include <iostream>
  9. #include <fstream>
  10. using namespace std;
  11.  
  12. const int SIZE = 20; //global constant
  13.  
  14. int calcMissed() //gets files to find student's incorrect answers
  15. {
  16. ifstream answers; //correct answers stored in this variable
  17. answers.open(correctanswers.txt);
  18. char cAnswers[SIZE] = {answers}; //stored into array for calculation
  19. ifstream student; //student answers stored in this variable
  20. student.open(studentanswers.txt);
  21. char sAnswers[SIZE] = student;
  22.  
  23. int incorrect = 0;
  24. for(int i = 0; i < 20; i++)
  25. {
  26. if(sAnswers[i] != cAnswers[i])
  27. {
  28. incorrect += 1;
  29. }
  30. }
  31. answers.close();
  32. student.close();
  33. return incorrect;
  34. }
  35. int calcCorrect(); //gets files to find student's correct answers
  36. {
  37. ifstream answers; //correct answers stored in this variable
  38. answers.open(correctanswers.txt);
  39. char cAnswers[SIZE] = answers; //stored into array for calculation
  40. ifstream student; //student answers stored in this variable
  41. student.open(studentanswers.txt);
  42. char sAnswers[SIZE] = student;
  43.  
  44. int correct = 0;
  45. for(int i = 0; i < 20; i++)
  46. {
  47. if(sAnswers[i] == cAnswers[i])
  48. {
  49. correct += 1;
  50. }
  51. }
  52. answers.close();
  53. student.close();
  54. return correct;
  55. }
  56. int main()
  57. {
  58. ifstream answers; //correct answers stored in this variable
  59. answers.open(correctanswers.txt);
  60. char cAnswers[SIZE] = answers; //stored into array for calculation
  61. ifstream student; //student answers stored in this variable
  62. student.open(studentanswers.txt);
  63. char sAnswers[SIZE] = student;
  64.  
  65. int correct[SIZE] = calcCorrect();
  66. int incorrect[SIZE] = calcMissed();
  67.  
  68. cout << "The student got " << correct << " of the answers correct." << endl;
  69. cout << "The student got " << incorrect << " of the answers incorrect." << endl;
  70. cout << "#" << "\t" << "Correct Answer" << "\t" << "Student's Answer" << endl;
  71. for(int i = 0; i < SIZE; i++)
  72. {
  73. cout << (i + 1) << "\t" << correct[i] << "\t" << incorrect[i] << endl;
  74. }
  75. return 0;
  76. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int calcMissed()':
prog.cpp:17:18: error: 'correctanswers' was not declared in this scope
     answers.open(correctanswers.txt);
                  ^
prog.cpp:18:35: error: invalid user-defined conversion from 'std::ifstream {aka std::basic_ifstream<char>}' to 'char' [-fpermissive]
     char cAnswers[SIZE] = {answers};  //stored into array for calculation
                                   ^
In file included from /usr/include/c++/4.9/ios:44:0,
                 from /usr/include/c++/4.9/ostream:38,
                 from /usr/include/c++/4.9/iostream:39,
                 from prog.cpp:8:
/usr/include/c++/4.9/bits/basic_ios.h:115:7: note: candidate is: std::basic_ios<_CharT, _Traits>::operator void*() const [with _CharT = char; _Traits = std::char_traits<char>] <near match>
       operator void*() const
       ^
/usr/include/c++/4.9/bits/basic_ios.h:115:7: note:   no known conversion from 'void*' to 'char'
prog.cpp:20:18: error: 'studentanswers' was not declared in this scope
     student.open(studentanswers.txt);
                  ^
prog.cpp:21:27: error: array must be initialized with a brace-enclosed initializer
     char sAnswers[SIZE] = student;
                           ^
prog.cpp: At global scope:
prog.cpp:36:1: error: expected unqualified-id before '{' token
 {
 ^
stdout
Standard output is empty