Question: can you help me change this trendtracker.cpp so it only utilizes the libraries that are in the header file or main.cpp . so you can
can you help me change this trendtracker.cpp so it only utilizes the libraries that are in the header file or main.cpp so you can only utilize
#include
#include
trendtracker.h
#ifndef TRENDTRACKERH
#define TRENDTRACKERH
You may not include any additional libraries for this assignment,
other than those listed below.
#include
#include
using namespace std;
class Trendtracker
For the mandatory running times below:
n is the number of hashtags in the Trendtracker.
public:
Creates a new Trendtracker tracking no hashtags.
Must run in O time.
Trendtracker;
Inserts a hashtag tweeted times into the Trendtracker.
If the hashtag already is in Trendtracker, does nothing.
Must run in On time.
void insertstring ht;
Return the number of hashtags in the Trendtracker.
Must run in O time.
int size;
Adds to the total number times a hashtag has been tweeted.
If the hashtag does not exist in TrendTracker, does nothing.
Must run in On time.
void tweetedstring ht;
Returns the number of times a hashtag has been tweeted.
If the hashtag does not exist in Trendtracker, returns
Must run in On time.
int popularitystring name;
Returns a mosttweeted hashtag.
If the Trendtracker has no hashtags, returns
Must run in On time.
string toptrend;
Fills the provided vector with the mosttweeted hashtags,
in order from mosttweeted to leasttweeted.
If there are fewer than hashtags, then the vector is filled
with all hashtags in mosttweeted to leasttweeted order
Must run in On time.
void topthreetrendsvector& T;
Remove the given hashtag from the trendtracker.
Must run in On time.
void removestring ht;
Fills the provided vector with the k mosttweeted hashtags,
in order from mosttweeted to leasttweeted.
If there are fewer than k hashtags, then the vector is filled
with all hashtags in mosttweeted to leasttweeted order
Must run in Onk time.
void topktrendsvector& T int k;
private:
A simple class representing a hashtag and
the number of times it has been tweeted.
class Entry
public:
string hashtag;
int pop;
;
Entries containing each hashtag and its popularity.
vector E;
;
#endif
trendtracker.cpp
#include "trendtracker.h
#include
Trendtracker::Trendtracker
Eclear;
void Trendtracker::insertstring ht
for Entry& entry : E
if entryhashtag ht
return;
Entry newEntry;
newEntry.hashtag ht;
newEntry.pop ;
EpushbacknewEntry;
int Trendtracker::size
return Esize;
void Trendtracker::tweetedstring ht
for Entry& entry : E
if entryhashtag ht
entry.pop;
return;
int Trendtracker::popularitystring ht
for const Entry& entry : E
if entryhashtag ht
return entry.pop;
return ;
string Trendtracker::toptrend
if Eempty
return ;
int maxPop Epop;
string topHashtag Ehashtag;
for const Entry& entry : E
if entrypop maxPop
maxPop entry.pop;
topHashtag entry.hashtag;
return topHashtag;
void Trendtracker::topthreetrendsvector& T
sortEbegin Eendconst Entry& a const Entry& b
return apop bpop;
;
Tclear;
for const Entry& entry : E
Tpushbackentryhashtag;
if Tsize
break;
void Trendtracker::removestring ht
for auto it Ebegin; it Eend; it
if ithashtag ht
Eeraseit;
break;
void Trendtracker::topktrendsvector& T int k
sortEbegin Eendconst Entry& a const Entry& b
return apop bpop;
;
Tclear;
for const Entry& entry : E
Tpushbackentryhashtag;
if Tsize k
break;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
