Question: This is the code that was in the link #include #include #include using namespace std; class RosterNode { public: RosterNode(string nname=, double sc=0.0, RosterNode *link=NULL);

 This is the code that was in the link #include #include

#include using namespace std; class RosterNode { public: RosterNode(string nname="", double sc=0.0,

This is the code that was in the link

#include

#include

#include

using namespace std;

class RosterNode {

public:

RosterNode(string nname="", double sc=0.0, RosterNode *link=NULL);

RosterNode(const RosterNode& rost);

~RosterNode();

string Name() const { return nickname;}

double Score() const { return score;}

RosterNode* Next() const { return next;}

void setNext(RosterNode *link) {next = link; }

friend class LinkedList;

private:

string nickname; // nickname of the student

double score; // its final score

RosterNode* next;

};

class LinkedList {

public:

LinkedList(){head_ptr = NULL; }

void DisplayList() const;

double ComputeDisplayAverage() const;

void DisplayBelowAverage() const;

void InsertStudentAtHead(string nname, double sc);

void RemoveStudent();

private:

RosterNode *head_ptr;

};

RosterNode::RosterNode(string nname, double sc, RosterNode *link) // constructor with three parameters

{

nickname = nname;

score = sc;

next = link;

}

RosterNode::RosterNode(const RosterNode& rost) // copy constructor

{

nickname = rost.nickname;

score = rost.score;

next = rost.next;

}

RosterNode::~RosterNode() // destructor

{

next = NULL;

}

void LinkedList::DisplayList() const // display the content of the list,

// starting with the current element and following the pointer next

{

RosterNode *cursor;

for (cursor = head_ptr->Next(); cursor != NULL; cursor = cursor->Next())

cout Name() Score()

cout

}

double LinkedList::ComputeDisplayAverage() const // calculate and display the

// average of all scores in the list, starting with current element and

// following the pointer next

{

double avg = head_ptr->Score(); // calculate the average here, initially is

// the current score

int no = 0; // calculate how many scores are in the list, initially is 1

RosterNode *cursor;

// add the scores in the list until reaching NULL

for(cursor = head_ptr->Next(); cursor != NULL; cursor = cursor->Next()) {

avg += cursor->Score();

no++;

}

if (no == 0) return 0;

// calculate the average by dividing it by the number of elements

avg /= no;

// display the average

cout

return avg;

}

void LinkedList::DisplayBelowAverage() const // display all the nicknames in

// the list below the average starting with the current element and following

// the pointer next

{

double avg = ComputeDisplayAverage(); // call function member to

// compute and display average

int no = 0; // compute the number of students below average, initially 0

RosterNode *cursor;

// increment variable no until reaching NULL

for(cursor = head_ptr->Next(); cursor != NULL; cursor = cursor->Next()) {

if (cursor->Score()

no++;

}

cout

// display the students below average

for(cursor = head_ptr->Next(); cursor != NULL; cursor = cursor->Next()) {

if (cursor->Score()

cout Name()

}

cout

}

void LinkedList::InsertStudentAtHead(string nname, double sc)

// Insert a pair (nickname, score) in the list at the beginning of the list

// element by updating the parameter head_ptr->next

{

if (head_ptr == NULL) {

head_ptr = new RosterNode;

RosterNode *tmp = new RosterNode(nname, sc);

head_ptr->setNext(tmp);

}

else {

RosterNode *tmp = new RosterNode(nname, sc, head_ptr->Next());

head_ptr->setNext(tmp);

}

}

void LinkedList::RemoveStudent()

// Remove the node in the list that has the lowest score

// including if the student is stored at the head

{

RosterNode *cursor;

if (head_ptr == NULL) return;

if (head_ptr->Next() == NULL) {

delete head_ptr;

head_ptr = NULL;

return;

}

// identify the lowest score

double lowest = head_ptr->Next()->Score();

for (cursor = head_ptr->Next(); cursor != NULL; cursor = cursor->Next())

if (lowest > cursor->Score())

lowest = cursor->Score();

// identify the node with the lowest score

// check if the head is that student

if (head_ptr->Next()->Score()

// remove the head;

RosterNode *temp = head_ptr->Next();

head_ptr->next = temp->Next();

delete temp;

}

else {

// need to keep track of the node before the deletion point

for(cursor=head_ptr->Next(); cursor->Next()!=NULL; cursor=cursor->Next() )

if (cursor->Next()->Score()

RosterNode *temp = cursor->next;

cursor->setNext(temp->next);

delete temp;

}

}

#2 [5 points] To see the advantages of storing and processing data using a linked list over an array, write a mainO program that stores five pairs (nickname, score) as shown below in the Table 1, and performs the following operations: a) displays the linked list b) computes and displays the score average as The average score is xx c) displays how many values are below the average (smaller than the average) and the nicknames ofthe students below average, as There average score is xx. d) reads from the user another pair (nickname, score) and inserts it in the list at the beginning of e) deletes the pair with the lowest score from the list, re-computes and displays the new average, The nickname is a single string only, no white spaces, and the score is a double value. There are xx students below average. Their names are xx xx xx.... the it, and as The new average score is xx Capture the console screen output. Show the runtime screenshot

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!