📄 readdata032.cpp
字号:
const int LOW_END=10; // low end of incomesconst int HIGH_END=100; // high end of incomesconst 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 indexvoid readData(TableType incomeData)// ---------------------------------------------------------// 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_END <= G <= HIGH_END. An input line with values// of zero for both G and N terminates the input.// Postcondition: incomeData[G-LOW_END] = 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 // clear array for (group = LOW_END; group <= HIGH_END; ++group) 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -