Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help me, please, i want to see the way u do step by step please please Overview

ID: 3723905 • Letter: H

Question

help me, please, i want to see the way u do step by step please please

Overview

For this assignment, write a program that will process two sets of random numeric information. The information will be needed for later processing, so it will be stored in arrays that will be displayed, sorted, and displayed (again).

Basic Program Logic

The main function for this program is pretty basic. It should start by creating two arrays. Each array should hold a maximum of 100 double or float elements. There should also be at least two integers. Each integer will hold the number of values that are placed into the arrays (Note: this is needed because it's possible that an entire array is not filled with data and only the part that is used should be processed).

Use srand to set the seed value for the random number generator. The program that is handed in will use srand(0) but any value can be used as the program is being developed.

Call the buildArray function that is described below to fill one of the arrays with a random number of random values. The value that is returned from the function should be saved in (assigned to) one of the integer variables.

Call the printArray function that is described below to display the first array of unsorted values with a title similar to "First Array -- Unsorted Random Numbers".

Call the sortArray function that is described below to put the values in the first array in ascending order.

Call the printArray function a second time to display the sorted values in the first array with a title similar to "First Array -- Sorted Random Numbers".

Call the buildArray function a second time to fill the other array with a random number of random values. The value that is returned from the function should be saved in (assigned to) the other integer variable.

Call the printArray function to display the second array of unsorted values with a title similar to "Second Array -- Unsorted Random Numbers".

Call the sortArray function to put the values in the second array in ascending order.

Finally, call the printArray function to display the sorted values in the second array with a title similar to "Second Array -- Sorted Random Numbers".

The Functions

The following functions are required for the assignment:

double randDouble()

This function will generate a random double value that is within a specific range. It takes no arguments and returns a double: the random number.

The rand function that has been used in previous assignments generates a random integer value. This function will still use that value but it will be used in a formula that changes the value to a double. The formula is:

lower bound + ( random integer / (maximum possible random number / (upper bound - lower bound)))

See the Symbolic Constants section for the "lower bound," "upper bound," and "maximum possible random number" values.

int buildArray( double array[] )

This function will fill an array of doubles with a random number of random values.

It takes as its argument an array of doubles: the array that will hold the numeric information and returns an integer: the number of values that were placed in the array.

The function should start by generating a random integer value that represents the number of values to place into the array. This value should be between 30 and 100. Use the following formula to generate a value within a specific range:

Once the number of values has been determined, write a loop that will execute that number of times. Inside of the loop, call the randDouble function that was previously described to get a random double value and then put the value that is returned from the function into the array argument.

After the values have been placed into the array, return the number of values that were placed in the array (the random integer from earlier).

void printArray( double array[], int numberOfValues, string title )

This function will display the numeric information in an array of doubles. There should be 8 values displayed per line, with the exception of the last line, which may have fewer than 8 values.

This function takes three arguments: the first argument is an array of doubles that holds the numbers to be displayed, the second argument is an integer that holds the number of values to be displayed, and the third argument is a string that holds a title that should be displayed before displaying the numeric information. The function returns nothing.

The function should first execute a cout statement that will display whatever the string argument is holding and the number of values to be displayed. After that, execute a loop that executes numberOfValues number of times. Within the loop, determine if 8 values have been displayed. If 8 values have been displayed, cout a newline character. After that, display a number from the array.

The values should be displayed with exactly 3 digits after the decimal point and the decimal points should line up from one line to the next.

void sortArray( double array[], int numberOfValues, char sortType )

This function will use the selection sort algorithm that was presented in lecture to sort the array.

This function takes three arguments: the first argument is an array of doubles that holds the numbers to be sorted, the second argument is an integer that holds the number of values to be sorted, and the third argument is a character that holds the type of sort that should be performed. The function returns nothing.

For the sortType argument, a value of 'A' or 'a' indicates that an ascending order sort should be performed. A value of 'D' or 'd' indicates that a descending order sort should be performed. You may assume that the sortType argument will only contain a valid value.

Symbolic Constants

This program requires the use of 6 symbolic constants. One of the constants is predefined and the remaining 5 must be defined by you.

Pre-defined constant

RAND_MAX is a symbolic constant that holds the maximum possible random number that is available on the system that is executing the program. At a minimum, the value will be 32767. Make sure to add #include <cstdlib> to the top of the program. DO NOT declare this constant in the program.

Constants that need to be created/defined

The first constant is a double that represents the lower bound of the double values that will be placed into the array of doubles. The value should be 0. (Note: make sure to use the value 0.0 if using #define)

The second constant is a double that represents the upper bound of the double values that will be placed into the array of doubles. The value should be 150. (Note: make sure to use the value 150.0 if using #define)

The third constant is an integer that represents the minimum number of values that the array of doubles can hold. The value should be 30.

The fourth constant is an integer that represents the maximum number of values that the array of doubles can hold. The value should be 100.

The fifth constant is an integer that represents the maximum number of values to display per line of output. The value should be 8.

Programming Requirements:

All 6 of the symbolic constants must be used in the program.

Add #include <cstdlib> at the top of the program.

Make sure to seed the random number generator by calling the srand function. This MUST be done in main before calling the buildArray function. The file that is handed in for grading must use srand(0);.

As with program 6, each of the functions should have a documentation box that describes the function. This is the last reminder about function documentation that will appear in the assignment write-ups.

Hand in a copy of the source code using Blackboard.

Output

Run 1 (using srand(0))

Run 2 using srand(time(0))

Explanation / Answer

//CODE IN C++

#include <iostream>

#include <iomanip> // std::setprecision

#include<cstdlib>

#include<ctime>

#define LOWER_BOUND 0.0

#define UPPER_BOUND 150.0

#define MINIMUM_NUMBER 30

#define MAXIMUM_NUMBER 100

#define MAX_VAL_DISPLAY 8

using namespace std;

double randDouble()

{

double f = (double)rand() / RAND_MAX;

return LOWER_BOUND + f * (UPPER_BOUND - LOWER_BOUND);

}

int buildArray(double array[])

{

int numberOfValues=rand()%(MAXIMUM_NUMBER-MINIMUM_NUMBER+1)+MINIMUM_NUMBER;

for(int i=0;i<numberOfValues;i++)

{

array[i]=randDouble();

}

return numberOfValues;

}

void printArray(double array[],int numberOfValues,string title)

{

cout<<endl;

cout<<title<<"--"<<numberOfValues<<"values"<<endl;

for(int i=0;i<numberOfValues;i++)

{

cout<<setprecision(2)<<array[i]<<" ";

if((i+1)%MAX_VAL_DISPLAY==0)

cout<<endl;

}

}

void sortArray(double array[],int numberOfValues,char sortType)

{

if(sortType=='a' || sortType=='A')

{

for(int i=0;i<numberOfValues-1;i++)

{

for(int j=i+1;j<numberOfValues;j++)

{

if(array[j]<array[i])

{

double temp=array[i];

array[i]=array[j];

array[j]=temp;

}

}

}

}

else

{

for(int i=0;i<numberOfValues-1;i++)

{

for(int j=i+1;j<numberOfValues;j++)

{

if(array[j]>array[i])

{

double temp=array[i];

array[i]=array[j];

array[j]=temp;

}

}

}

}

}

int main(){

srand(time(NULL));

double FirstArray[MAXIMUM_NUMBER];

double SecondArray[MAXIMUM_NUMBER];

double numberOfValuesInFirstArray=buildArray(FirstArray);

printArray(FirstArray,numberOfValuesInFirstArray,"First Array--Unsorted Random Number");

sortArray(FirstArray,numberOfValuesInFirstArray,'a');

printArray(FirstArray,numberOfValuesInFirstArray,"First Array--Sorted Random Number");

double numberOfValuesInSecondArray=buildArray(SecondArray);

printArray(SecondArray,numberOfValuesInSecondArray,"Second Array--UnSorted Random Number");

sortArray(SecondArray,numberOfValuesInSecondArray,'a');

printArray(SecondArray,numberOfValuesInSecondArray,"Second Array--Sorted Random Number");

return 0;

}