Part II – C++ and Functions – Math Test MUST BE IN C++ Critical Review   A value-returning function is a function that returns a value back to the part of the program that called it.  In C++, you can use value-returning functions and those that do not.    y = sqrt(x);                    // value returning function printBonus(stAmount, empAmount);// function returns no value   Standard Library Functions C++ comes with a standard library of functions that have already been written for you. These functions, known as library functions, make a programmer’s job easier because they perform many of the tasks that programmers commonly need to perform.   The rand Function In order to use the random function in C++, you must include library.  You also should provide a random seed in order to get a random sequence every time you run the program by using library.  To do this, simply add the following line to the top of your code: #include #include      Add the following statement in main before using the rand() function:      srand(static_cast(time(0)));   The rand() function typically returns a number between 0 and 32767.  The following is how you would get a random number between 1 and 6.   value = rand() % 6 + 1;       Write a program that will allow a student to enter their name and then ask them to solve 5 mathematical equations.  The program should display two random numbers that are to be added, such as:     247 + 129   The program should allow the student to enter the answer.  The program should then display whether the answer was right or wrong and accumulate the correct values.  After the 5 questions are asked, display the student name and the number correct.   In addition to any library functions you may use, you might consider the following functions: A function that allows the student to enter their name. A function that generates two random numbers, anywhere from 1 to 500. A function that displays the equation and asks the user to enter their answer. A function that calculates the results. A function that displays the student name and the number right.   Your sample output might look as follows (random numbers will be different):   Enter student name: Katie Equation is 424 + 28 Enter the sum: 472 Wrong Equation is 163 + 233 Enter the sum: 396 Right Etc…(through 5 iterations) Information for Katie The number right:  3   The Pseudocode   Module main()             //Declare local variables             Declare Integer counter             Declare String studentName             Declare Integer right = 0             Declare Integer number1             Declare Integer number2             Declare Integer answer             Call srand(time(0))                                // to generate random sequence each time             Set studentName = inputName()             //Loop to run program again             For counter  = 1 to 5                         //calls functions Call generateNumbers(number1, number2) Set answer = getAnswer(number1, number2)                         If answer == number1 + number2 then                                     Display “Right”                                     Set right = right + 1                         Else                                     Display “Wrong”                         End If             End For             Call displayInfo(right, studentName) End Module Function String inputName() Declare String name             Display “Enter student name: ”             Input name             Return name     End Function Module generateNumbers(Integer Ref number1, Integer Ref number2)             Set number1 = rand() % 500 + 1             Set number2 = rand() % 500 + 1 End Module Function Integer getAnswer(Integer number1, Integer number2)             Declare Integer answer             Display “Equation is ”, number1, “+”, number2             Display “Enter the sum: ”             Input answer             Return answer End Function Module displayInfo(Integer right, String studentName)             Display “Information for ”, studentName             Display “The number right:”, right End Module   When your code is complete and runs properly, capture the output.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Part II – C++ and Functions – Math Test

MUST BE IN C++

Critical Review

 

A value-returning function is a function that returns a value back to the part of the program that called it.  In C++, you can use value-returning functions and those that do not. 

 

y = sqrt(x);                    // value returning function

printBonus(stAmount, empAmount);// function returns no value

 

Standard Library Functions

C++ comes with a standard library of functions that have already been written for you. These functions, known as library functions, make a programmer’s job easier because they perform many of the tasks that programmers commonly need to perform.

 

The rand Function

In order to use the random function in C++, you must include <cstdlib> library.  You also should provide a random seed in order to get a random sequence every time you run the program by using <ctime> library.  To do this, simply add the following line to the top of your code:

#include <cstdlib>

#include <ctime>  

 

Add the following statement in main before using the rand() function:

     srand(static_cast<unsigned int>(time(0)));

 

The rand() function typically returns a number between 0 and 32767.  The following is how you would get a random number between 1 and 6.

 

value = rand() % 6 + 1;

 

 

 

Write a program that will allow a student to enter their name and then ask them to solve 5 mathematical equations.  The program should display two random numbers that are to be added, such as:

 

  247 + 129

 

The program should allow the student to enter the answer.  The program should then display whether the answer was right or wrong and accumulate the correct values.  After the 5 questions are asked, display the student name and the number correct.

 

In addition to any library functions you may use, you might consider the following functions:

  • A function that allows the student to enter their name.
  • A function that generates two random numbers, anywhere from 1 to 500.
  • A function that displays the equation and asks the user to enter their answer.
  • A function that calculates the results.
  • A function that displays the student name and the number right.

 

Your sample output might look as follows (random numbers will be different):

 

Enter student name: Katie<Enter>

Equation is 424 + 28

Enter the sum: 472<Enter>

Wrong




Equation is 163 + 233

Enter the sum: 396<Enter>

Right




Etc…(through 5 iterations)




Information for Katie

The number right:  3

 

The Pseudocode

 

Module main()

            //Declare local variables

            Declare Integer counter

            Declare String studentName

            Declare Integer right = 0

            Declare Integer number1

            Declare Integer number2

            Declare Integer answer




            Call srand(time(0))                                // to generate random sequence each time

            Set studentName = inputName()




            //Loop to run program again

            For counter  = 1 to 5

                        //calls functions

Call generateNumbers(number1, number2)

Set answer = getAnswer(number1, number2)

                        If answer == number1 + number2 then

                                    Display “Right”

                                    Set right = right + 1

                        Else

                                    Display “Wrong”

                        End If

            End For




            Call displayInfo(right, studentName)

End Module







Function String inputName()

Declare String name

            Display “Enter student name: ”

            Input name

            Return name    

End Function




Module generateNumbers(Integer Ref number1, Integer Ref number2)

            Set number1 = rand() % 500 + 1

            Set number2 = rand() % 500 + 1

End Module




Function Integer getAnswer(Integer number1, Integer number2)

            Declare Integer answer

            Display “Equation is ”, number1, “+”, number2

            Display “Enter the sum: ”

            Input answer

            Return answer

End Function




Module displayInfo(Integer right, String studentName)

            Display “Information for ”, studentName

            Display “The number right:”, right

End Module


 

When your code is complete and runs properly, capture the output.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education