Question
In C++ Language. First question is for context, need help with 2). All functions should be in one main.cpp 1) A function is needed to
In C++ Language.
First question is for context, need help with2).All functions should be in one main.cpp
1)A function is needed 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.
#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 = "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;
}
2) A function is needed 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.
Please help, thanks
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