fork download
  1. //Xinnuo Wang CS1A chapter7 #9
  2. /*******************************************************************************
  3.  * Grade an Exam
  4.  * _____________________________________________________________________________
  5.  * The program accepts 20 answers,grades the written portion of the exam and
  6.  * displays the total number of correctly answered questions, the total number
  7.  * of incorrectly answered questions, and a list showing the question numbers of
  8.  * the incorrectly answered questions.
  9.  *
  10.  * _____________________________________________________________________________
  11.  * Input:
  12.  * choice : The accepted choices in an array.
  13.  * solution : The solutions in an array.
  14.  * Output:
  15.  * c_num : The total number of correctly answered questions.
  16.  * ic_num : The total number of incorrectly answered questions.
  17.  *
  18.  * ****************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main() {
  23. const int SIZE = 20;
  24. char choice[SIZE];
  25. char solution[SIZE] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
  26. int c_num = 0;
  27. int ic_num = 0;
  28. int m= 0;
  29. int ic_choice[20];
  30. for(int i = 0; i < SIZE; i++)
  31. {
  32. cout << "Enter your answer of qustion " << i+1 ;
  33. cin>> choice[i];
  34. cout << choice[i] << endl;
  35. // validate check
  36. while(choice[i]!= 'A'&&choice[i]!= 'B'&&choice[i]!= 'C'&&choice[i]!= 'D')
  37. {
  38. return 0;
  39. }
  40. if(choice[i] == solution[i])
  41. {
  42. c_num ++;
  43. }
  44. else
  45. {
  46. ic_num ++;
  47. ic_choice[m]=i+1;
  48. m++;
  49. }
  50. }
  51. // Output Result
  52. if (c_num >=15)
  53. {
  54. cout<< "You pass the exam!"<< endl;
  55. }
  56.  
  57. cout << "The total number of correctly answered questions is: " << c_num << endl;
  58. cout << "the total number of incorrectly answered questions is : " << ic_num << endl;
  59. cout << "A list showing the question of the incorrectly answered questions";
  60.  
  61. for (int n = 0; n< ic_num ; n++)
  62. {
  63. cout<< ic_choice[n]<< " " ;
  64. }
  65. return 0;
  66. }
Success #stdin #stdout 0s 5312KB
stdin
B D A A C A D A C  D B C D A D C C B D B
stdout
Enter your answer of qustion 1B
Enter your answer of qustion 2D
Enter your answer of qustion 3A
Enter your answer of qustion 4A
Enter your answer of qustion 5C
Enter your answer of qustion 6A
Enter your answer of qustion 7D
Enter your answer of qustion 8A
Enter your answer of qustion 9C
Enter your answer of qustion 10D
Enter your answer of qustion 11B
Enter your answer of qustion 12C
Enter your answer of qustion 13D
Enter your answer of qustion 14A
Enter your answer of qustion 15D
Enter your answer of qustion 16C
Enter your answer of qustion 17C
Enter your answer of qustion 18B
Enter your answer of qustion 19D
Enter your answer of qustion 20B
You pass the exam!
The total number of correctly answered questions is: 18
the total number of incorrectly answered questions is : 2
A list showing the question of the incorrectly answered questions7 20