Question

in c++ Create a program that will generate 1000 random integers between 1 - 1000 and...

in c++

Create a program that will generate 1000 random integers between 1 - 1000 and write into a file.

***Implement a file buffer***

in c++

upload snipping photos of the output too, thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main() {
    srand(time(NULL));
    string fileName;
    cout << "Enter file name: ";
    cin >> fileName;
    ofstream out(fileName.c_str());
    for (int i = 0; i < 1000; ++i) {
        out << (1 + rand() % 1000) << endl;
    }
    cout << "Random numbers are written to " << fileName << endl;
    out.close();
    return 0;
}

Enter file name: numbers.txt Random numbers are written to numbers.txt

numbers,tct:

373 849 548 491 568 923 198 953 531 192 356 576 888 482 318 193 657 7488 99 116 958 611 53 86 486 687 965 634 131 163 975 855

Add a comment
Know the answer?
Add Answer to:
in c++ Create a program that will generate 1000 random integers between 1 - 1000 and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A. Create a java program that generates 1000 random integers. Write the 1000 random integers to...

    A. Create a java program that generates 1000 random integers. Write the 1000 random integers to a file using the Formatter class. B. Create a second java program that opens the file with the 1000 integers using the Scanner class. Read in the integers and find and print out the largest, smallest and the average of all 1000 numbers. C. Repeat A from above but use the BufferedWriter class B. Repeat B from above but use the BufferedReader class.

  • Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 -...

    Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...

  • Create a JavaFX game: Guess the Number create a random # between 1 and 1000 Ask...

    Create a JavaFX game: Guess the Number create a random # between 1 and 1000 Ask user for a guess; possible answers TOO LOW TOO HIGH WINNER! print guess to screen if the user wins, write the random number, and all the guesses to a file. If the user doesn't guess in 10 turns, display the number. NOTES: You may want to implement: Restart option Best Guess statistic (game 1 took 8 tries, game 2 took 5 - 5 is...

  • In c# create a program that generates a random number from 1 to 1000. Then, ask...

    In c# create a program that generates a random number from 1 to 1000. Then, ask the user to guess the random number. If the user's guess is too high, then the program should print "Too High, Try again". If the user's guess is too low, then the program should print "Too low, Try again". Use a loop to allow the user to keep entering guesses until they guess the random number correctly. Once they figure it, congratulate the user....

  • Task 3: Functions or classes are ok. Create an array that holds 1000 random floats between...

    Task 3: Functions or classes are ok. Create an array that holds 1000 random floats between 1-1000. Implement Quick Sort to sort the values in ascending order. Least → Greatest Measure the time it takes to execute the sort in milliseconds. Please run the sort 3 times. Attach Photos of Source Code and Output

  • Write a C++ program that generates twenty five random integers between 0 and 24 and display the sum of even integers.

    (C++)Write a program that generates twenty five random integers between 0 and 24 and display the sum of even integers. (Hint: Use rand()%25 to generate a random integer between 0 and 24. Use an array of 25 integers, say num , to store the random integers generated between 0 and 24.)

  • Write a program in c++ that generates a 100 random numbers between 1 and 1000 and...

    Write a program in c++ that generates a 100 random numbers between 1 and 1000 and writes them to a data file called "randNum.dat". Then re-open the file, read the 100 numbers, print them to the screen, and find and print the minimum and maximum values. Specifications: If your output or input file fails to open correctly, print an error message that either states: Output file failed to open Input file failed to open depending on whether the output or...

  • C++ language Write a program that 1. generates a random integer between 100 and 1000, call...

    C++ language Write a program that 1. generates a random integer between 100 and 1000, call the number N 2. reads a file name from the keyboard 3. opens a file for output using the file name from step 2 4. generates N random numbers between 1 and 100 and writes them to the file from step 3 5. closes the file 6. opens the file from steps 3, and 4 for input 7. reads the numbers from the file...

  • My following program has an array which holds 1000 random integers between 1-1000. Now I need...

    My following program has an array which holds 1000 random integers between 1-1000. Now I need help to create an array that holds 10,000 random integer between 1-1000 in my following program. The main goal of this program is time analysis by using bubble sort and binary search algorithms. Please do the following task; 1. Replace the 1000 random integers with 10,000 random integers After change please answer the following question 2. what will be happen, if an array holds...

  • (c++) Write a program that generates a random number between 1 and 100 and asks the...

    (c++) Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Be sure that your program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT