Question

Hi I need some help in C programing class and I doing one of the exercise...

Hi I need some help in C programing class and I doing one of the exercise so that I can get better at coding.

Suppose you are asked to design a software that helps an elementary school student learn multiplication and division of one-digit integer numbers. The software allows the student to select the arithmetic operation she or he wishes to study. The student chooses from a menu one of two arithmetic operations: 1) Multiplication and 2) Division (quotient). Based on the student choice, the software tests the user with exactly 10 questions. For each question, two random positive one-digit integers are generated; then the student is asked to enter the answer for the arithmetic operation.
The software displays a message “Congratulations!” if more that 7 questions are answered correctly otherwise, the program should display "Please ask your teacher for help!".
The Challenge
Design the software system with the following separate sub-programs (You may define additional sub-programs if needed):
1. A sub-program (called print_Menu()) that prints the operations menu and returns the user selection as integer value. The sub-program loops until the user enters a valid choice .
int print_Menu();
2. A sub-program (called run_Test()) to execute the arithmetic test. The sub-program receives references to three arrays (x, y, and answers that will store the randomly generated numbers and the user’s answers and also receives an integer that represents
the required operation from the main function (1 for multiplication and 2 for division). The sub-program then gets the student to answer 10 questions as follows:
a. Randomly generates two positive one-digit integers,
b. Stores the two numbers in the two arrays,
c. Ask the student to enter the answer for the arithmetic operation of the two numbers,
d. Stores the user’s answer in the third array.

The sub-program has the following prototype:
void run_Test(int x[], int y[], int answers[], int operation, int size)
3. A sub-program (called Print_Summary()) that prints out a summary table for the questions and answers. The table should also indicate the incorrect answers. The subprogram returns the number of correct answers.
int Print_Summary(int x[], int y[], int answers[], int operation, int size)
4. The main program consists of a loop that controls the overall process, i.e., prints the main menu and get a user selection by calling print_Menu(), run the test by calling
run_Test(), print a summary of the test by calling print_Summary(), and prints the confirmation message to the user (“Congratulations!” or “Please ask your teacher for help!”)). In the selection menu, allow the user to terminate the program.
Here is an example of the designed software output (see next page):

This software tests you with 10 questions ……
1) Multiplication
2) Division
3) Exit
Please make a selection (1–3): 1
Please give the answers to the following additions:
5 x 4 = 20
1 x 8 = 8
2 x 3 = 6
9 x 9 = 77
4 x 2 = 8
3 x 7 = 21
2 x 2 = 4
8 x 5 = 40
9 x 2 = 18
1 x 1 = 1
Exam summary:
5 x 4 = 20 – correct answer
1 x 8 = 8 – correct answer
2 x 3 = 6 – correct answer
9 x 9 = 77 – Incorrect answer – the answer is 81
4 x 2 = 8 – correct answer
3 x 7 = 21 – correct answer
2 x 2 = 4 – correct answer
8 x 5 = 40 – correct answer
9 x 2 = 18 – correct answer
1 x 1 = 1 – correct answer
Congratulations! You scored 9/10.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the complete program as per the requirements. It is well explained inside the code using comments.

#include <stdio.h>
#include <stdlib.h>

// function definitions
int print_Menu();
void run_Test(int x[], int y[], int answers[], int operation, int size);
int Print_Summary(int x[], int y[], int answers[], int operation, int size);

// main function
int main()
{
   int size = 10;   // size of arrays
   int x[10], y[10], answers[10];   // arrays for questions and answers
   int operation;   // operation
   int selection;   // selection
   int correctAnswers;   // correct answers

   // keep continuing run the test until user chose to exit
   // call function to get user selection
   selection = print_Menu();
  
   while (selection != 3)
   {
       // run test
       run_Test(x, y, answers, selection, size);

       // print summary
       correctAnswers = Print_Summary(x, y, answers, selection, size);

       // display message according to correct answers
       if (correctAnswers > 7)
           printf("Congratulations! ");
       else
           printf("Please ask your teacher for help! ");
       printf("You scored %d/%d.\n\n", correctAnswers, size);

       // call function to get user selection
       selection = print_Menu();
   }

   return 0;
}

// prints the operations menu and returns the user selection as integer value
int print_Menu()
{
   int selection;   // to store the user selection

   // keep asking until user enters a correct input
   do{
       // display the menu and read the user selection
       printf("This software tests you with 10 questions ......\n");
       printf("1) Multiplication\n");
       printf("2) Division\n");
       printf("3) Exit\n");
       printf("Please make a selection (1-3): ");
       scanf("%d", &selection);
   } while ((selection < 1 || selection > 3));

   // returns selection
   return selection;
}

// run the test
void run_Test(int x[], int y[], int answers[], int operation, int size)
{
   int i;
   int num1, num2;   // two operands
   int userAnswer;   // user answer
   char op;   // to store the operator

   // set the operator on the basis of operation
   printf("\nPlease give the answers to the following ");
   if (operation == 1)
   {
       op = 'x';
       printf("multiplications:\n");
   }
   else
   {
       op = '/';
       printf("divisions:\n");
   }

   // run test size times
   for (i = 0; i < size; i++)
   {
       // get random numbers
       num1 = rand() % 9 + 1;
       num2 = rand() % 9 + 1;

       // display multiplication or division as per the operation
       printf("%d %c %d = ", num1, op, num2);
       scanf("%d", &userAnswer);

       // set num1, num2 and userAnswer in arrays
       x[i] = num1;
       y[i] = num2;
       answers[i] = userAnswer;
   }
}

// prints the summary
int Print_Summary(int x[], int y[], int answers[], int operation, int size)
{
   int i;
   int correctCount = 0;   // to keep track of correct answers
   int correctAnswer = 0;       // correct answer

   printf("\nExam summary:\n");
   // loop to print the summary
   for (i = 0; i < size; i++)
   {
       // get correct answer
       if (operation == 1)
       {
           correctAnswer = x[i] * y[i];
           // print operation
           printf("%d x %d = %d - ", x[i], y[i], answers[i]);
       }
       else
       {
           correctAnswer = x[i] / y[i];
           // print operation
           printf("%d / %d = %d - ", x[i], y[i], answers[i]);
       }

       // check if user's answer is correct
       if (answers[i] == correctAnswer)
       {
           printf("correct answer\n");
           correctCount++;
       }
       else
       {
           // if incorrect, display the correct answer
           printf("Incorrect answer - the answer is %d\n", correctAnswer);
       }
   }

   // return the number of correct answers
   return correctCount;
}

Below is the sample output:

This completes the requirement. Let me know if you have any queries.

Thanks!

Add a comment
Know the answer?
Add Answer to:
Hi I need some help in C programing class and I doing one of the exercise...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • Programming Fundamental (C++) Lab C++ Lab Ra'fat Amareh Faculty of Engineering and Information Technology Assignment Write...

    Programming Fundamental (C++) Lab C++ Lab Ra'fat Amareh Faculty of Engineering and Information Technology Assignment Write a C++ program that performs the following: Prints on screen a selection menu as follow: a. Sin (x), Series b. Sum odd digit, Print Digits, Print Shape c. Array d. Exit If user presses a or A, the following sub menu should be displayed 1- Sin (x) (Program should solve the following series x - x'/3! + x®/5! – x/7...x"m!) 2- F (Program should...

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • import random def doTest(operation): ## complete your work here ##    # return True for now...

    import random def doTest(operation): ## complete your work here ##    # return True for now return True    responsesCorrect = 0 print("The software will process a test with 10 questions …… ") for compteur in range (10): operation = random.randint(0,1) if doTest(operation) == True: responsesCorrect += 1 print(responsesCorrect, "Correct responses")    if responsesCorrect <= 6 : print("Ask some help from your instructor.") else: print("Congratulations!") Requirement: You must use the format provided below and then complete the fill! Python! Thanks!...

  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • In this lab you will code a simple calculator. It need not be anything overly fancy,...

    In this lab you will code a simple calculator. It need not be anything overly fancy, but it is up to you to take it as far as you want. You will be creating this program in three small sections. You have the menu, the performance of the basic arithmetic operations (Addition, Subtraction Multiplication, and Division), and the looping. You may want to get the switch menu working first, and then fill in the code for these four arithmetic operations...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • Python: Write a code to ask a number (one digit) from the user and prints the...

    Python: Write a code to ask a number (one digit) from the user and prints the respective row of the multiplication table. For example, if the user enters 5, the following lines will be printed. Note that, if the user enters any number outside the range of 1-9, the program should display an error message. 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25...

  • CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c...

    CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c that implements the following features. Implement this program in stages using stepwise refinement to ensure that it will compile and run as you go. This makes it much easier to debug and understand. This program presents the user a menu of operations that it can perform. The choices are listed and a prompt waits for the user to select a choice by entering a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT