98.1k views
4 votes
Write a program in C++ that reads a sequence of numbers from a text file named numbers.txt and then outputs information about the sequence to a text file named output.txt. Output.txt will contain the amount of numbers in numbers.txt, the max number, min number, average, median, and a vertical bar chart of the values using asterisks. The bar chart will start with 0−10 and then go by groups of 9 . Use functions instead of writing the entire program in main. Only use any of the following libraries: iostream, iomanip, cmath, string, fstream, sstream, vector, cstdlib, ctime, cctype, cstring.

1 Answer

0 votes

Final answer:

To write a program in C++ that reads a sequence of numbers from a text file and outputs information about the sequence, you can use the fstream library for file input/output operations. Calculate the necessary information like the number of numbers, max/min number, average, median. Create a bar chart using asterisks based on the magnitude of the numbers.

Step-by-step explanation:

To write a program in C++ that reads a sequence of numbers from a text file and outputs information about the sequence, you can use the fstream library to handle file input/output operations. First, open the 'numbers.txt' file using an input file stream object. Then, you can read the numbers from the file and calculate the necessary information such as the number of numbers, max/min number, average, and median.

To create a bar chart using asterisks, you can use a loop to iterate over the values and print asterisks based on their magnitude. For example, if a number is in the range 0-10, you can print one asterisk, and for numbers in the range 11-19, print two asterisks, and so on. Finally, you can open the 'output.txt' file using an output file stream object and write the information and the bar chart to the file.

User Anjana
by
8.2k points