Answer: The c++ program is shown below.
#include <iostream>
using namespace std;
int main() {
int ques[20], correct=0, incorrect=0, q[20];
// arrays to store answers for the questions
char a[20], ans[20];
// variable to store pass or fail result
string result;
for(int k=0; k<20; k++)
{
ques[k] = k+1;
q[k] = 0;
}
ans[0]='B';
ans[1]='D';
ans[2]='A';
ans[3]='A';
ans[4]='C';
ans[5]='A';
ans[6]='B';
ans[7]='A';
ans[8]='C';
ans[9]='D';
ans[10]='B';
ans[11]='C';
ans[12]='D';
ans[13]='A';
ans[14]='D';
ans[15]='C';
ans[16]='C';
ans[17]='B';
ans[18]='D';
ans[19]='A';
for(int k=0; k<20; k++)
{
cout<<"Enter the ans for question "<<k+1<<endl;
cin>>a[k];
}
for(int k=0; k<20; k++)
{
if(a[k] == ans[k])
correct++;
else
{
incorrect++;
q[k] = k+1;
}
}
if(correct >= 15)
result = "passed";
else if(incorrect >= 5)
result = "failed";
cout<<endl<<"You have "<<result<<" in the exam."<<endl;
cout<<"Correctly answered questions "<<correct<<endl;
cout<<"Incorrectly answered questions "<<incorrect<<endl;
cout<<"Incorect questions are "<<endl;
cout<<"\t";
for(int k=0; k<20; k++)
{
// 0 indicates correct question
if(q[k] == 0)
continue;
else
cout<<k+1<<"\t";
}
}
OUTPUT
Enter the ans for question 1
A
Enter the ans for question 2
A
Enter the ans for question 3
A
Enter the ans for question 4
A
Enter the ans for question 5
A
Enter the ans for question 6
A
Enter the ans for question 7
A
Enter the ans for question 8
A
Enter the ans for question 9
A
Enter the ans for question 10
A
Enter the ans for question 11
A
Enter the ans for question 12
A
Enter the ans for question 13
A
Enter the ans for question 14
A
Enter the ans for question 15
A
Enter the ans for question 16
D
Enter the ans for question 17
D
Enter the ans for question 18
D
Enter the ans for question 19
D
Enter the ans for question 20
D
You have failed in the exam.
Correctly answered questions 6
Incorrectly answered questions 14
Incorect questions are
1 2 5 7 9 10 11 12 13 15 16 17 18 20
NOTE:
The answers are stored in upper case. This program may not accept answers in lower case.