Trendtrackerh Ifndef Trendtrackerh Define Trendtrackerh Include Include Using Namespace St Q43884847
//trendtracker.h
#ifndef TRENDTRACKER_H
#define TRENDTRACKER_H
#include <vector>
#include <string>
using namespace std;
class Trendtracker
{
public:
Trendtracker();
void insert(string ht);
int size();
void tweeted(string ht);
int popularity(string name);
string top_trend();
void top_three_trends(vector<string>&T);
void top_k_trends(vector<string> &T, intk);
private:
class Entry
{
public:
string hashtag;
int pop;
};
vector<Entry> E;
};
#endif
//trendtracker.cpp
#include”trendtracker.h”
using namespace std;
// Creates a new Trendtracker tracking no hashtags.
//
// Must run in O(1) time.
Trendtracker::Trendtracker(){
}
// Inserts a hashtag (tweeted 0 times) into theTrendtracker.
// If the hashtag already is in Trendtracker, does nothing.
//
// Must run in O(n) time.
void Trendtracker::insert(string ht){
Entry t;
int n = E.size();
t.hashtag = ht;
t.pop = 0;
for (int i = 0; i < n; i++) {
if (ht == E[i].hashtag) {
break;
}
}
}
// Return the number of hashtags in the Trendtracker.
//
// Must run in O(1) time.
int Trendtracker::size(){
return E.size();
}
// Adds 1 to the total number times a hashtag has beentweeted.
// If the hashtag does not exist in TrendTracker, doesnothing.
//
// Must run in O(n) time.
void Trendtracker::tweeted(string ht) {
int n = E.size();
for (int i = 0; i < n; i++) {
if (E[i].hashtag == ht) {
E[i].pop++;
}
}
}
// Returns the number of times a hashtag has been tweeted.
// If the hashtag does not exist in Trendtracker, returns -1.
//
// Must run in O(n) time.
int Trendtracker::popularity(string name){
int i = 0;
int n = E.size();
bool check = 0;
for (int i = 0; i < n; i++) {
if (name == E[i].hashtag) {
check = 1;
}
}
if (check == 1) {
return E[i].pop;
}
else {
return -1;
}
}
// Returns a most-tweeted hashtag.
// If the Trendtracker has no hashtags, returns “”.
//
// Must run in O(n) time.
string Trendtracker::top_trend(){
if (E.size() == 0) {
return “”;
}
int popular;
for (int i = 0, n = E.size(), popular = 0; i < n;i++) {
if (E[i].pop > E[popular].pop){
popular =i;
}
}
return E[popular].hashtag;
}
// Fills the provided vector with the 3 most-tweetedhashtags,
// in order from most-tweeted to least-tweeted.
//
// If there are fewer than 3 hashtags, then the vector isfilled
// with all hashtags (in most-tweeted to least-tweetedorder).
//
// Must run in O(n) time.
void Trendtracker::top_three_trends(vector<string>&T){
int f, s, t;
int n = E.size();
for (int i = 0, f = s = t = n; i < n; i++) {
if (E[i].pop > E[f].pop) {
t = s;
s = f;
f = i;
}
else if (E[i].pop > E[s].pop){
t = s;
s = i;
}
else if(E[i].pop > E[t].pop){
t = i;
}
}
T.push_back(E[f].hashtag);
if (s != n && s != f)
T.push_back(E[s].hashtag);
if (t != n && t != s)
T.push_back(E[t].hashtag);
}
// Fills the provided vector with the k most-tweetedhashtags,
// in order from most-tweeted to least-tweeted.
//
// If there are fewer than k hashtags, then the vector isfilled
// with all hashtags (in most-tweeted to least-tweetedorder).
//
// Must run in O(nk) time.
void Trendtracker::top_k_trends(vector<string> &T, intk){}
canyou help me figure out how to solve whatever code i dont havecompleted in trendtracker.cpp
Expert Answer
Answer to //trendtracker.h #ifndef TRENDTRACKER_H #define TRENDTRACKER_H #include #include using namespace std; class Trendtracke…
OR