张钰珑改错本

时间:2020-8-28 作者:admin


c++改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
张钰珑改错本
【问题描述】

Write a program that reads a file (“testScore.txt”) consisting of students’ test scores in the range 0–200. It should then determine the number of students having scores in each of the following ranges: 0–24, 25–49, 50–74, 75–99, 100–124, 125–149, 150–174, and 175–200. Output the score ranges and the number of students.

a. Write a function readData to read students’ test score from the file and determine which range the test scores fall into. Hint 1: the formal parameters of this function will include: input file stream variable, the array that contain the number of students having scores in each of the above ranges, and the size of the array. Hint 2: determine which range the test score should fall into. Suppose the score is 20, score/25 evaluates to 0. This test score falls into the range 0-24 (the first component in the array). score is 176, score/25 evaluates to 7. This test score falls into the range 175-200 (the eighth component in the array). Score is 200, score/25 evaluates to 8. This test score falls into the range 175-200 (the eighth component in the array). Hint 3: use a while loop to input data and determine the test score in which range. You can use the while loop:

while (inputFile)
{
}

b. The code of function print is provided below. You can call the function to output the score range and the number of students. Your task is to write the function main.

void print(int list[], int size)
{
int range;
int lowRange = 0;
int upperRange = 24;

cout << "   Range       # of Students" << endl;

for (range = 0; range < size; range++)
{
    cout << setw(3) << lowRange << " - " << setw(3)
         << upperRange << setw(15)
         << list[range] << endl;
    lowRange = upperRange + 1;
    upperRange = upperRange + 25;
    if (range == size - 2)
        upperRange++;
}
cout << endl;

}
【样例输入】

testScore.txt 文件内容:

45

100

154

81

13

193

【样例输出】

Range # of Students

0 -  24              1

25 – 49 1

50 – 74 0

75 – 99 1

100 – 124 1

125 – 149 0

150 – 174 1

175 – 200 1

张钰珑改错本

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。