DOMINGUEZ CHEESE WEBSITE TRAFFIC

DOMINGUEZ CHEESE WEBSITE TRAFFIC

Student’s Name

Institutional Affiliation

Course Name

Date

#include <iostreamm> #include <fstream> #include <iomanip> using namespace std; struct node{ int number, int counter; node *link; class linkedlist private: node *head; public: linkedlist(0: void add(int num); vold printo0 void delete5Mulitples(); int size(); int sum); double average() linkedlist:linkedlist){ head = nullptr; void linkedlist::add(int num){

linkedlist:linkedlist(0{ head nullptr, void linkedlist:add(int num){ if(head == nullptr){ head = new node(); head->number = num; head->counter = 1; head->link = nullptr; else{ node *prev = nullptr, *curr = head; while(curr = nullptr){ if(num< curr->number) break; eise if(num == curr->number){ curr->counter++; return; prev = curr; curr = curr->link; node *n new node(); n->number = num; n->link =curr, n->counter = 1; if(curr = = head) /add before 1st node?

avg Count return avg int main(0{ string tilename= “LinkNbrs.dat ifstream in(filename.c_str()); if(in.fail))X cout < “ERROR: could not open input file <<filename << endl; return 1; int num; linkedlist list; while(in >> num) list.add(num); list.print): cout «< “There are ” << list.size() «< ” nodes in the list”‘ << endl; cout « “Sum = “<< list.sum()<< endl; cout “Average = ” << list.average() << endl cout «< endl << “Deleting nodes with value that are multiples of 5” << endl; list.delete5Mulitples);

cout « “There are ” << list.size() << ” nodes in the list” <« endl; cout< “Sum = “<< list.sum(0<< endl; cout «< “Average = “<< list.average)<< endl; cout << endl «< “Deleting nodes with value that are multiples of 5” << endl; list.delete5Mulitples(0: list.print(): cout< “There are ” << list.size() << ” nodes in the list” << endl; cout «< “Sum = ” << list.sum() << endl; cout « “Average = ” << list.average) «« endl; return 0; }

delete curr; Curr = next; else{ prev Curr curr = curr->link; int linkedlist:size){ int count 0; for(node *n = head; n= nullptr,n =n->link) count++ return count int linkedlist::sum(){ int sum= 0 for(node *n = head;n!= nullptr; n =n->link) sum + n->number * n->counter; return sum; double linkedlist::average0 double avg 0; int count = 0; for(node *n = head; nl= nullptr,n =n->link) avg += n->number * n->counter; cOunt +n->counter;

prev->link = n; void linkedlist::print(){ if(head = nullptr) cout < “list is empty” << endl; else{ int i = 1; for(node *n = head;nl= nullptr; n = n->link){ cout < setw(4) << n->number << ” – ” << setw(4) << n->counter «< ” times” << setw(3) << ” “, i++; if(i % 8 == 0) cout << endl; cout << endl; void linkedlist:delete5Mulitples({ node *prev = nullptr, *curr = head, *next; while(curr != nullptr}{ if(curr->number % 5 == 0){ next curr->link; if(curr == head) //delete 1st node? head = next; else prev->link = next;