张钰珑改错本

   日期:2020-08-28     浏览:96    评论:0    
核心提示:c++改错本

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

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服