text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

c01p050.cpp

Go to the documentation of this file.
00001 
00037 bool readData(TableType incomeData)
00038 {
00039    int group, number;  // input values
00040    bool dataCorrect = true;  // no data error found as yet
00041 
00042    for (group = LOW_END; group <= HIGH_END; ++group)
00043       incomeData[index(group)] = 0;
00044 
00045    for (cin >> group >> number;
00046    (group != 0) || (number != 0);
00047    cin >> group >> number) {
00048       // Invariant: group and number are not both 0
00049       cout << "Input line specifies that income group "
00050       << group << "\ncontains " << number
00051       << " people.\n";
00052 
00053       if ((group >= LOW_END) && (group <= HIGH_END) &&
00054      (number >= 0))
00055     // input data is valid -- add it to tally
00056     incomeData[index(group)] += number;
00057 
00058       else
00059     // error in input data: set error flag and
00060     // ignore input line
00061     dataCorrect = false;
00062    }  // end for
00063    return dataCorrect;
00064 }  // end readData

Generated on Sat Aug 26 19:58:10 2006 for AWLogo by  doxygen 1.4.6