Question: Your job is to write a sort program that uses the bubble sort. This will take some time to sort and we don t want
Your job is to write a sort program that uses the bubble sort.
This will take some time to sort and we dont want to wait around for the results, so we will run the program in
the background using the &
You will run this shell file to test your program:
# This file is called sortrace.sh
# It must have execute privilege set to run
# run it as a background task like this: see the lines below
#
# $ rm sortrace.log # start with fresh log file
# $ sortrace.sh sortrace.log & # this may take an hour
#
#
echo Generating random numbers
sleep
generate # you have to write generate.cpp
sleep
echo Starting system sort
sleep
time sort n numbers.dat systemsort.out; sortrace.log # this line is for Windows
time sort n numbers.dat systemsort.out; & sortrace.log # modification for Mac
sleep
echo Starting mysort
sleep
timemysort numbers.dat mysort.out; sortrace.log # this line is for Windows
timemysort numbers.dat sort.out; & sortrace.log # modification for Mac computers
sleep
wc mysort.out
sort c n mysort.out sortrace.log # verify file is sorted
You must write the following programs
generate.cpp
o Purpose: generate a file called numbers.dat
o Description: The numbers.dat file will have COUNT random numbers between MIN and MAX
o Usage: generate COUNT MIN MAX
o Example: generate
o This program accepts command line arguments as shown above
o If there are not command line arguments, the program fails and prints error message
mysort.cpp
o Purpose: read numbers from input file, sort, write sorted numbers to output file
o Description: Uses bubble sort function on an array of integers
o Usage: mysort numbers.dat mysort.out
o It accepts command line arguments which is the input file and the output file name
o It will accept up to million numbers from the input file, but will run successfully with less
Requirements:
Use an array to store your numbers in mysort.cpp
You must have a function called bubble int A int size
The bubble function takes parameters the array and the number of items to sort.
The bubble function will be called from the main function
generate and mysort programs must work according to the above descriptions
What to submit:
mysort.cpp
generate.cpp
sortrace.log
sortrace.sh
Notice Your requirement is to use the exact sortrace.sh file listed above which sorts
numbers. Mac users may need to make minor changes. However the graders will run your
program with numbers for efficiency so make sure it works with less than
numbers as described in the requirements.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
