One-Dimension Array

Help me out, my professor gave us this problem, I can't figure it out. And I also do not have a C++ program in my PC because it's too low-tech and no internet. Thanks in advance.

A university gives an entrance exam to new students before allowing them to enroll in their preferred programs. Write a program that will check the score of the student’s entrance exam. The exam has 25 multiple choice questions and here are the correct answers:

1. D 2. C 3. D 4. D 5. A
6. B 7. C 8. A 9. B 10. B
11. C 12. D 13. A 14. B 15. C
16. D 17. D 18. A 19. B 20. A
21. A 22. B 23. D 24. A 25. C

You should have an array that contains the correct answers. Part of the program will accept the student’s answer for each of the 25 questions that will also be stored in an array. After the student’s answers have been entered, the program will display a message if the student passed or failed the exam with the corresponding score. It is required that the student should get 15 correct answers out of the 25 questions. Finally, display the total number of questions correctly answered and the total number of questions incorrectly answered.
If you genuinely can't figure this out, your problem is not programming but basic thinking.

Write out two arrays. One of them is the correct answer. One is the students answers. How would YOU work out the student's score? On paper.
Last edited on
Start by creating an array that stores a single char.

 
char correctArray[25] = {'D', 'C', ...}; //0 being the first question, 24 the last. 


Then iterate over each element and set answers like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
char inputBuffer;
int correct = 0;
for (int i = 0; i < 25; i++)
{
std::cout << "Set answer #" << (i+1) << ": ";
std::cin >> inputBuffer;
if (correctArray[i] == inputBuffer)
correct++;
}
if (correct >= 15)
std::cout << "The student passed!\n";
else
std::cout << "The student failed!\n";

std::cout << "Correct answers: " << correct << "/25";
Last edited on
Our professor said to follow this format...
Can you create a version of the program that I'm asking and put it in this format?

HERE'S THE SAMPLE FORMAT:

#include <iostream>
#include <string>
using namespace std;

int main ()
{
string names[5][5]={{"Jose","Andres",},{"Apolinario","Manny"}};
string names2[2][2];
int row,col,score=0;

cout<<"Enter 5 names:"<<endl;
for(row=0; row<=1; row++)
{
for(col=0; col<=1; col++)
{
cin>>names2[row][col];
}
}

for(row=0; row<=1; row++)
{
for(col=0; col<=1; col++)
{
if(names2[row][col]==names[row][col])
score++;
}
}
cout<<"Your total correct answer/s is/are: "<<score<<endl;
system("PAUSE");
return 0;
}
Last edited on
Topic archived. No new replies allowed.