I was practising some c++ before my test and I came across this task which says:
a-) Design class RankingList with three type parameters name, evaluation, id defining 3 features of each element of a ranking list. The elements should be sorted according to the value of evaluation.
b-) Write implementation of a method inserting element to a ranking list. An element with not unique id should not be inserted.
c-) Write implementation of operator<< for class template RankingList
So what I have currently done is the following:
#include <iostream>
#include <string.h>
using namespace std;
template<typename T1, typename T2, typename T3>
class RankingList
{
private:
struct Rank
{
T1 name;
T2 evaluation;
T3 id;
Rank *next;
} rank;
Rank *head;
Rank *tail;
public:
void setName(T1 newName)
{
rank.name = newName;
}
const T1 getName()
{
return rank.name;
}
void setEvaluation(T2 newEvaluation)
{
rank.evaluation = newEvaluation;
}
const T2 getEvaluation()
{
return rank.evaluation;
}
void setId(T3 newId)
{
rank.id = newId;
}
const T3 getId()
{
return rank.id;
}
RankingList();
RankingList(const &other);
~RankingList(){};
friend ostream &operator << (ostream &os, const RankingList<T1, T2, T3> &toPrint);
};
template<typename T1, typename T2, typename T3>
ostream &operator << (ostream &os, const RankingList<T1, T2, T3> & toPrint)
{
cout << "12212" << endl;
typename RankingList<T1, T2, T3>::Rank *temp;
temp = toPrint.head;
while(temp)
{
os << "Name: " << temp->name << ", evaluation " << temp->evaluation << ", id " << temp->id << endl;
temp = temp->next;
}
return os;
}
int main()
{
RankingList<int, int, int> list23();
cout << list23 << endl;
return 0;
}
So I have written a template class with the 3 types, used structure with the parameters required and added a node pointing to the next. Also, reference for the head and tail of ranks. I then added some getters and setters for the variables I got and implemented, declared few methods and implemented the operator<<;
The issue is that calling operator << wouldn't do anything at all just prints out 1 and not even sure if what I have any issues with the current code and how to implement task 2 properly.