I need to change this code into object oriented code. here's how to objects are supposed to be setup. First you will need to make a Timer object. This object should function like a traditional stopwatch with methods for starting, stopping, resetting, and reporting back times. The design of the object itself is up to you (it should minimally contain methods for the aforementioned ideas), but it must consist of a solitary object that provides interfaces appropriate for being compositionally included as part of a sorting object to facilitate the time keeping portion of this exercise. Make sure you have a properly separated specification and implementation file for your Timer/Stopwatch object. The second object you will make should be a data housing object that has methods that enable client code to read in the formatted contents of data files, house the data in memory, and execute bubble sort, selection sort, and insertion sort algorithms in a timed fashion with the assistance of your Timer object. You will need to include interfaces/methods for providing file names, reporting erroneously formatted data files, reporting files sizes, initiating individual sort algorithms, and reporting back unbiased times to the client code.   Here is the code: #include #include #include #include #include #include using namespace std; long length = 500; const long max_length = 100000; long list[max_length]; int i = 0; #define INFILE "testing.txt" //defining name of the input file void read(); void bubbleSort(); void insertionSort(); void selectionSort(); int main()//running sorts and outputting results { double t1, t2; //time values for start and finish of sort for (length = 500; length <= max_length;) { cout << endl << "Length: : " << length << endl; cout << "Sorting..." << endl; read(); //calling in values to be sorted cout << "Sort Complete!!" << endl;; t1 = clock(); //start time bubbleSort(); // sort t2 = clock(); //end time cout << "Bubble Sort : " << (t2 - t1)/CLK_TCK << " sec" << endl; // outputting the results of the bubble sort read(); //calling in values to be sorted t1 = clock();//start time insertionSort();// sort t2 = clock();//end time cout << "Insertion Sort : " << (t2 - t1) / CLK_TCK << " sec" << endl;// outputting the results of the insertion sort read();//calling in values to be sorted t1 = clock();//start time selectionSort();// sort t2 = clock();//end time cout << "Selection Sort : " << (t2 - t1) / CLK_TCK << " sec" << endl;// outputting the results of the selection sort switch (length) { // changing the length of the sort case 500: length = 1000; break; case 1000: length = 5000; break; case 5000: length = 10000; break; case 10000: length = 25000; break; case 25000: length = 50000; break; case 50000: length = 100000; break; case 100000: length = 100001; break; } } return 0; } void read() //bringing in txt file with values { for (i = 0; i < length; i++) { list[i] = 0; } ifstream inputHandle(INFILE, ios::in); if (inputHandle.is_open() == true) { i = 0; while (i < length) { inputHandle >> list[i]; i++; } inputHandle.close(); } else { cout << "ERROR: The file \"" << INFILE << "\" could not be opened for reading..." << endl; } } void bubbleSort() //bubble sort function { int temp; for (long i = 0; i < length; i++) { for (long j = 0; j < length - i - 1; j++) { if (list[j] > list[j + 1]) { temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } } void insertionSort() //insertion sort function { int currentValue; for (int i = 1; i < length; i++) { int j = i - 1; currentValue = list[i]; while (list[j] > currentValue && j >= 0) { list[j + 1] = list[j]; j--; } list[j + 1] = currentValue; } } void selectionSort() //selection sort function { for (int i = 0; i < length - 1; i++) { int currentMin = i; for (int j = i + 1; j < length; j++) { if (list[j] < list[currentMin]) currentMin = j; } int tempNum = list[i]; list[i] = list[currentMin]; list[currentMin] = tempNum; } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need to change this code into object oriented code. here's how to objects are supposed to be setup.

First you will need to make a Timer object. This object should function like a traditional stopwatch with methods for starting, stopping, resetting, and reporting back times. The design of the object itself is up to you (it should minimally contain methods for the aforementioned ideas), but it must consist of a solitary object that provides interfaces appropriate for being compositionally included as part of a sorting object to facilitate the time keeping portion of this exercise. Make sure you have a properly separated specification and implementation file for your Timer/Stopwatch object.

The second object you will make should be a data housing object that has methods that enable client code to read in the formatted contents of data files, house the data in memory, and execute bubble sort, selection sort, and insertion sort algorithms in a timed fashion with the assistance of your Timer object. You will need to include interfaces/methods for providing file names, reporting erroneously formatted data files, reporting files sizes, initiating individual sort algorithms, and reporting back unbiased times to the client code.

 

Here is the code:

#include <iostream>

#include <fstream>

#include <cstdlib>

#include <ctime>

#include <conio.h>

#include <iomanip>

using namespace std;

long length = 500;

const long max_length = 100000;

long list[max_length];
int i = 0;

#define INFILE "testing.txt" //defining name of the input file

void read();
void bubbleSort();
void insertionSort();
void selectionSort();


int main()//running sorts and outputting results
{
double t1, t2; //time values for start and finish of sort
for (length = 500; length <= max_length;)
{
cout << endl << "Length: : " << length << endl;
cout << "Sorting..." << endl;
read(); //calling in values to be sorted
cout << "Sort Complete!!" << endl;;
t1 = clock(); //start time
bubbleSort(); // sort
t2 = clock(); //end time
cout << "Bubble Sort : " << (t2 - t1)/CLK_TCK << " sec" << endl; // outputting the results of the bubble sort
read(); //calling in values to be sorted
t1 = clock();//start time
insertionSort();// sort
t2 = clock();//end time
cout << "Insertion Sort : " << (t2 - t1) / CLK_TCK << " sec" << endl;// outputting the results of the insertion sort
read();//calling in values to be sorted
t1 = clock();//start time
selectionSort();// sort
t2 = clock();//end time
cout << "Selection Sort : " << (t2 - t1) / CLK_TCK << " sec" << endl;// outputting the results of the selection sort
switch (length) { // changing the length of the sort
case 500:
length = 1000;
break;
case 1000:
length = 5000;
break;
case 5000:
length = 10000;
break;
case 10000:
length = 25000;
break;
case 25000:
length = 50000;
break;
case 50000:
length = 100000;
break;
case 100000:
length = 100001;
break;
}
}
return 0;
}

void read() //bringing in txt file with values
{
for (i = 0; i < length; i++) {
list[i] = 0;
}
ifstream inputHandle(INFILE, ios::in);
if (inputHandle.is_open() == true)
{
i = 0;
while (i < length)
{
inputHandle >> list[i];
i++;
}
inputHandle.close();
}
else {
cout << "ERROR: The file \"" << INFILE << "\" could not be opened for reading..." << endl;
}
}

void bubbleSort() //bubble sort function
{
int temp;
for (long i = 0; i < length; i++)
{
for (long j = 0; j < length - i - 1; j++)
{
if (list[j] > list[j + 1])
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
}
void insertionSort() //insertion sort function
{
int currentValue;
for (int i = 1; i < length; i++) {
int j = i - 1;
currentValue = list[i];
while (list[j] > currentValue && j >= 0) {
list[j + 1] = list[j];
j--;
}
list[j + 1] = currentValue;
}
}


void selectionSort() //selection sort function
{
for (int i = 0; i < length - 1; i++) {
int currentMin = i;
for (int j = i + 1; j < length; j++) {
if (list[j] < list[currentMin])
currentMin = j;
}
int tempNum = list[i];
list[i] = list[currentMin];
list[currentMin] = tempNum;
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 7 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education