I think I have been working on this too long.....in the Main Function area I can't get this to work, I am sure it is probably something simple but I am not seeing it, are you???
Thanks!!!!
Code:#include <iostream.h> #include <string.h> //----------Node Class-------------// class Digit { friend class NumberList; public: Digit( const int & ); int getData() const; private: int data; Digit *nextPtr; }; Digit::Digit( const int &info ) : data( info ), nextPtr( 0 ) { } int Digit::getData() const { return data; } //-----------NumberList Class ------------------// class NumberList{ public: NumberList(); ~NumberList(); void insertAtBack( const int & ); bool isEmpty() const; void display() const; void HighInt(); void LowInt(); void AverageInt(); private: Digit *firstPtr; Digit *lastPtr; Digit *getNewNode( const int & ); }; NumberList::NumberList() : firstPtr( 0 ), lastPtr( 0 ) { } NumberList::~NumberList() { if ( !isEmpty() ) { Digit *currentPtr = firstPtr; Digit *tempPtr; while ( currentPtr != 0 ) { tempPtr = currentPtr; currentPtr = currentPtr->nextPtr; delete tempPtr; } } } void NumberList::insertAtBack( const int &value ) { Digit *newPtr = getNewNode( value ); if ( isEmpty() ) firstPtr = lastPtr = newPtr; else { lastPtr->nextPtr = newPtr; lastPtr = newPtr; } } bool NumberList::isEmpty() const { return firstPtr == 0; } Digit *NumberList::getNewNode( const int &value ) { return new Digit( value ); } void NumberList::display() const { if ( isEmpty() ) { cout << "The list is empty\n\n"; return; } Digit *currentPtr = firstPtr; while ( currentPtr != 0 ) { cout << currentPtr->data << " "; currentPtr = currentPtr->nextPtr; } cout << "\n\n"; } void NumberList::AverageInt() { if( isEmpty() ) {cout << "The list is empty" << endl;} int length = 0; Digit *currentPtr = firstPtr; int sum = 0; while(currentPtr != 0) { length++; sum+=currentPtr->data; currentPtr = currentPtr->nextPtr; } cout << "The average is " << (float)sum/length << endl; } void NumberList::HighInt() { if( isEmpty() ) {cout << "The list is empty" << endl;} Digit *currentPtr = firstPtr; int high = currentPtr->data; while(currentPtr != 0) { if(currentPtr->data > high) {high = currentPtr->data;} currentPtr = currentPtr->nextPtr; } cout << "The high is " << high << endl; } void NumberList::LowInt() { if( isEmpty() ) {cout << "The list is empty" << endl;} Digit *currentPtr = firstPtr; int low = currentPtr->data; while(currentPtr != 0) { if(currentPtr->data < low) {low = currentPtr->data;} currentPtr = currentPtr->nextPtr; } cout << "The low is " << low << endl; } //---------------main function---------------// void main() { int input; int getInput(int *input); int n = 0; while(n != 9999) { cout << "Enter #" << n << " => "; cin >> input[i]; if (input[i] == -1) break; i++; } return (n - 1); }



LinkBack URL
About LinkBacks



' ), instead of imposing an arbitrary limit (which is infinite anyway since 'n; never changes).