Question

Attached is a text file containing lots of randomly generated numbers in no particular order. Write...

Attached is a text file containing lots of randomly generated numbers in no particular order. Write a program that can open that file, sort the numbers from least to greatest, and display them in sorted order on the screen.

The name of the text file is; numbers_fall2020.txt

Please solve using C++

Thanks!

Homework Answers

Answer #1
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;


int main(){
    ifstream file("data.txt");   // open a file stream 
    vector<int> arr;             // declear a vector
    int x;
    while(file>>x){              // read till the end of file
        arr.push_back(x);
    }
    sort(arr.begin(),arr.end());   // sort the vector 
    for(int val:arr)cout<<val<<endl;   // display to stdout
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Attached is a text file full of names. Write a program that prompts the user to...
Attached is a text file full of names. Write a program that prompts the user to type in a name. If the name appears in the list of names, the program prints a message indicating the name was found. If the name entered by the user is not in the database, the program prints a different message indicating the name was not found. The program will continue prompting the user and searching for names until the user enters "quit". The...
C# Reading from Files Write a program to open a text file containing information about buildings....
C# Reading from Files Write a program to open a text file containing information about buildings. The program must display all the buildings in the file and then find the lowest cost building based on the cost per square foot. Format for one building: <building name> <size> sqft $<cost> Example: Allgood Hall 35000 sqft $8,250,099.75 Create the text file and add three or more of your favorite buildings.
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...
JAVA Write a program that will search a text file of strings representing numbers of type...
JAVA Write a program that will search a text file of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. Include appropriate error handling in case a line contains more than one int or it contains a String. Wrap all the work you are doing with the file in a try/catch/finally block with appropriate "catch" sections; the finally block will be where you close your file object (if desired, look this...
I cannot upload the needed text files to this question for your benefit of double checking...
I cannot upload the needed text files to this question for your benefit of double checking your solution, but I need help on this multi part question. Thanks! Write a Python program that will open the ‘steam.csv’ file. Your program should load the data as col- umns corresponding to the variable names located in the first row (You can hard code this – i.e open the file and use the names in the first row as variable names). You should...
The following code to run as the described program on python. The extra test file isn't...
The following code to run as the described program on python. The extra test file isn't included here, assume it is a text file named "TXT" with a series of numbers for this purpose. In this lab you will need to take a test file Your program must include: Write a python program to open the test file provided. You will read in the numbers contained in the file and provide a total for the numbers as well as the...
Consider the following file arrest.dat containing information of a suspect that the police is looking for:...
Consider the following file arrest.dat containing information of a suspect that the police is looking for: arrest.dat: The police is looking for Robert Whiteshead, also known as Whity, ID number 4607091111027, from address 4 Azalea Court, 219 Belmont Street, Germiston, 2065, in connection with a bank robbery at UNITED BANK in January 2016. An amount of about R45,000,000 was stolen on this day. Apparently he had a helper that goes by the name of JOINT13. Mr Whiteshead was also an...
Vectors of structs containing vectors, searching, and sorting. This program will serve to keep track of...
Vectors of structs containing vectors, searching, and sorting. This program will serve to keep track of people’s purchase records. Specifically: Create a struct type that will represent a purchase record , where each PurchaseRecord has a name (a string that may contain blank spaces), the number of purchases (1-8), the total cost of all of the purchases combined, and a vector of the individual costs for each purchase (maximum of 8 doubles). Create a vector of an unknown number of...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...