In: Computer Science
#include <iostream>
using namespace std;
int main()
{
int i=0,c=0,k=0;
int arr[20];//list which will show incorrect answers
char str1[]={'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};//the correct list
char str2[20];//the list of student answers
cin>>str2;
//validating input
while(i<20){
if((str2[i]!='A')&&(str2[i]!='B')&&(str2[i]!='C')&&(str2[i]!='D')){
cout<<"input error at"<<i+1<<"try again";
cin>> str2[i];
}
i++;
}
//comparing the answers
for(i=0;i<20;i++){
if(str1[i]!=str2[i]){
c++;
arr[k]=i+1;
k++;
}
}
if(c>5){
cout<<"Student failed the exam\n";
}
else{
cout<<"Student passed the exam\n";
}
cout<<"The number of correctly answered questions are"<<20-c<<"\n";
cout<<"The number of incorrectly answered questions are"<<c<<"\n";
if(c!=0){
cout<<"list showing number of the incorrectly answered questions\n";
//prints the list of incorrect answered questions
for(i=0;i<k;i++){
cout<<arr[i]<<"\n";
}
}
return 0;
}
Sample output: