Knowee
Questions
Features
Study Tools

Task B builds upon the code from Task A. Submit the source code as arithmetic2.cpp.1. Enter the number of questions to answer. Ensure that the input is a positive integer. Continueprompting users with “The number of questions cannot be zero or negative. Re-enter: ” and acceptinput from users until a positive integer is provided.2. Utilize the code from Task A to generate questions involving addition (+), subtraction (-), multipli-cation (*), division (/), and remainder (%), with operands restricted to single-digit integers.3. Calculate and print the correctness percentage.4. If the percentage is 90 or higher, print ’A’; if it’s 80 or higher, print ’B’; if it’s 70 or higher, print ’C’;if it’s 60 or higher, print ’D’; otherwise, print ’F’

Question

Task B builds upon the code from Task A. Submit the source code as arithmetic2.cpp.1. Enter the number of questions to answer. Ensure that the input is a positive integer. Continueprompting users with “The number of questions cannot be zero or negative. Re-enter: ” and acceptinput from users until a positive integer is provided.2. Utilize the code from Task A to generate questions involving addition (+), subtraction (-), multipli-cation (*), division (/), and remainder (%), with operands restricted to single-digit integers.3. Calculate and print the correctness percentage.4. If the percentage is 90 or higher, print ’A’; if it’s 80 or higher, print ’B’; if it’s 70 or higher, print ’C’;if it’s 60 or higher, print ’D’; otherwise, print ’F’

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a step-by-step guide on how to complete the task:

  1. First, you need to prompt the user to enter the number of questions they want to answer. You can use a do-while loop to keep asking for input until the user enters a positive integer. You can use the cin function to get the user's input and the cout function to display the error message if the input is not a positive integer.

  2. Next, you need to generate the questions. You can use the code from Task A as a base and modify it to include all the required operations (+, -, *, /, %). You can use the rand function to generate random single-digit integers and random operations. Make sure to handle the division and remainder operations carefully to avoid division by zero errors.

  3. After the user has answered all the questions, you need to calculate the correctness percentage. You can do this by dividing the number of correct answers by the total number of questions and multiplying the result by 100.

  4. Finally, you need to print the grade based on the correctness percentage. You can use a series of if-else statements to check the percentage and print the corresponding grade. Make sure to start from the highest grade and go down to the lowest grade in your if-else statements to ensure that the correct grade is printed.

Here is a rough outline of how your code might look:

#include <iostream>
#include <cstdlib>
#include <ctime>

int main() {
    srand(time(0)); // seed the random number generator

    int numQuestions;
    do {
        std::cout << "Enter the number of questions: ";
        std::cin >> numQuestions;
        if (numQuestions <= 0) {
            std::cout << "The number of questions cannot be zero or negative. Re-enter: ";
        }
    } while (numQuestions <= 0);

    int numCorrect = 0;
    for (int i = 0; i < numQuestions; i++) {
        // generate and ask a question, increment numCorrect if the answer is correct
    }

    double correctness = (double)numCorrect / numQuestions * 100;
    std::cout << "Correctness: " << correctness << "%\n";

    if (correctness >= 90) {
        std::cout << 'A';
    } else if (correctness >= 80) {
        std::cout << 'B';
    } else if (correctness >= 70) {
        std::cout << 'C';
    } else if (correctness >= 60) {
        std::cout << 'D';
    } else {
        std::cout << 'F';
    }

    return 0;
}

Please note that this is just a rough outline. You will need to fill in the details yourself, especially the part where you generate and ask the questions.

This problem has been solved

Similar Questions

2 Task BTask B builds upon the code from Task A. Submit the source code as arithmetic2.cpp.1. Enter the number of questions to answer. Ensure that the input is a positive integer. Continueprompting users with “The number of questions cannot be zero or negative. Re-enter: ” and acceptinput from users until a positive integer is provided.2. Utilize the code from Task A to generate questions involving addition (+), subtraction (-), multipli-cation (*), division (/), and remainder (%), with operands restricted to single-digit integers.3. Calculate and print the correctness percentage.4. If the percentage is 90 or higher, print ’A’; if it’s 80 or higher, print ’B’; if it’s 70 or higher, print ’C’;if it’s 60 or higher, print ’D’; otherwise, print ’F’.Here is a sample run: Enter the total number of questions to ask: -2The number of questions cannot be zero or negative. Re-enter: -1The number of questions cannot be zero or negative. Re-enter: 32(1) what is 1 / 2? 0true(2) what is 8 - 0? 8true(3) what is 5 - 5? 1falsepercentage correct: 66.6667%letter grade: D Here is another sample run: 1 Enter the total number of questions to ask: -12 The number of questions cannot be zero or negative. Re-enter: -23 The number of questions cannot be zero or negative. Re-enter: -34 The number of questions cannot be zero or negative. Re-enter: 556 (1) what is 4 - 0? 47 true89 (2) what is 2 / 3? 0.666710 false1112 (3) what is 9 * 7? 6313 true1415 (4) what is 7 - 7? 016 true1718 (5) what is 5 * 4? 2019 true2021 percentage correct: 80%22 letter grade: B Warning: To pass gradescope, the prompts must be exact matches.The prompt for percentage must be percentage correct: followed by a percentage number, ended with%.The prompt for letter grade must be letter grade: .3 Task CRead a csv (Command-Separated Values) file containing arithmetic expressions and their correspondinganswers, generate questions and answer them, calculate and report the correct rate. Based on the correctpercentage, print the corresponding letter grade.For example, consider the following CSV file. Each row contains items separated by commas, wherethe first item represents an arithmetic expression, and the second item is the corresponding answer for3that expression. 1 (3 + 2) % 2,12 3 + 2 % 2,33 1 + 3 % 2,24 1 + 4 % 2,15 1 + 4 / 2,36 1 / 2 * 3,07 1.0 / 2 * 3,1.58 1 / 2 * 3.0,09 1 / 2.0 * 3,1.5 A sample run of the code is as follows. 1 (1) what is (3 + 2) % 2? 12 true34 (2) what is 3 + 2 % 2? 35 true67 (3) what is 1 + 3 % 2? 28 true910 (4) what is 1 + 4 % 2? 111 true1213 (5) what is 1 + 4 / 2? 314 true1516 (6) what is 1 / 2 * 3? 017 true1819 (7) what is 1.0 / 2 * 3? 1.520 true2122 (8) what is 1 / 2 * 3.0? 023 true2425 (9) what is 1 / 2.0 * 3? 1.526 true2728 percentage correct: 100%29 letter grade: A

Enter the number of questions to answer. Ensure that the input is a positive integer. Continueprompting users with “The number of questions cannot be zero or negative. Re-enter: ” and acceptinput from users until a positive integer is provided.2. Utilize the code from Task A to generate questions involving addition (+), subtraction (-), multipli-cation (*), division (/), and remainder (%), with operands restricted to single-digit integers.3. Calculate and print the correctness percentage.4. If the percentage is 90 or higher, print ’A’; if it’s 80 or higher, print ’B’; if it’s 70 or higher, print ’C’;if it’s 60 or higher, print ’D’; otherwise, print ’F’.

Problem StatementPriya is fascinated by maths and wants to calculate the value for the given expression: ++a * ++b / a. The program takes these 2 values as input, calculates the expression, and displays the result.Can you help her by writing a program?Input format :The first line consists of a integer value a, representing the first value.The second line consists of a integer value b, representing the second valueOutput format :The output displays a result as integer.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1<=a<=10001<=b<=1000Sample test cases :Input 1 :44Output 1 :5Input 2 :105Output 2 :6Input 3 :120500Output 3 :501

Assignment operatorsYou want to withdraw some money from your bank account.The program takes two numbers as input, your account balance and the amount you want to withdraw, and assigns them to corresponding "balance" and "withdraw" variables.TaskCalculate and output the remaining balance after the withdrawal.Sample Input4500009000Sample Output441000ExplanationThe first two lines of the given code declare the balance and the withdraw variables, whose values will be automatically taken as input and will be used in test cases. This means that your solution will be tested with different values of those variables.Don't change that part of the code and treat it as a usual variable.Use the -= shorthand for easier calculation.

Write a program that does basic arithmetic operations (addition, subtraction, multiplication,and division). The inputs to the program are two numbers (in double format) and theoperation required. Provide a function for each operation and the identifiers for addition,subtraction, multiplication, and division are ‘+’, ‘-‘, ‘*’, and ‘/’ respectively.

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.