Question

In: Computer Science

In C++ Write a program that will conduct a quiz consists of 10 arithmetic questions and...

In C++

Write a program that will conduct a quiz consists of 10
arithmetic questions and display the final score as ‘Your score in the quiz is X’ with a
response message in the next line. A response message will be as follows based on the student’s
performance:
a. Number of correct answers >= 9: Excellent, your are passed with ‘A’ grade!
b. Number of correct answers >= 7, but less than 9: Very Good, you are passed with
‘B’ grade!
c. Number of correct answers >= 5, but less than 7: Good, you are passed with ‘C’
grade!
d. Number of correct answers < 5: Sorry, we cannot pass you in the quiz!

For generating a question, you need to write a generateQuestion() function that will generate
a question.. In addition to generate the numbers randomly, the function should randomly select the operator among +, -, and * operators. If the operator is + or -, the numbers should be double-digit. For * operator, the numbers should be single-digit. The function should also compute the answer for the question to compare it with the student’s answer. If the answer is correct, the function returns 1, otherwise 0. Your main() function should call this
function.

Solutions

Expert Solution

RAW CODE

#include <iostream>

using namespace std;

int generateQuestion(){
        char Operator = "-+*"[rand() % 3]; //Choose random character from index 0,1,2
        int num1,num2,answer,student_answer;
        if(Operator == '*'){ // Check for Operator. (IF '*' THEN GO INSIDE LOOP)
            num1 = rand() % 10; //Random number from 0-9 i.e. one digit number only
            num2 = rand() % 10;
            answer =  num1*num2;
        }
        else{ // Check for Operator. (IF '+-' OR NOT '*' THEN GO INSIDE LOOP)
            num1 = 10 + rand() % 90; //Random number from 10-99 i.e. two digit number only
            num2 = 10 + rand() % 90;
            if(Operator == '+'){ // If '+' then go inside loop
                answer = num1 + num2;
            }
            else{ // If '-' then go inside loop
                answer = num1 - num2;
            }
        }
            cout<<num1<<Operator<<num2<<"=";
            cin>>student_answer;
            if(answer == student_answer){
                return 1; // If Right Answer then return 1
            }
            else{
                return 0; // If Wrong Answer then return 0
            }}

int main()
{
    srand(time(0)); // This will help generate random expressions every single time
    int count = 0,points;
    cout<<"QUIZ\n\n";
    for(int i=0; i<10; i++){ // Loop 10 times. i.e 10 Questions
    points = generateQuestion(); // Calling function
    count += points;
    }
    if(count >= 9){
        cout<<"Excellent, your are passed with ‘A’ grade!\n";
    }
    else if(count >= 7 && count <9){
        cout<<"Very Good, you are passed with ‘B’ grade!\n";
    }
    else if(count >= 5 && count <7){
        cout<<"Good, you are passed with ‘C’ grade!\n";
    }
    else{
        cout<<"Sorry, we cannot pass you in the quiz!\n";
    }

    return 0;
}

SCREENSHOTS (CODE AND OUTPUT)

CODE

OUTPUT

##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####


Related Solutions

in c++ Write a program that can calculate the arithmetic mean, the geometric mean, and the...
in c++ Write a program that can calculate the arithmetic mean, the geometric mean, and the harmonic mean of a set of five numbers. •The program should ask the user to enter fiver numbers, calculate the means, and print all the data to a text file. The program should output the expected results.•Example: The text file should read: For the set of numbers {1,2,3}. The arithmetic mean is 2, the geometric mean is about 1.82, and the harmonic mean is...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented with an infix notation), then outputs this expression in prefix form and also outputs the result of the calculation. The program will first convert the input infix expression to a prefix expression (using the Stack ADT) and then calculate the result (again, using the Stack ADT). The details are provided in the following sections.
Binomial Probabilities A multiple-choice quiz consists of n = 10 questions in the form True or...
Binomial Probabilities A multiple-choice quiz consists of n = 10 questions in the form True or False. Mary assumes that her comprehension level is p = 0.70, so that is the chance that she picks up a right answer. Let M denote a number of questions Mary answered correctly. Suppose that all TEN trials are independent. Answer questions below using answers in the multiple-choice format. No calculation is required here. Just recognize the proper formula for each case. A: (10)...
A Maths quiz consists of 10 questions were given to a group of students. Each question...
A Maths quiz consists of 10 questions were given to a group of students. Each question has 4 choices. Grade A is given to the students managed to get 70% marks and above. According to the compiled data, 45% of students managed to get grade A. (a) What is the probability that exactly 3 of a random sample of 5 the students were grade A? (b) What is the probability that not more than 7 of a random sample of...
Write a complete C++ program that at least consists of the main() function and at least...
Write a complete C++ program that at least consists of the main() function and at least two recursive functions. The first function has no return value and can be named printPrime(). It prints first n prime numbers with proper prompt. Note that number 1 is not regarded as a prime number. We assume the first prime number is 2. The printout should start from 2. The prototype of the recursive function should be void printPrime(int n); The algorithm of printPrime()...
C++ polymorphism. Create a program that issues a quiz through the terminal. The quiz will ask...
C++ polymorphism. Create a program that issues a quiz through the terminal. The quiz will ask a variety of C++ questions to the user and prompt them for a response. The response will differ based on the type of question, such as true or false, multiple-choice, or fill in the blank. Part 1: Designing the Quiz Design this program using a polymorphic vector of questions. Create a Question base class that will serve to point to three different derived classes:...
write a “quiz” program on a topic, about which you are knowledgeable. this quiz can be...
write a “quiz” program on a topic, about which you are knowledgeable. this quiz can be work related, general knowledge or any set of questions where there is a specific answer. ignore questions where long descriptions or general answers needed. the program should display the questions, one at a time, and possible answers, and accept an answer from the user. if the answer is correct, the program should go on to the next question. if it is incorrect, store the...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables...
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables and display the resulting value.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT