0

Hello, I can't write this program in C++. Please help, preferably without any vector<double>... something stuff. Thank you.

Write a program to read an arbitrary-length list of scores between 1 and 99 from a text file named scores.txt. After reading the scores, your program must analyze all of them, determine the average score and print statistics about the number of scores less than or equal to that average and the number of scores above it. The following is a sample output of the program: Average: 68 Below average: 32 scores Above average: 78 scores

12th Nov 2022, 5:09 PM
Alexandr Ignatov
Alexandr Ignatov - avatar
4 odpowiedzi
+ 1
Ok so your program needs to be able to process a file that can have any number of scores in it. Maybe 2, maybe 2 millions. Interestingly, C++ does have a data type which can handle data whose size you don't know upfront. https://www.mygreatlearning.com/blog/vectors-in-c/ "Vectors in C++ are sequence containers representing arrays that can change their size during runtime." So my question is, why do you want to avoid using the most suitable tool? Besides the scores seem to be integers, so luckily you can use a vector<int> instead of a vector<double> 😊 Maybe you can get away without using "something stuff", at least I don't know that library anyway 😜
13th Nov 2022, 5:19 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Maybe an idea. Open the file and read the numbers one by one, only to calculate how many numbers there are. While you are doing this you can also calculate the total sum of all numbers. So after processing the file, you have a count and a sum variable. From this you can calculate the average. Then open the file again (or just reset the file if it's still open) and read all values again one by one, and this time you keep track how many scores are below and above average. This way you don't even have to store the actual numbers in memory (in array or vector). https://cplusplus.com/reference/istream/istream/seekg/
13th Nov 2022, 10:29 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Will try. Thanks
13th Nov 2022, 10:42 AM
Alexandr Ignatov
Alexandr Ignatov - avatar
0
The task is not to use vectors (
13th Nov 2022, 10:19 AM
Alexandr Ignatov
Alexandr Ignatov - avatar