欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c++编程的一些练习改错题

程序员文章站 2022-09-21 09:35:38
c++改错本...

c++改错本
c++编程的一些练习改错题
c++编程的一些练习改错题
c++编程的一些练习改错题
c++编程的一些练习改错题
c++编程的一些练习改错题
c++编程的一些练习改错题
c++编程的一些练习改错题
c++编程的一些练习改错题
c++编程的一些练习改错题
c++编程的一些练习改错题
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

c++编程的一些练习改错题

本文地址:https://blog.csdn.net/zhangyulong007/article/details/108248794

相关标签: macos c++ 编程