//-------------------------------------------------------------------- // // Laboratory 3 lab03-ex1.cpp // // Copy of example problem in prelab section (step 2) that demonstrates // using a list to read in a set of numbers and then traverse the list // calculating the sum of the numbers in the list // //-------------------------------------------------------------------- // For this example, set DataType to "int" in listarr.h, #include #include "listarr.h" // Include the class declaration file using namespace std; void main () { List samples(100); // Set of samples int newSample, // Input sample total = 0; // Sum of the input samples // Read in a set of samples from the keyboard. cout << "Enter list of samples (end with eof) : "; while ( cin >> newSample ) samples.insert(newSample); // Sum the samples and output the result. if ( !samples.isEmpty() ) // Verify that list has data { samples.gotoBeginning(); // Go to beginning of list do total += samples.getCursor(); // Add element to running sum while ( samples.gotoNext() ); // Go to next element (if any) } cout << "Sum is " << total << endl; }