Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #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 #include #include

using namespace std; void sort_array(vector& arr) { int n = arr.size(); for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } }

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 numbers; int num; while (input_file >> num) { numbers.push_back(num); }

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

LO14.1 Describe the characteristics of oligopoly.

Answered: 1 week ago