Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then,
Write a program that adds the following to the fixed code.
• Add a function that will use the BubbleSort method to put the numbers in ascending order.
– Send the function the array.
– Send the function the size of the array.
– The sorted array will be sent back through the parameter list, so the data type of the function will be void.
Output:
• Display the array after the numbers have been placed in it. It will be unsorted at this point.
• Display the array after it has been sorted.
NOTE: There is no input from the User in this program.
Please post the original program fixed(with srand(time(NULL)) removed first), then post the fixed program with the new added program.
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
void fillArray(int randNos[], int SIZE);
int getRandom(int begin, int end);
void displayArray(int randNos[], int SIZE);
int searchNumber(int randNos[], int SIZE, int s);
int main() {
const int SIZE = 20;
srand(time(NULL)); <---Remove this
int randNos[SIZE];
char ch = 'y';
while (ch == 'y') {
fillArray(randNos, SIZE);
displayArray(randNos, SIZE);
int s = getRandom(1, 10);
cout << "Search Number :" << s << endl;
int cnt = searchNumber(randNos, SIZE, s);
if (cnt == 0) {
cout << s << " is not found in the array" << endl;
} else {
cout << "No of times " << s << " appears in the array is :" << cnt << endl;
}
cout << "\nDo you Want to continue(Y/N):";
cin >> ch;
if (ch == 'y' || ch == 'Y') {
ch = 'y';
} else {
ch = 'n';
}
}
return 0;
}
void fillArray(int randNos[], int SIZE) {
for (int i = 0; i < SIZE; i++) {
randNos[i] = getRandom(1, 10);
}
}
int getRandom(int begin, int end) {
return begin + (rand() % (end - begin + 1));
}
void displayArray(int randNos[], int SIZE) {
cout << "Displaying Array Elements :" << endl;
for (int i = 0; i < SIZE; i++) {
cout << randNos[i] << " ";
}
cout << endl;
}
int searchNumber(int randNos[], int SIZE, int s) {
int cnt = 0;
for (int i = 0; i < SIZE; i++) {
if (randNos[i] == s) {
cnt++;
}
}
return cnt;
}Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
void fillArray(int randNos[], int SIZE);
int getRandom(int begin, int end);
void displayArray(int randNos[], int SIZE);
int searchNumber(int randNos[], int SIZE, int s);
void bubbleSort(int randNos[], int SIZE);
int main() {
const int SIZE = 20;
int randNos[SIZE];
char ch = 'y';
while (ch == 'y') {
fillArray(randNos, SIZE);
displayArray(randNos, SIZE);
int s = getRandom(1, 10);
cout << "Search Number :" << s << endl;
int cnt = searchNumber(randNos, SIZE, s);
if (cnt == 0) {
cout << s << " is not found in the array" <<
endl;
} else {
cout << "No of times " << s << " appears in the
array is :" << cnt << endl;
}
bubbleSort(randNos,SIZE);
cout<<"\n:: After Sorting in ascending order
::"<<endl;
displayArray(randNos,SIZE);
cout << "\nDo you Want to continue(Y/N):";
cin >> ch;
if (ch == 'y' || ch == 'Y') {
ch = 'y';
} else {
ch = 'n';
}
}
return 0;
}
void fillArray(int randNos[], int SIZE) {
for (int i = 0; i < SIZE; i++) {
randNos[i] = getRandom(1, 10);
}
}
int getRandom(int begin, int end) {
return begin + (rand() % (end - begin + 1));
}
void displayArray(int randNos[], int SIZE) {
cout << "Displaying Array Elements :" << endl;
for (int i = 0; i < SIZE; i++) {
cout << randNos[i] << " ";
}
cout << endl;
}
int searchNumber(int randNos[], int SIZE, int s) {
int cnt = 0;
for (int i = 0; i < SIZE; i++) {
if (randNos[i] == s) {
cnt++;
}
}
return cnt;
}
void bubbleSort(int randNos[], int SIZE)
{
//This Logic will Sort the Array of
elements in Decending order
int temp1;
for (int i = 0; i < SIZE; i++)
{
for (int j = i + 1; j < SIZE; j++)
{
if (randNos[i] > randNos[j])
{
temp1 = randNos[i];
randNos[i] = randNos[j];
randNos[j] = temp1;
}
}
}
}
__________________________
Output:

_______________Could you plz rate me well.Thank
You
Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write...
Fix this C++ code so that the function prototypes come before main. Main needs to be declared first. Then call to the functions from inside of main. #include<cstdlib> using namespace std; //prompt user for input void getGrades(int gradeArray[],int size) { for(int i=0; i<size; i++) { cout<<"Enter the grade "<<i+1<<": "; cin>>gradeArray[i]; } } // finding average of all numbers in array float computeAverage(int numbers[],int size) { float sum=0; for(int i=0; i<size; i++) { sum = sum + numbers[i]; //compute sum...
Modify this C++ below to show the selection sorting algorithm method. Then write a test program and show that it works. HINT: Replace the bubbleSort function with the selectionSort. Your test program should perform the following steps: Create an array of random numbers. Display the array in its original order. Pass the array to your sorting function. Display the array again to show that it has been sorted. Provide a screen shot showing that the above steps are working. CODE:...
In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater or equal to the average and fill out the second array with these numbers. You need to design the function. I tried this code but the errors returned were: expression must have a constant value #include<iostream> using...
How do i do a random generated numbers for an array that genrates nothing but char by using ascii from 33 - 126 example of a function i have to make the array full of char. This way does not work and need help. void displayArray(char arr[], int size) { srand(time(NULL)); for(int i = 0; i < size; i++) { arr[i] = ( (rand() % 33) + 'a'); cout << arr[i] << " "; } }
THE CODE CALCULATES THE MEAN MEDIAN AND MODE OF THE SET OF NUMBERS THE CODE IS WRITTEN IN C++ PLEASE FIX THE MODE FUNCTION ! SO THAT IT OUTPUTS 0 WHEN THERE ARE NO REPETITIONS IN THE DATASET eg. for 1,2,3,4,5 mode should be zero but it gives 1 ! #include<iostream> #include<math.h> using namespace std; class statistical{ protected: double *dataArray; int size; public: statistical(double a[], int s){ dataArray = new double[s]; for (int i = 0; i<s; i++){ dataArray[i] =...
Write a c++ code into the given code to find composite numbers from the given random number list. The composite numbers is only counted once if there is a repeated number. I need to use this code and add on a code to find if the numbers generated is a composite function. Please help #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <vector> using namespace std; int main() { srand(time(NULL)); int size_of_list = 0; // the number of random...
Hello, I need help with my code. The code needs to display random number from 1 to 50 every time the program runs but the program displays the same random numbers every time. Thanks #include #include using namespace std; void dynAlloc(int size, int *&arr); void displayArray(int *arr, int n); void insertionSort(int *arr, int n, int *temp); void linear_search(int *arr, int n, int key); void binary_search(int *arr, int n, int key); int main() { const int n = 50; int *arr,...
C++ Create a function called countOccurences that will count how many times a certain number occurs in the array. The function should take an array, a size and a variable, which is what you are searching for. Heres what I got so far: #include <iostream> #include <string> #include <vector> using namespace std; void fillArray(int a[], int size); void printArray(int a[], int size); int countEvens(int ar[], int size); int main() { int ar[10]; fillArray(ar, 10); printArray(ar, 10); ...
read in numbers into array , print out, sort - my program reads in and prints out but crashes before the sort - crashes after it prints out the scores - *important I have to use pointers!!!! c++ #include <iostream> using namespace std; void sortarray(int *tarray, int ); void displayarray(int *[], int); void averageshowarray(int *[], int); int main() { int Size; int count; cout << "enter the size: " << endl; cin >> Size; int...
Write a C++ program that simulates a lottery. The user will select 5 numbers 0 through 9 and put this in an array. Then these user numbers are compared to the random numbers the computer generated. The program will display both the computer random number and below the user selected numbers. The program will tell the user how many matches are made. If the user guesses all five you let them know they are the grand winner. Here is the...