Question
help me edit c++ 1.cpp, please do it with stoi 2.cpp should have sort (please use merge or bubble sort to sort the number), mine
help me edit c++
1.cpp, please do it with "stoi"
2.cpp should have sort (please use merge or bubble sort to sort the number), mine is not woeking
edit also need to write ifstream and ofstrea, whe you run your code it opens the files as you generate numebrs and close when stop generating
"You're not supposed to print error: unable to open file because you need to write starting your sort to 1000000 items and print another statement saying ending your sort."
please check with this shell file
############################################################ # this file should be called sortrace.sh Please rename it # it must have execute privilege set to run # run it as a background task like this: # $ rm sortrace.log # start with fresh log file # $ sortrace.sh >> sortrace.log & ########################################################### echo Generating 1000000 random numbers sleep 1 generate 1000000 100000 999999 # you have to write generate.cpp sleep 1 echo Starting system sort sleep 1 { time sort numbers.dat > systemsort.out; } 2>> sortrace.log sleep 1 echo Starting my sort sleep 1 { time mysort numbers.dat mysort.out; } 2>> sortrace.log # you have to write mysort.cpp sleep 1 sort -c mysort.out 2>> sortrace.log # verify file is sorted
1.cpp
#include
using namespace std;
int main(int argc, char* argv[]) { if (argc != 4) { cerr << "Usage: generate COUNT MIN MAX" << endl; return 1; }
int count = stoi(argv[1]); int min = stoi(argv[2]); int max = stoi(argv[3]);
ofstream cout("numbers.dat");
for (int i = 0; i < count; i++) { int num = (rand() % (max - min + 1)) + min; cout << num << endl; }
cout.close();
exit(EXIT_SUCCESS); }
2.cpp
#include
using namespace std; void sort_array(vector
int main(int argc, char* argv[]) { if (argc != 3) { cerr << "Usage: " << argv[0] << " INPUT_FILE OUTPUT_FILE" << endl; return 1; }
ifstream input_file(argv[1]); if (!input_file) { cerr << "Error: Unable to open input file." << endl; return 1; }
vector
input_file.close();
sort_array(numbers);
ofstream output_file(argv[2]); if (!output_file) { cerr << "Error: Unable to open output file." << endl; return 1; }
for (int i = 0; i < numbers.size(); i++) { output_file << numbers[i] << endl; }
output_file.close();
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