const int LOW_END = 10; // low end of incomes considered const int HIGH_END = 100; // high end of incomes considered const int TABLE_SIZE = HIGH_END - LOW_END + 1; typedef int tableType[TABLE_SIZE]; int Index(int Group) // Returns the array index that corresponds to Group number. { return Group - LOW_END; } // end Index void ReadData(tableType IncomeData, int Low, int High) // --------------------------------------------------------- // Reads and organizes income statistics. // Precondition: The calling module gives directions and // prompts user. Input data is error-free and each input // line is in the form G N, where N is the number of // people with an income in the G-thousand-dollar group // and Low <= G <= High. An input line with values of zero // for both G and N terminates the input. // Postcondition: IncomeData[G-Low] = total number of people // with an income in the G-thousand-dollar group for each G // read. The values read are displayed. // --------------------------------------------------------- { int Group, Number; // input values for (Group = Low; Group <= High; ++Group) // clear array IncomeData[Index(Group)] = 0; for (cin >> Group >> Number; (Group != 0) || (Number != 0); cin >> Group >> Number) { // Invariant: Group and Number are not both 0 cout << "Income group " << Group << " contains " << Number << " people.\n"; IncomeData[Index(Group)] += Number; } // end for } // end ReadData