Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The local diver\'s license office has asked you to create an application that gr

ID: 3833711 • Letter: T

Question

The local diver's license office has asked you to create an application that grades the written portion of the driver's license exam. The exam has 20 multiple questions. Here are the correct answer: 1. B 2. D 3. A 4. A 5. C 6. A 7. B 8. A 9, C 10. D 11. B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19. D 20. A Your Program should store these correct answers in an array. The program should read the student's answers for each the 20 questions from a text file and store the answers in another array, (Create your own text file test the application.) After the student's answers have been or read from file, 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 questions numbers of the incorrectly answered questions. A local zoo to keep track of how many pounds of food each of the monkey eat each day during a typical week. Write a program that stores this information in a two dimensional 3 times 7 array, where each row represents a different monkey and each column represents a different day of the week. The program should first have the input the data for each monkey. Then it should create a report that includes the following information: Average amount of food eaten per day by the whole family of monkeys The least amount of food eaten during the week by one monkey The greatest amount of food eaten during the week by any one monkey

Explanation / Answer

Here is the code for the first question:

// Driver’s License xam - Check user's answers
#include<iostream>
#include <cctype>
// Required for toupper
using namespace std;
// Function prototypes
void input(char [], int);
void checkAnswers(char[], char[], int &, int &, int);
int main()
{
// Constant for the number of questions
const int ARRAY_SIZE = 20;
// Array of the correct answers
char answers[ARRAY_SIZE] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A' };
// Array to hold the student's replies
char replies[ARRAY_SIZE];
// Accumulator for number of correct answers
int correctAnswers = 0;
// Accumulator for number of incorrect answers
int incorrectAnswers = 0;
// Get the student's replies for each question.
input(replies, ARRAY_SIZE);
// Check the student's replies against the correct answers.
checkAnswers(answers, replies, correctAnswers, incorrectAnswers, ARRAY_SIZE);
// Determine whether the student passed or failed.
if (correctAnswers > 14)
cout << " The student passed the xam. ";
else
cout << " The student failed the xam. ";
// Display the numbers of correct and incorrect
// answers provided by the student.
cout << "Correct Answers: " << correctAnswers << endl;
cout << "Incorrect Answers: " << incorrectAnswers << endl << endl;
// Display a list of the questions that were
// incorrectly answered.
cout << "Questions that were answered incorrectly: ";
for (int i = 0; i < 20; i++)
if (answers[i] != replies[i])
cout << (i + 1) << endl;
//system("pause");
return 0;
}
// ********************************************************
// The input function accepts an array of characters and *
// an integer for the size of the array. The function *
// asks the user to input answers to the xam and stores *
// them in the array.                                    *
// ********************************************************
void input(char array[], int size)
{
for (int i=0; i < size; i++)
{
cout<<"Answer #"<<i+1<<": ";
cin>>array[i];
if(array[i] < 'A' || array[i] > 'D')
{
cout<<"Invalid answer. Try again. ";
i--;
}
}
}
// ********************************************************
// The checkAnswers function compares the values in the *
// answers array to the values in the replies array. The *
// number of correct and incorrect answers are stored in *
// the correct and incorrect reference parameters. *
// ********************************************************
void checkAnswers(char answer[], char replies[], int &correct, int &incorrect, int size)
{
for(int i = 0; i < size; i++)
if(answer[i] == replies[i])
correct++;
else
incorrect++;
}