Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HW _ 1 1 - Sorts - Demonstrates 5 Sorting Algorithm - ( One . cpp file for each sorting algorithm ) Create a new
HW Sorts Demonstrates Sorting Algorithm One cpp file for each sorting algorithm
Create a new C project and name it HWSorts
When your program executes, it will first read commands from the input file.
o See the commands in the input.txt file.
Each command will be executed and the output will be sent to the output file
You are given files.
Enter the code for each file and run the program.
Turn in the output for credit.
Create the following files:
Source.cpp main The same Source.cpp file is used for all sorts.
BubbleSort.cpp
SelectionSort.cpp
HeapSort.cpp sorts
MergeSort.cpp
QuickSort.cpp
input.txt You can create an output text file in the project or C: drive.
Your program will read the input data and run accordingly.
output.txt You can create an output text file in the project or C: drive.
NOTE: You dont have to create the output file, because, when the program runs, the file will
automatically be created for you. It will be created within the project and the data will be written.
Run the following program and turn in the output from the output file.
File: Input.txt
SelectionSort
Refresh
BubbleSort
Refresh
QuickSort
Refresh
MergeSort
Refresh
HeapSort
ReInitialize
SelectionSort
Quit
File: Source.cpp Copy and paste this code into Source.cpp
#include
#include
#include
#include
using namespace std;
typedef int T;
const int SIZE ;
void printofstream & int;
void initValuesint;
void copyValuesint int;
void swapT & item T & item;
#include "SelectionSort.cpp
#include "MergeSort.cpp
#include "QuickSort.cpp
#include "BubbleSort.cpp
#include "HeapSort.cpp
int main
ifstream inFile;
ofstream outFile;
string inFileName;
string outFileName;
string outputLabel;
string command;
T valuesSIZE;
int numCommands;
T copiedValuesSIZE;
cout "Enter the input file name: ;
getlinecin inFileName;
inFile.openinFileNamecstr;
cout "Enter the output file name: ;
getlinecin outFileName;
outFile.openoutFileNamecstr;
inFile command;
initValuesvalues;
copyValuesvalues copiedValues;
outFile "Initial values" endl;
printoutFile values;
numCommands ;
while command "Quit"
if command "SelectionSort"
selectionSortvalues SIZE;
outFile "Results from SelectionSort: endl;
printoutFile values;
outFile endl;
else if command "BubbleSort"
bubbleSortvalues SIZE;
outFile "Results from BubbleSort: endl;
printoutFile values;
outFile endl;
else if command "MergeSort"
mergeSortvalues SIZE;
outFile "Results from MergeSort: endl;
printoutFile values;
outFile endl;
else if command "QuickSort"
quickSortvalues SIZE;
outFile "Results from QuickSort: endl;
printoutFile values;
outFile endl;
else if command "HeapSort"
heapSortvalues SIZE;
outFile "Results from HeapSort: endl;
printoutFile values;
outFile endl;
else if command "Refresh"
copyValuescopiedValues values;
else if command "ReInitialize"
initValuesvalues;
copyValues<
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