Drivers License Exam The local Drivers License Office has as

Driver\'s License Exam The local Driver\'s License Office has asked you to write a program that grades the written portion of the driver\'s license exam. The exam has 20 multiple-choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A Your program should store the correct answers shown above in an array. It should ask the user to enter the student\'s answers for each of the 20 questions, and the answers should be stored in another array. After the student\'s answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions. Input Validation: Only accept the letters A, B, C, or D as answers. IMPORTANT: Your program must display informative messages for both input inquiry and output display. Vague messages and bad display of results will result in losing points.

Solution


% This program is to conduct License Exam

correct_ans = [\'B\',\'D\',\'A\',\'A\',\'C\',\'A\',\'B\',\'A\',\'C\',\'D\',\'B\',\'C\',\'D\',\'A\',\'D\',\'C\',\'C\',\'B\',\'D\',\'A\']; % Correct answers
user_ans = [];
i = 0;
question_num = 20;
wrong_ans = [];
marks = 0;
while (i<question_num) % Reading input from user
option = input(\"Enter your answer ::\\t\",\"s\");
if (length(option) == 1 & (option == \'A\' | option == \'B\' | option ==\'C\' | option == \'D\')) % Validating the answer
user_ans = [user_ans,option];
i = i+1;
else
fprintf(\"This option is not Valid..!!! Please Try again \ \");
end
end

for ind = 1 : question_num % Validating the answers
if (correct_ans(ind) == user_ans(ind))
marks = marks + 1;
else
wrong_ans = [wrong_ans ind];
end
end

if (marks > 15)
disp(\"Congratulations....!! You passed the test.\");
else
disp(\"Sorry..!! U are failed the test\");
end

fprintf(\'\ The total number of correctly answered is : %d\', marks);
fprintf(\'\ The total number of uncorrectly answered is :: %d\', question_num - marks);
disp(\"\ Incorrectly answered question numbers :: \");

if (length(wrong_ans) == 0) % If all answers are right
disp(\" No question is found..!!\")
else
for ind = 1 : length(wrong_ans)
fprintf(\'\\t\\t %d \ \',ind);
end
end

 Driver\'s License Exam The local Driver\'s License Office has asked you to write a program that grades the written portion of the driver\'s license exam. The e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site