Please utilize the sample programs for timing and file reading: BinaryFileRead.cpp // BinaryFileRead.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; int main() { int *arrayToSort; char fileName[50]; int size,readVal; cout << "Enter a filename to sort => "; cin >> fileName; FILE *inFile; fopen_s(&inFile,fileName, "rb"); fread(&size, sizeof(size), 1, inFile); arrayToSort = new int[size]; for (int i = 0; i < size; i++) { fread(&readVal, sizeof(readVal), 1, inFile); arrayToSort[i] = readVal; } fclose(inFile); return 0; } Timing.cpp // Timing.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include //ctime #include //_timeb _ftime_s using namespace std; int main() { struct _timeb timebuffer; char timeline[26]; _ftime_s(&timebuffer); ctime_s(timeline,sizeof(timeline), &(timebuffer.time)); printf("The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20]); system("pause"); return 0; } Write the program that allows the user to sort using the Merge Sort and Quick Sort. The program should be able to read in data from a binary file. The first element of the binary file will be used to tell how many elements to read in. Once all the data has been read in, the program should sort the data. The user should be able to choose which algorithm to use to sort the data. The program should print the time before and after the sort. The last part of the program should prompt the user for a lower and upper bound. These two values should then be used to decide how much and which part of the array will be display. You should test all of the sorts on each of the data files. Add a a justification of the difference between the run times of each sort when compared to those you're reported on earlier. Include the runtimes on both the million and 10 million element lists (Don't rerun the first four algorithms with the 10 million list). Continue noting the best, worst, and average runtims for all algorithms as well as a justification of why the new algorithms are faster or slower. Note: All files may have duplicate numbers in them. USE C++
Please utilize the sample programs for timing and file reading:
BinaryFileRead.cpp
// BinaryFileRead.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int *arrayToSort;
char fileName[50];
int size,readVal;
cout << "Enter a filename to sort => ";
cin >> fileName;
FILE *inFile;
fopen_s(&inFile,fileName, "rb");
fread(&size, sizeof(size), 1, inFile);
arrayToSort = new int[size];
for (int i = 0; i < size; i++) {
fread(&readVal, sizeof(readVal), 1, inFile);
arrayToSort[i] = readVal;
}
fclose(inFile);
return 0;
}
Timing.cpp
// Timing.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>
#include <time.h> //ctime
#include <sys/timeb.h> //_timeb _ftime_s
using namespace std;
int main()
{
struct _timeb timebuffer;
char timeline[26];
_ftime_s(&timebuffer);
ctime_s(timeline,sizeof(timeline), &(timebuffer.time));
printf("The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20]);
system("pause");
return 0;
}
Note: All files may have duplicate numbers in them.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 6 images
Can you edit the code and utilize these sample programs for timing and file reading:
BinaryFileRead.cpp
// BinaryFileRead.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int *arrayToSort;
char fileName[50];
int size,readVal;
cout << "Enter a filename to sort => ";
cin >> fileName;
FILE *inFile;
fopen_s(&inFile,fileName, "rb");
fread(&size, sizeof(size), 1, inFile);
arrayToSort = new int[size];
for (int i = 0; i < size; i++) {
fread(&readVal, sizeof(readVal), 1, inFile);
arrayToSort[i] = readVal;
}
fclose(inFile);
return 0;
}
Timing.cpp
// Timing.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>
#include <time.h> //ctime
#include <sys/timeb.h> //_timeb _ftime_s
using namespace std;
int main()
{
struct _timeb timebuffer;
char timeline[26];
_ftime_s(&timebuffer);
ctime_s(timeline,sizeof(timeline), &(timebuffer.time));
printf("The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20]);
system("pause");
return 0;
}