The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
In this section, you will modify a function that determines the largest and smallestnumbers that occur in a sequence of seemingly random numbers (the random numbersare generated by using a simple formula). Since the function needs to return two values instead of just one, it is not appropriate to use a pass by value here. You will modify thefunction so that it has two arguments, passed by reference, so that their values can betransmitted back to the main program.Start up a new project for today’s lab. If you are working on one of the classroomlaptops, it’s recommended that you save your project in the Desktop. Download a copyof the file arguments.cpp from Learn and add this file to your project.On line 8 you will see the following comment://NOTE: ADD YOUR NAME AND LAB PARTNER NAME HERE:Replace it with your and your partner’s name. Now take a look at the program.Consider the function smallestRand() defined in this program. This function accepts a(positive) integer n, then generates n random integers, comparing each to the smallestseen so far and continually storing this value in the variable min. Note that min initiallyholds a value larger than the maximum possible random integer, so that there issomething with which to compare subsequent values.Modify smallestRand() so that it also determines the largest value generated, and storesit in a variable called max. (NOTE: Don't create a second loop which generates n morerandom values!)Obviously, although this function is capable of finding min and max, it can't return bothof them at the same time. Thus, you will modify this function so it uses pass by referenceto send the min and max values back to the main program. This will now be a voidfunction. The parameter list will consist of three variables: an integer n, passed by value, which specifies how many numbers to generate; an integer min, passed by reference, which tells the value of the smallest numbergenerated in the sequence of n random integers; an integer max, passed by reference, which tells the value of the largest numbergenerated in the sequence of n random integers.Write a prototype for the modified function. You should rename the function also since itno longer returns just the smallest value. You will also need to change the functiondocumentation (e.g. the comment on top of the prototype), to match the modifiedfunction.Complete this function, modify the main program and test your function on a randomsequence. Continue testing and modifying until it works correctly.
Â
// Program: arguments.cpp// Purpose: Examine several aspects of argument passing://- passing arguments by value//- passing arguments by reference// Author:Jeffrey L. Popyack// Modified: January 2016//NOTE: ADD YOUR NAME AND LAB PARTNER NAME HERE: Moyses Sabba// the preprocessor#include <iostream>#include <iomanip>//to use commands to format the output#include <string>using namespace std ;// Prototypes//Purpose: generates n pseudo-random integers and determines the smallest one,//using the given value SEED as a seed.//@param n an int value representing the number of random numbers to begenerated//@return the smallest random number generaged// Usage example:int smallRandom = smallestRand (10);int smallestRand(int n) ;// Determines the smallest of n pseudo-randomintegers// the main functionint main(){// Sequences of Random Numbers:// ---------------------------------------------------------------------// The function smallestRand() generates a list of pseudo-random// numbers and determines the smallest number generated.// It is to be modified to determine both the smallest and largest// number generated, and send these values back to maincout << "smallestRand(n)" << endl ;cout << "-----------------------" << endl ;int minRand = smallestRand(10) ;cout << "The smallest value produced was " << minRand << endl ;cout << endl << endl << endl ;return 0 ;} // end of the main function// Function Definitionint smallestRand(int n){//declare constants and variables neededconst int SEED = 444 ;const int MODULUS = 32767 ;const int MULTIPLIER = 16807 ;const int FIELD_WIDTH = 10 ;//for formatting outputconst int ENTRIES_PER_LINE = 5 ; //display 5 numbers per linecout << "\nHere are " << n<< " pseudo-random numbers generated with seed= "<< SEED << " : " << endl << endl ;int i = 0 ;int x = SEED ;