#include class llist { public: double getdata(); void setdata(double d); llist* getnext(); void setnext(llist *n); llist(); const llist& operator +=(double d); private: double data; llist *next; }; // the way this will work is that += will be overloaded to // add the double to the end of the linked list const llist& llist::operator +=(double d) { // remember, this is a pointer to the current instance // of the linked list llist *temp; temp = this; // if this isn't the last node of the linked list if (temp->next) // we want to return the results of the += operator on the // next one because it will also seek out the last // node (recursion) return *(temp->next) += d; else { // if we are at the last node, we want to attach a new // node to it, and set its data to be the assigned data // note: we don't need to worry about setting the new node's // data to be 0 since the default constructor will handle that // for us next = new llist; next->data = d; } return *this; } llist::llist() { // again, this makes sure that our pointers default to 0 next = 0; } void llist::setnext(llist *n) { next = n; } void llist::setdata(double d) { data = d; } double llist::getdata() { return data; } llist* llist::getnext() { return next; } int main() { llist *start; llist *current = new llist; double sum; double avg, correction; int count = 1; double data; start = current; // set both to be the new item cin >> data; start->setdata(data); sum = data; while (data != 0) { cin >> data; current += data; // see! there is use to overloading // operators current = current->getnext(); sum += data; count++; } avg = sum / count; correction = avg / 10; for (current = start; current; current = current->getnext()) { current->setdata(current->getdata() * correction); } *start += 100.2; *start += 23.0; for (current = start; current; current = current->getnext()) { cout << current->getdata() << endl; } return 0; }