Question
In C++ Language 3. Write a function to read the data from the above-generated files and construct 10 unsorted arrays. This function does not take
In C++ Language
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.
**Mainly I need help with 3. and combining all of these previous functions/code from questions 1 and 2 into one .cpp
From below are the previous questions that follow up to question 3.
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. For example, for quicksort, you will have a header file such as "quicksort.h", in which you will declare all the functions that you need 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].
Current Code: (IGNORE CREATION OF HEADER FILES, they're already made)
#include iostream.h
#include SelectionSort.h
#include BubbeSort.h
#include InsertionSort.h
#include MergeSort.h
#include QuickSort.h
#include HeapSort.h
using namespace std ;
//funtion 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;
}
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.
Current Code:
#include #include #include #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 = "dataset"+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; }
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