Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HW _ 1 1 - Sorts - Demonstrates 5 Sorting Algorithm - ( One . cpp file for each sorting algorithm ) Create a new

HW_11- Sorts - Demonstrates 5 Sorting Algorithm -(One .cpp file for each sorting algorithm)
Create a new C++ project and name it HW_11_Sorts
- 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 7 files.
- Enter the code for each file and run the program.
- Turn in the output for credit.
_______________________________________________________________________________________________________
Create the following 8 files:
1. Source.cpp (main)- The same Source.cpp file is used for all 5 sorts.
2. BubbleSort.cpp
3. SelectionSort.cpp
4. HeapSort.cpp (5 sorts )
5. MergeSort.cpp
6. QuickSort.cpp
7. 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.
8. 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 =50;
void print(ofstream &, int[]);
void initValues(int[]);
void copyValues(int[], int[]);
void swap(T & item1, T & item2);
#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 values[SIZE];
int numCommands;
T copiedValues[SIZE];
cout << "Enter the input file name: ";
getline(cin, inFileName);
inFile.open(inFileName.c_str());
cout << "Enter the output file name: ";
getline(cin, outFileName);
outFile.open(outFileName.c_str());
inFile >> command;
initValues(values);
copyValues(values, copiedValues);
outFile << "Initial values" << endl;
print(outFile, values);
numCommands =0;
while (command != "Quit")
{
if (command == "SelectionSort")
{
selectionSort(values, SIZE);
outFile << "Results from SelectionSort: "<< endl;
print(outFile, values);
outFile << endl;
}
else if (command == "BubbleSort")
{
bubbleSort(values, SIZE);
outFile << "Results from BubbleSort: "<< endl;
print(outFile, values);
outFile << endl;
}
else if (command == "MergeSort")
{
mergeSort(values,0, SIZE-1);
outFile << "Results from MergeSort: "<< endl;
print(outFile, values);
outFile << endl;
}
else if (command == "QuickSort")
{
quickSort(values,0, SIZE-1);
outFile << "Results from QuickSort: "<< endl;
print(outFile, values);
outFile << endl;
}
else if (command == "HeapSort")
{
heapSort(values, SIZE);
outFile << "Results from HeapSort: "<< endl;
print(outFile, values);
outFile << endl;
}
else if (command == "Refresh")
copyValues(copiedValues, values);
else if (command == "ReInitialize")
{
initValues(values);
copyValues<

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

What is a position, and how is it established?

Answered: 1 week ago