Dynamically score input

From CS100 Homework 2-1

题目描述

In CS999 midterm examination, Prof. Wang wants to calculate the average score of his class. But unfortunately, he has forgotten the number of students in his class, so, the number of scores is unknown in advance. To help him solve this problem, you may need dynamic memory allocation to enlarge memory to store the scores once needed.

All scores are non-negative numbers, and -1 indicates the end of input.

After all the scores are stored into your array, you can calculate the average score. Then you should output it.

The following is a demo process for the program if you can do it successfully: (red indicates input)

image
问题输入

Input contains unknown number of lines.
All non-nagative inputs represent scores. They are floating point numbers with at most 1 decimal point digit.
The final input is -1, indicating the end of input.

问题输出

First, you should output a prompt: Please type scores to be calculated:
Note that there should be no whitespaces after the colon, and you should end this prompt with a newline.
Then, once you need to resize your array, output a message like this: (resize) from 5 to 10
Finally, after getting the final input -1, you should output Average score: , followed by the average score of the inputs.

*All of your outputs should be printed with “printf” to only 2 decimal point digits floating point number, even if a number is an integer.

*The last number -1 is not a score, so:
(1) It should not be calculated when you calculate average score.
(2) It will not be stored into your array, and therefore will not cause a resize.

样例输入1
92.6
17.5
71.0
66.3
51.9
99.6
-1
样例输出1
Please type scores to be calculated:
(resize) from 5 to 10
Average score: 66.48




在线测试 (语言:C;时间限制:1s)
当前状态

无提交记录

有话想说?