C++ Timing Tests of Sorting functions C++ running timing tests on the algorithms
ID: 3741126 • Letter: C
Question
C++
Timing Tests of Sorting functions C++
running timing tests on the algorithms. You can download my sorts.h file and include it. Call each method with a single vector of (probably) unsorted objects.
Sorts.h file = https://raw.githubusercontent.com/irawoodring/263/master/sorting/code_samples/sorts.h
You will need to do a tiny bit of programming though. I would like you to create a Celebrity class. This class should hold the following information (state): Their name How badly you want to meet them (0-10, 10 being you would sell your parents to meet them [assuming you love your parents...]) What area they are involved in (movies, music, standup, etc.) Whether or not you have met them before You will also need to create the normal accessor and mutator functions (behavior). Most importantly though, you must implement the operatorExplanation / Answer
For this answer I am giving the required code here, It will be very time consuming much more than the time we have to answer this question to generate the graph. So I can give you the instructions how to generate the graph from this code. in the main function replace the function with the sort function you want to call and measure time with the number of items. and then store it in the excel file.
The code:
#include<iostream>
#include"sort.h"
#include<algorithm>
#include<string>
#include<vector>
#include<ctime>
using namespace std;
class Celebrity
{
private:
string name;
int meetInterest;
string area;
bool metBefore;
public:
Celebrity(string name,int howmuch,string area,bool metbefore)
{
this->name = name;
this->meetInterest = howmuch;
this->area = area;
this->metBefore = metbefore;
}
string getName() const
{
return name;
}
int getMeetInterest() const
{
return meetInterest;
}
string getArea() const
{
return area;
}
bool getMetBefore() const
{
return metBefore;
}
void setName(string name)
{
this->name=name;
}
void setMeetInterest(int meetinterest)
{
this->meetInterest = meetinterest;
}
void setArea(string area)
{
this->area = area;
}
void setMetBefore(bool metbefore)
{
this->metBefore = metbefore;
}
bool operator <(const Celebrity& c)
{
if(c.getMeetInterest() > meetInterest)
return true;
else if(c.getMeetInterest() == meetInterest)
{
if(c.getMetBefore() > metBefore)
return true;
else if(c.getMetBefore() == metBefore)
{
if(lexicographical_compare(c.getName().begin(),c.getName().end(),name.begin(),name.end())) // using lexicographical ordering of string
return true;
}
}
return false;
}
};
string genRandom(int len)
{
static const string alphanum ="ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";
string s;
for(int i = 0; i < len; i++)
s += alphanum[rand()%(alphanum.length())];
return s;
}
int main()
{
//cout << "How many celebrities?:" << endl;
int number=1000000 ; // change this number to required number of elements to get time.
// cin >> number;
vector<Celebrity> vc;
for(int i =0; i < number ;i++)
{
string n = genRandom(8); // randomly getting the name
int meet = rand()%10+1; //randomly generating the meeting priority
bool met = rand()%2; // randomly generating if met beofore
string a ="";
Celebrity c(n,meet,a,met);
vc.push_back(c);
}
insertion_sort(vc); // replace it with different sorting methods given in the file sorts.h.
return 0;
}
P.S: please give me a thumbs up if you like this answer. and also give us feedback so that we can give better answer to your queries.
Happy Chegging!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.