Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ using class and header file For this assignment, you will create a main.cpp file and a randomnumbers.h header file. A class will be

In C++ using class and header file

For this assignment, you will create a main.cpp file and a randomnumbers.h header file. A class will be defined in the header file (described below). Instances of the class (objects) will be used in main to perform the specified random number generation, calculations, and the results will be printed out (explained below). You will also be using vectors in this assignment.

Your program should run as follows: first, the user will be asked to enter a lower bound, an upper bound, and a quantity n. The class will then be used to generate n random numbers in the range [lowerupper]. After this, the average (mean), max, and min will be calculated (in a separate function from the generator), and then another function (print) will print out the lower, upper bounds, n, and the average, max, and min. The user will then be asked if they wish to go again (with possibly new values).

1. Create a header file named randomnumbers.h. Define a class named RandNum. Create private variables (they wont be all of the same type) for n, lower, upper, average, max, min, and vector numbers. Define public functions RandInput, RandGen, RandCalc, Print.

The RandInput function should set the values of lower,upper, and n (based on the user input in main).

The RandGen function should first initialize the vector using: numbers.resize(0); then proceed to generate n random numbers in the range [lowerupper] and store each number in the vector (since the vector does not have a predefined size you will have to use push_back i.e. numbers.push_back(randvalue) to store the values). Dont calculate the average, max, and min here (part of this assignment is to make sure you can use vectors).

RandCalc should loop through the vector (use numbers.size() as the loop bound and the denominator in the average calculation) and calculate the average(mean), max, and min values and store them in the private variables.

Print should print out what the user entered as the lower, and upper bounds, the amount of numbers generated, and then the average, max, and min.

2. Create a main.cpp. Make sure you include the necessary header files. Declare an object of class RandNum. Then, within a while loop, ask the user for the lower, upper, and amount, then use the function RandInput to set the values , and then the 3 other public member functions are executed in order. Make sure you ask the user if they want to go again (this is why you have to initialize the vector to size 0 in RandGen).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions