Question

In: Computer Science

Write a program in C to grade an n-question multiple-choice exam (for n between 5 and...

Write a program in C to grade an n-question multiple-choice exam (for n between 5 and 20) and provide feedback about the most frequently missed questions. Your program will use a function scan_exam_data to scan and store the exam data in an appropriate data structurer. Use file redirection to input data – do not use fopen() in your code. The first line of input contains the number of students. Second line is number of questions on the exam followed by a space and then an n-character string of the correct answers. Each of the lines that follow contain an integer student ID followed by a space and then the student answers.


Sample Input

3

5 dbbac

111 dabac

102 dcbdc

251 dbbac


Your program then uses a function analyze_data to calculate each student’s score as a percentage and the number of each missed questions in the exam. A function print_data will be called to produce an output, containing the answer key, each student’s ID, each student’s score as a percentage, and information about how many students missed each question.


Sample Output

Exam Report

Students 3

Question 1 2 3 4 5

Answer d b b a c

ID Score(%)

111 80

102 60

251 100

Question 1 2 3 4 5

Missed by 0 2 0 1 0


Error checking
You will have to perform some error checks while the program is being running. However, these error checks will not cause the program to terminate – except if you have a corrupted file. Your program should print error messages when appropriate. Here is a list that need to be checked: Illegal inputs like the number of questions must be between 5-20 and key answers must be lower-case letters.

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<stdio.h>

void scan_exam_data(int stud_ids[], char stud_answers[][20], int no_students);

void analyze_data(char correct_ans[], char stud_answers[][20], int no_students, int no_questions, int perc[], int misses[]);

void print_data(int stu_ids[], char correct_ans[], int no_studs, int no_ques, int perc[], int misses[]);

int main(){

    int no_students, no_questions, i;

    char correct_answers[21];

    scanf("%d", &no_students);

    scanf("%d %s", &no_questions, correct_answers);

    int stud_ids[no_students];

    char stud_answers[no_students][no_questions+1];

    int percentage[no_students];

    int misses[no_questions];

    for(i=0; i<no_students; i++)

        stud_ids[i] = 0;

    for(i=0; i<no_questions; i++)

        misses[i] = 0;

    scan_exam_data(stud_ids, stud_answers, no_students);

    analyze_data(correct_answers, stud_answers, no_students, no_questions, percentage, misses);

    print_data(stud_ids, correct_answers, no_students, no_questions, percentage, misses);

    return 0;

}

void scan_exam_data(int stud_ids[], char stud_answers[][20], int no_students){

    int i;

    for(i=0; i<no_students; i++){

        scanf("%d %s", &stud_ids[i], stud_answers[i]);

    }

}

void analyze_data(char correct_ans[], char stud_answers[][20], int no_students, int no_questions, int perc[], int misses[]){

    int i, j;

    for(i=0; i<no_students; i++){

        int correct = 0;

        for(j=0; j<no_questions; j++){

            if(correct_ans[j]==stud_answers[i][j])

                correct++;

            else

                misses[j]++;

        }

        perc[i] = ((double)correct/no_questions)*100;

    }

}

void print_data(int stu_ids[], char correct_ans[], int no_studs, int no_ques, int perc[], int misses[]){

    int i;

    printf("Exam Report\n");

    printf("Students %d\n", no_studs);

    printf("Question");

    for(i=1; i<=no_ques; i++)

        printf(" %d", i);

    printf("\nAnswer");

    for(i=0; i<no_ques; i++)

        printf(" %c", correct_ans[i]);

    printf("\n\nID\tScore(%%)\n");

    for(i=0; i<no_studs; i++){

        printf("%d %d\n", stu_ids[i], perc[i]);

    }

    printf("\nQuestion");

    for(i=1; i<=no_ques; i++)

        printf(" %d", i);

    printf("\nMissed by");

    for(i=0; i<no_ques; i++)

        printf(" %d", misses[i]);

    printf("\n");

}


Related Solutions

. Write a C program that asks the user a multiple-choice question and shows four possible...
. Write a C program that asks the user a multiple-choice question and shows four possible answers, (a) through (d). Prompt the user to input a response as a character. If the user enters the correct response, print a message stating that the answer is correct. If the user enters an incorrect response, print a message stating that the answer is wrong. If the user enters anything other than the letters a, b, c, or d, print a message stating...
There are 100 multiple-choice question on exam, each having responses a, b, c, d. Suppose that...
There are 100 multiple-choice question on exam, each having responses a, b, c, d. Suppose that a student has a 70% chance to answer each question correctly, and all the answers are independent. If the student needs to answer at least 40 questions to pass, what is the probability that the student passes? Use normal approximation.
In a multiple choice exam, there are 7 questions and 4 choices for each question (a,...
In a multiple choice exam, there are 7 questions and 4 choices for each question (a, b, c, d). Nancy has not studied for the exam at all and decides to randomly guess the answers. What is the probability that: (please round all answers to four decimal places) a) the first question she gets right is question number 3? b) she gets all of the questions right? c) she gets at least one question right?
Write a shell script of the following: “A Multiple Choice Question that contains 5 questions and...
Write a shell script of the following: “A Multiple Choice Question that contains 5 questions and each question carries 2 options. Choice will be given by the students. A record file is created each time the script runs to store the answers along with the total marks obtained. The record filename that has date and timing information as well as the student name.
Ann has taken a multiple-choice exam consisting of 25 questions. Each question has 5 choices of...
Ann has taken a multiple-choice exam consisting of 25 questions. Each question has 5 choices of which only one is the correct answer. Ann has correctly answered 9 questions. We would like to test if Ann is doing better than randomly guessing the answer to each question. Define the parameter to be tested. State the alternative hypothesis.                                                                         _____________ Compute the test statistic.                                                                                   _____________ Compute the p-value.                                                                                            ____________ At the 1% level of significance, state your conclusion.
Write a C++ program to read in various types of test questions (multiple choice and True/False)...
Write a C++ program to read in various types of test questions (multiple choice and True/False) from a test bank (text file), and load the questions into an array of questions. You will need to implement the following class hierarchy (given in UML): Once the test bank has been loaded, simply iterate over the array of questions and have each question printed out to the screen. The test bank (text file) will have the following format: Line 1 will be...
Write a C# program using Repl.it that asks the user for a numeric grade between 0...
Write a C# program using Repl.it that asks the user for a numeric grade between 0 and 100, and displays a letter grade using the following conversion table: Numeric grade   Letter grade 90 < grade <= 100 A 80 < grade <= 90 B 70 < grade <= 80 C 60< grade <= 70 D grade <= 0.0 F Don’t forget the comments in your code. The output should be similar to: Enter the test score: 87 The letter grade...
Question: How do I write a program in C# that calculates a student's final grade for...
Question: How do I write a program in C# that calculates a student's final grade for a test with 20 multiple questions using arrays and helper methods? Instructions: (0-incorrect answer, 1-correct answer) If the student answered the question right, add .5 points to the running total. If the student didn’t answer correctly subtract .5 points from the running total. The running total is initialized with 5 points (so the student receives 5 points extra credit). To define the final grade...
n-class: Write a program to store exam scores into a file. The program will ask the...
n-class: Write a program to store exam scores into a file. The program will ask the user how many exam scores to enter. Then it will ask the user for each exam score and store them in a file called scores.dat The file output should have the following format . Exam 1: 97 Exam 2: 85 C++ Coding please
Ada Nixon, a student, has just begun a 30-question, multiple-choice exam. For each question, there is...
Ada Nixon, a student, has just begun a 30-question, multiple-choice exam. For each question, there is exactly one correct answer out of four possible choices. Unfortunately, Ada hasn't prepared well for this exam and has decided to randomly select an answer choice for each question. (a) (4 points) For a given question, what is the probability Ada picks the correct answer, assuming each answer choice is equally likely to be selected? (b) Assume the number of questions Ada answers correctly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT