Please refer to the class NumberList defined in the files called Numberlist.h an
ID: 3815273 • Letter: P
Question
Please refer to the class NumberList defined in the files called Numberlist.h and Numberlist.cpp. In NumberList class, add a new data member called count to trace the total number of node you have in current linked list (you need to modify some member functions for adding count). Add a member function called getAverage to calculate the average of all the double values stored in each node in the current list. You also need to have a driver program to test your modified new class and new member function.
Explanation / Answer
Hi, you have not posted NumberList class files so I can not see the available members function and data.
I have assumed the structure and answered the question.
Please try to post all required details.
// Lets suppose the structure of Node class is:
class Node{
int data;
Node *next;
}
// Add this method in NumberList class
Lets assume : head is the pointer pointing to head of the list
double getAverage(){
Node *temp = head;
double sum = 0 ;
int count = 0;
while(temp != NULL){
sum = sum + temp->data;
temp = temp->next;
count++;
}
return sum/count;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.