
//main.cpp file
#include <iostream>
#include "helper.h"
#include "sorting.h"
using namespace std;
int main() {
unsigned int size;
cout << "Enter the size of the array: ";
cin >> size;
int* Array = new int[size];
unsigned int choice = 0;
do {
fillRandom(Array, size);
cout << "Choose your sorting
cout << "1. Bubble Sort" << endl;
cout << "2. Selection Sort" << endl;
cout << "3. Insertion Sort" << endl;
cout << "4. Merge Sort" << endl;
cout << "5. Quick Sort" << endl;
cout << "6. Shell Sort" << endl; //Optional
cout << "Enter 0 to exit" << endl;
cout << "Your choice: ";
cin >> choice;
cout << "Unsorted Array: ";
print(Array, size);
/****************************
* TODO: Implement what you will do with the choice
*****************************/
cout << "Sorted Array: ";
print(Array, size);
} while(choice!=0);
delete [] Array;
return 0;
}
//helper.h
#ifndef HELPER_H_
#define HELPER_H_
#include <iostream>
#include <stdlib.h>
using namespace std;
void fillRandom(int *Array, const unsigned int size){
for(unsigned int i = 0; i < size; i++){
Array[i] = rand();
}
}
void print(int *Array, const unsigned int size){
for(unsigned int i = 0; i < size; i++){
cout << Array[i] << ", ";
}
cout << endl;
}
#endif /* HELPER_H_ */
//sorting.h
#ifndef SORTING_H_
#define SORTING_H_
void bubbleSort(int* Array, const unsigned int size);
void selectionSort(int* Array, const unsigned int size);
void insertionSort(int* Array, const unsigned int size);
void mergeSort(int* Array, const unsigned int size);
void quickSort(int* Array, const unsigned int size);
void shellSort(int* Array, const unsigned int size);
#endif /* SORTING_H_ */


Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- 2. int count(1); while(count <5) { } --count; std::cout << count << endl; Maalarrow_forwardWORLD SERIES (C++) Code two functions to fill an array with the names of every World Series winning team from 1903 to 2020, then output each World Series winner and the number of times the team won the championship. The input file is attached, along with a main function and screen print. Please note team names that include two words, such as Red Sox, have an underscore in place of the space. This enables you to use the extraction operator with a single string variable. The following resources are included: Here is main. #include <iostream>#include <fstream>#include<string> using namespace std; // Add function declarations and documentation here void fill(string teams[], int size);void findWinner(string teams[], int size); int main(){ const int SIZE = 118;int lastIndex;string team[SIZE]; fill(team, SIZE);findWinner(team, SIZE); return 0;} // Add function definitions herearrow_forward#include <iostream>#include <cstdlib>#include <time.h>#include <chrono> using namespace std::chrono;using namespace std; void randomVector(int vector[], int size){ for (int i = 0; i < size; i++) { //ToDo: Add Comment vector[i] = rand() % 100; }} int main(){ unsigned long size = 100000000; srand(time(0)); int *v1, *v2, *v3; //ToDo: Add Comment auto start = high_resolution_clock::now(); //ToDo: Add Comment v1 = (int *) malloc(size * sizeof(int *)); v2 = (int *) malloc(size * sizeof(int *)); v3 = (int *) malloc(size * sizeof(int *)); randomVector(v1, size); randomVector(v2, size); //ToDo: Add Comment for (int i = 0; i < size; i++) { v3[i] = v1[i] + v2[i]; } auto stop = high_resolution_clock::now(); //ToDo: Add Comment auto duration = duration_cast<microseconds>(stop - start); cout << "Time taken by function: " << duration.count()…arrow_forward
- #include using namespace std; int main() { // Declare two dimensional array here // Declare other variables int numDays; int age; int QUIT = 99; // This is the work done in the getReady () function // Perform a priming read to get the age of the child while (age != QUIT) { // This is the work done in the determineRateCharge() function // Ask the user to enter the number of days // Print the weekly rate // Ask the user to enter the next child's age } // This is the work done in the finish() function cout << "End of program" << endl; return 0; } // End of main() functionarrow_forward#include <iostream> #include <string> using namespace std; int main() { // Declare a named constant for array size here // Declare array here // Use this integer variable as your loop index int loopIndex; // Use this variable to store the batting average input by user double battingAverage; // Use these variables to store the minimim and maximum values double min, max; // Use these variables to store the total and the average double total, average; // Write a loop to get batting averages from user and assign to array cout << "Enter a batting average: "; cin >> battingAverage; // Assign value to array // Assign the first element in the array to be the minimum and the maximum min = averages[0]; max = averages[0]; // Start out your total with the value of the first element in the array total = averages[0]; // Write a loop here to access array values starting with…arrow_forward1) Code that takes number of rows and columns from the user using the concept of multidimensional arrays using java. 2) Ask the user for the elements to be stored 3) Print the elements by row 4) Print the sum of the elements by row Enter number of rows: 3 Enter number of columns : 3 Enter contents of the table: a[0][0]: 1 a[0][1]: 2 a[0][2]: 3 a[1][0]: 4 a [1][1]: 10 a[1] [2]: 20 a[2][0]: 30 a[2][1]: 70 a[2][2]: 5 The contents of the table are: Row 0 ==Y [ 1 2 3 Row 1 ==V Row 2 ==> [4 10 20 [ 30 70 5 ]Sum of Row 0 is = 6 ] Sum of Row 1 is = 34 ]Sum of Row 2 is = 105arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





