Drivers license exam program to grade a 20 question test


SUBMITTED BY: Guest

DATE: Nov. 12, 2013, 2:52 a.m.

FORMAT: Text only

SIZE: 3.7 kB

HITS: 1384

  1. /* Drivers license exam program to grade a 20 question test
  2. *Put all the correct answers in 1 array, all the users answers in another
  3. *compare arrays for # of correct answers
  4. **student must get 15 out of 20 to pass
  5. *tells student in this order
  6. **Did they pass
  7. **total number of correct questions
  8. **total number of incorrect questions
  9. **list showing the numbers of the questions that were wrong
  10. */
  11. /*
  12. ***ANSWERS
  13. //can only accept ABC or D as an answer
  14. 1. B 2. D 3. A 4. A 5. C 6. A 7. B 8. A 9. C 10. D 11. B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19. D 20. A
  15. */
  16. #include <iostream>
  17. #include <iomanip>
  18. #include <string>
  19. using namespace std;
  20. int main()
  21. {
  22. const int QUESTIONS = 20; //1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  23. char correctAnswers[QUESTIONS] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
  24. //number of questions is 20 in the test, and then we store the answers in an array
  25. char studentAnswers[QUESTIONS];
  26. bool badEntry = false;
  27. int answeredCorrectly = 0;
  28. //we use char right & wrong to compare against since if we try to compare against 'A' it'll compare incorrectly
  29. const char wrong = 'X', right = '.', A = 'A', B = 'B', C = 'C', D = 'D';
  30. //now we use a for loop to go through the questions and store whether the answer was right or wrong
  31. /*for (int x = 0; x < QUESTIONS;)
  32. {
  33. cout << "Please enter the answer for question #" << (x + 1) << endl;
  34. cin >> studentAnswers[x];
  35. if (studentAnswers[x] != A || B)
  36. {
  37. badEntry = true;
  38. while (badEntry = true)
  39. {
  40. cout << "Invalid entry, please enter A, B, C, or D" << endl;
  41. cin >> studentAnswers[x];
  42. if (studentAnswers[x] == A || B)
  43. badEntry = false;
  44. }
  45. }
  46. }*/
  47. //here's where we check for an invalid entry
  48. //stores the answer and replaces the students answer with whether it was right or wrong
  49. if (studentAnswers[x] == correctAnswers[x])
  50. {
  51. answeredCorrectly++;
  52. studentAnswers[x] = '.';
  53. }
  54. else
  55. studentAnswers[x] = 'X';
  56. x++;
  57. }
  58. //now that we have cycled through all the questions and gotten the answers, heres the info we have
  59. //questions have been entered
  60. //judged whether they were right or wrong
  61. //stored Y or N in the studentAnswer array so we can tell them which questions were wrong
  62. //now we just output all of it
  63. /*
  64. **Did they pass
  65. **total number of correct questions
  66. **total number of incorrect questions
  67. **list showing the numbers of the questions that were wrong
  68. */
  69. //need to use strcmp to compare the char arrays
  70. if (answeredCorrectly >= 15)
  71. cout << endl << "Congratulations, you passed!" << endl << endl;
  72. if (answeredCorrectly < 15)
  73. cout << endl << "You failed, better work on those pipe laying skills!" << endl << endl;
  74. cout << "You got " << answeredCorrectly << " questions right." << endl;
  75. cout << "You got " << (20 - answeredCorrectly) << " questions wrong." << endl << endl;
  76. cout << "The questions you got wrong were" << endl;
  77. for (int y = 0; y < QUESTIONS; y++)
  78. {
  79. if (studentAnswers[y] == wrong)
  80. cout << "Question " << (y + 1 ) << ": " << studentAnswers[y] << endl;
  81. //if (studentAnswers[y] = 'N')
  82. //cout << "Question " << (y + 1) << endl;
  83. }
  84. cout << "Please press any key then hit enter to exit" << endl;
  85. cin >> answeredCorrectly;
  86. }

comments powered by Disqus