
Concept explainers
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
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;
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 6 steps with 7 images

- I need help in improving my Elevator class and it's subclasses code. This is an elevator simulator that uses polymorphism and object-oriented programming to simulate the movement of elevators in a building with multiple types of passengers and elevators. There are 4 types of elevators in the system:StandardElevator: This is the most common type of elevator and has a request percentage of 70%. Standard elevators have a maximum capacity of 10 passengers.ExpressElevator: This type of elevator has a request percentage of 20%. Express elevators have a maximum capacity of 8 passengers and are faster than standard elevators.FreightElevator: This type of elevator has a request percentage of 5%. Freight elevators have a maximum capacity of 5 passengers and are designed to transport heavy items.GlassElevator: This type of elevator has a request percentage of 5%. Glass elevators have a maximum capacity of 6 passengers and are designed to transport fragile item Classes should have this: Elevator {…arrow_forwardI need help in improving my code. This is an elevator simulator that uses polymorphism and object-oriented programming to simulate the movement of elevators in a building with multiple types of passengers and elevators.The system has 8 elevators, each of which can be one of 4 types of elevators, with a certainpercentage of requests for each type. Similarly, each passenger can be one of 4 types, with adifferent percentage of requests for each type. The simulation should have 4 types of Passengers: Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements. VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators. Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators. Glass: This type…arrow_forwardI also am struggling with this project but do not understand this code. The problem I have uses a main.cpp file alongside a dateTypelmp.cpp file. This solution does not solve the task as I understand it to be. The class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Function setDate and the constructor need to be rewrit so that the values for the month, day, and year are checked before storing the date into the member variables. A member function should be included, isLeapYear, to check whether a year is a leap year. Input should be format month day year with each separated by a space. Output should resemble the following: Date #: month-day-year If the year is a leap year, print the date and a message indicating it is a leap year, otherwise print a message indicating that it is not a leap year. The header file for the class dateType has…arrow_forward
- Please the code in Java eclipse. Please add comments for each instructions given in the image. I'll appreciate your help. And send the screenshoot of the output.arrow_forwardplease may you : create a Python class named Animal with properties for name, age, and a method called speak. also include an initializer method for the class and demonstrate how to create an instance of this class. and extend the Animal class by adding a decorator for one of its properties (e.g., age). please include both a getter and a setter for the property, and demonstrate error handling.arrow_forwardFirst, a quick definition of the method should be given before moving on to the three components that make it up.arrow_forward
- In JavaScript, how are an object and an interface related to each other? a. The object’s interface consists of the code and data needed for that object. b. An object’s interface is analogous to a pocket calculator’s inner workings. c. Built-in JavaScript objects do not require an interface, but custom objects do. d. An interface allows another program to access an object’s properties and methods.arrow_forwardB elow for each class you find a UML and description of the public interface. Implementing the public interface as described is madatory. There's freedom on how to implement these classes.The private properties and private methods are under your control.. There are multiple ways of implementing all these classes. Feel free to add private properties and methods. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. It's best to develop the driver as the class is being written. Check each section to see if there are added additional requirements for the driver. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate…arrow_forwardDraw the UML diagram for the class. Implement the class. Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500, use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when this account was created.arrow_forward
- Below for each class you find a UML and description of the public interface. Implementing the public interface as described is madatory. There's freedom on how to implement these classes.The private properties and private methods are under your control.. There are multiple ways of implementing all these classes. Feel free to add private properties and methods. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. It's best to develop the driver as the class is being written. Check each section to see if there are added additional requirements for the driver. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate…arrow_forwardBelow for each class you find a UML and description of the public interface. Implementing the public interface as described is madatory. There's freedom on how to implement these classes.The private properties and private methods are under your control.. There are multiple ways of implementing all these classes. Feel free to add private properties and methods. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. It's best to develop the driver as the class is being written. Check each section to see if there are added additional requirements for the driver. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate…arrow_forwardadd a class to package that represents your new drivable type. That type should be something that is capable of being driven (speeding up and slowing down) and therefore a perfect candidate for a class that implements the actions in the Drivable interface.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





