text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

c01p049.cpp

Go to the documentation of this file.
00001 
00017 const int LOW_END    = 10;
00019 const int HIGH_END   = 100;
00020 const int TABLE_SIZE = HIGH_END - LOW_END + 1;
00021 typedef int TableType[TABLE_SIZE];
00022 
00024 int index(int group)
00025 {
00026    return group - LOW_END;
00027 }  // end index
00028 
00041 void readData(TableType incomeData)
00042 {
00043    int group, number; // input values
00044 
00045    // clear array
00046    for (group = LOW_END; group <= HIGH_END; ++group)
00047       incomeData[index(group)] = 0;
00048 
00049    for (cin >> group >> number;
00050    (group != 0) || (number != 0);
00051    cin >> group >> number) {
00052       // Invariant: group and number are not both 0
00053       //    cout << "Income group " << group << " contains "
00054       //  << number << " people.\n";
00055       incomeData[index(group)] += number;
00056    }  // end for
00057 }  // end readData

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