Question
DO NOT ATTEMPT QUESTIONS 1 AND 2. I just need help applying these functions into a main.cpp file ***************DO NOT DO QUESTIONS 1,2,3. THEY'RE FOR
DO NOT ATTEMPT QUESTIONS 1 AND 2.
I just need help applying these functions into a main.cpp file
***************DO NOT DO QUESTIONS 1,2,3. THEY'RE FOR UNDERSTANDING THE CONTEXT.******************
1. Write six functions to code for the following six sorting algorithms in C++. Make your own header files to declare all the functions you need to implement each of these sorting algorithms. Header files will be used to declare functions needed to perform quicksort. Then you will include these header files in your main cpp program, in which you will implement and call all these functions. The input to all these sorts is the array of unsorted integers, the size of the array, and if required the start and end variables. The output of each of these sorts is the sorted array of integers printed on the console. Test these sorts with the unsorted array - A [89, 373, 1, 783, 23, 987, 12, 65, 28, 17]. (Look at First Code, ASSUME HEADER FILES ARE ALREADY CREATED. DONT CREATE HEADER FILES.)
2. Write a function to generate 10 unique dataset files of unsorted integers separated by a comma ",". E.g., 34, 32421, 124124, 67, 92, ... The sizes of these 10 datasets are (n) - 1000, 4000, 8000, 10000, 40000, 80000, 100000, 400000, 800000, 1000000. Generate random integers between 0 to 1,000,000 as the elements of each dataset. This function does not take any input arguments. This function generates and saves 10 ".txt" files. The output of this function is just a print statement to console that file generation completed. (Look at 2nd code.)
3. Write a function to read the data from the above-generated files and construct 10 unsorted arrays. This function does not take any input arguments. This function declares 10 arrays of sizes sufficient to store the content of the above-generated files and constructs these arrays by reading these files. The output of this function is just a print statement to console that unsorted array generation completed. (Look at 3rd code)
First code:
#include iostream.h
#include SelectionSort.h
#include BubbeSort.h
#include InsertionSort.h
#include MergeSort.h
#include QuickSort.h
#include HeapSort.h
using namespace std ;
//function to Print Array
void printArray(int arr[], int n)
{
for (int i = 0; i < n; ++i)
cout << arr[i] << " ";
cout << " ";
}
int main()
{
int arr[] = { 89, 373, 1, 783, 23, 987, 12, 65, 28, 17 };
int n = sizeof(arr) / sizeof(arr[0]);
heapSort(arr, n);
cout << "Sorted array is ";
printArray(arr, n);
return 0;
}
Second Code:
#include
using namespace std;
//main method int main(){ srand(time(0)); int sizes[] = {1000, 4000, 8000, 10000, 40000, 80000, 100000, 400000, 800000, 1000000}; for(int i=0;i<10;i++){ ostringstream ss; ss << i; string ch = ss.str(); string filename = "filename"+ch+".txt"; fstream file; //opening the file file.open(filename.c_str(),ios::out); for(int j=0;j //writing to the file separating by commas if(j!=sizes[i]-1){ file< }else{ file< } } //closing this file file.close(); } cout<<"Files written"< return 0; }
Third code:
#include using namespace std;
int main() { int sizes[] = {1000, 4000, 8000, 10000, 40000, 80000, 100000, 400000, 800000, 1000000}; char filenames[][50]={"filename1.txt","filename2.txt","filename3.txt","filename4.txt","filename5.txt", "filename6.txt","filename7.txt","filename8.txt","filename9.txt","filename10.txt"}; for(int i=0;i<10;i++){ int arr[sizes[i]]; FILE *fp=fopen(filenames[i],"r"); for(int j=0;j fscanf(fp,"%d",&arr[j]); } fp.close(); } cout<<"unsorted array generation completed";
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started