Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem #1 (Random Sequence) Create a class that returns a random number from the following set, {16,33,56,77,126}. Loop 100,000 times with this procedure and print

Problem #1 (Random Sequence)

Create a class that

returns a random number from the following set,

{16,33,56,77,126}. Loop 100,000 times with this

procedure and print the frequency of each of the

5 numbers obtained. The following is the

specification for the class.

Specification

class Prob1Random

{

private:

char *set; //The set of numbers to draw random numbers from

char nset; //The number of variables in the sequence

int *freq; //Frequency of all the random numbers returned

int numRand; //The total number of times the random number function is called

public:

Prob1Random(const char,const char *); //Constructor

~Prob1Random(void); //Destructor

char randFromSet(void); //Returns a random number from the set

int *getFreq(void) const; //Returns the frequency histogram

char *getSet(void) const; //Returns the set used

int getNumRand(void) const; //Gets the number of times randFromSet has

//been called

};

Driver program to return a random sequence

char n=5;

char rndseq[]={16,33,56,77,126};

int ntimes=100000;

Prob1Random a(n,rndseq);

for(int i=1;i<=ntimes;i++)

{

a.randFromSet();

}

int *x=a.getFreq();

char *y=a.getSet();

for(int i=0;i

{

cout<

}

cout<<"The total number of random numbers is "<

Sample Output

16 occured 20045 times

33 occured 19952 times

56 occured 20035 times

77 occured 20039 times

126 occured 19929 times

The total number of random numbers is 100000

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

define EFFECTIVE PARTICIPATION

Answered: 1 week ago