Implement unsorted AND sorted array-based list and compare the time it takes to
ID: 3529797 • Letter: I
Question
Implement unsorted AND sorted array-based list and compare the time it takes to perform the inserting operation, the searching operation, and the deletion operation respectively. The numbers you should use for insertions are in file: http://cms.dt.uh.edu/faculty/yuans/courses/cs2410/prj2data.txt The numbers you should use for searching are in file: http://cms.dt.uh.edu/faculty/yuans/courses/cs2410/prj2search.txt The numbers you should use for deletions are in file: http://cms.dt.uh.edu/faculty/yuans/courses/cs2410/prj2deldata.txt You should have the client code to insert each of the numbers of prj2data.txt into the list and measure the time. Then search each of the numbers of prj2search.txt to see whether it is in the list, and measure the time. And finally, remove each of the numbers of prj2deldata.txt from the list one by one and measure the time. Submit the following: 1. The specification file and the implementation file for the two list classes; 2. The client code (should be the same for both list implementations); 3. The output screen shots showing the time of each operation, as well as the number of matching found during the search operation. To measure the time, you can use the time( ) function, which give you the time in seconds at the exact moment when the function is called. Here is an example on the use of the function: #include ... time_t t_start, t_end, t_spent; t_start = time (NULL); //do insertions... ... t_end = time(NULL); t_spent = t_end - t_start;Explanation / Answer
// included libraries
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <time.h>
#define cls system("cls")
#define pauseOutput system("pause")
void printM(int x);
void age(int m, int d, int y, int &yearAge, int &monthAge, int &dayAge);
using namespace std;
int main()
{
time_t nowIsTheMoment; // set time variable nowIsTheMoment
int bMonth,bDay, bYear;
int yearAge, monthAge, dayAge;
cout << "The current time is, " << ctime(&nowIsTheMoment) << endl << endl;
cout << "Enter your birth month in number format ex. 1 for January: ";
cin >> bMonth;
while(cin.fail())
{
cin.clear();
cout << "Error ";
cout << "Enter your birth month in number format ex. 1 for January: ";
cin >> bMonth;
}
while(bMonth < 1 || bMonth > 12)
{
cin.clear();
cout << "Error ";
cout << "Enter your birth month in number format ex. 1 for January: ";
cin >> bMonth;
}
cin.clear();
cout << " Enter your birth date: ";
cin >> bDay;
while(cin.fail())
{
cin.clear();
cout << "Error ";
cout << "Enter your birth date: ";
cin >> bDay;
}
while(bDay < 1 || bDay > 31)
{
cin.clear();
cout << "Error ";
cout << "Enter your birth date: ";
cin >> bDay;
}
cin.clear();
cout << " Enter your birth year: ";
cin >> bYear;
while(cin.fail())
{
cin.clear();
cout << "Error ";
cout << "Enter your birth year: ";
cin >> bYear;
}
cin.clear();
cout << " --- Your Birthday --- " << endl << endl;
printM(bMonth);
cout << " " << bDay << ", " << bYear << endl;
age(bMonth,bDay,bYear,yearAge,monthAge,dayAge);
cout << yearAge << " " << monthAge << " " << dayAge;
system("PAUSE");
return EXIT_SUCCESS;
}
void printM(int x)
{
//Choose and print Month
switch ( x )
{
case 1:
cout << "January";
break;
case 2:
cout << "February";
break;
case 3:
cout << "March";
break;
case 4:
cout << "April";
break;
case 5:
cout << "May";
break;
case 6:
cout << "June";
break;
case 7:
cout << "July" ;
break;
case 8:
cout << "August";
break;
case 9:
cout << "September";
break;
case 10:
cout << "October";
break;
case 11:
cout << "November";
break;
case 12:
cout << "December";
break;
}
}
void age(int m, int d, int y, int &yearAge, int &monthAge, int &dayAge)
{
time_t nowIsTheMoment; // set time variable nowIsTheMoment
time(&nowIsTheMoment);
struct tm* timeinfo;
timeinfo = localtime( &nowIsTheMoment );
yearAge = (timeinfo->tm_year) - y;
monthAge = timeinfo->tm_mon - m;
dayAge = timeinfo->tm_mday - d;
}