menu
bartleby
search
close search
Hit Return to see all results

In C++ Create a function called SuperRandomNumber. It should accept a number called top as the argument. It should output to a file 100 random numbers below top.

Question

In C++

 

Create a function called SuperRandomNumber. It should accept a number called top as the argument. It should output to a file 100 random numbers below top.

check_circleAnswer
Step 1

Note:

The following program creates a function “SuperRandomNumber()” which accepts “top” as argument and the output file must include about 100 random numbers below the “top” argument.

  • Here, the “txt” file stores the 100 generated random numbers below the range of “top” argument.
Step 2

Program (Editable code):

 //Header file section

#include <iostream>

#include <fstream>

#include <cstdlib>

#include <ctime>

using namespace std;

//Create the function SuperRandomNumber()

void SuperRandomNumber(int top)

{

     //Write the numbers into text file

     ofstream out("numbers.txt");

     //Iterate the loop until it generates 100 numbers

     for (int i = 0; i < 100; i++)

{

          /*Print the random number generated within the

         range of "top"*/

          out << rand() % top << endl;

     }

     //Close the output file

     out.close();

}

//Main() function

int main()

{

     /*Remain with the same seed number until it completes

the iteration*/

     srand(time(NULL));

     //Call the SuperRandomNumber() function

     SuperRandomNumber(1000);

     //Return the value

     return 0;

}

Step 3
/Header file section
#include <iostream
#include <fstream
#include <cstdlib>
#include <ctime>
using namespace std;
//Create the function SuperRandomNumber ()
void SuperRandomNumber (int top)
{
//Write the numbers into text file
ofstream out ("numbers.txt");
//Iterate the loop until it generates 100 numbers
for (int i
0 i 100; i++
/*Print the random number generated within the
range of "top" */
out rand () % top <« endl;
}
//close the output file
out.close ();
}
help_outline

Image Transcriptionclose

/Header file section #include <iostream #include <fstream #include <cstdlib> #include <ctime> using namespace std; //Create the function SuperRandomNumber () void SuperRandomNumber (int top) { //Write the numbers into text file ofstream out ("numbers.txt"); //Iterate the loop until it generates 100 numbers for (int i 0 i 100; i++ /*Print the random number generated within the range of "top" */ out rand () % top <« endl; } //close the output file out.close (); }

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: I have a question about blockchain technologies. The question states "Describe three components of b...

A: Solution:Blockchain technologies:Blockchain is a technology which permits the digital data to be dis...

question_answer

Q: Typically, a hospital patient receives medication that have been ordered by a particular doctor. Bec...

A: Lets write the business logic first. The business rules between PATIENT and ORDER will be.• A patien...

question_answer

Q: how can I write a statement in C++ that would print last name, followed by a comma, followed by firs...

A: Given below is the C++ program to print a statement with last name, followed by comma, followed by f...

question_answer

Q: Question: Write a program that prompts the user to enter the number of students and each student's s...

A: Solution:The python program has the following algorithm:Prompt and read the total number of students...

question_answer

Q: Cell Phones Records In this part, you are required to write a program, using linked lists, that man...

A: In the given question, some parts of the question are missing to use linked lists.Here, I have creat...

question_answer

Q: How can I check if a binary number is an even number. So, the binary has a 0 remainder when divided ...

A: Approach: Result = (((n &gt;&gt; 1) &lt;&lt; 1) == n). First we shift the 1 bit right then we shift ...

question_answer

Q: Write a GUI application that calculates a car’s gas mileage. The application should let the user ent...

A: Program plan:Test.javaImport the required header filesDefine “Test” classCreate an object for the “M...

question_answer

Q: write a program in c++. You work for a box company, and have been asked to write a program to compar...

A: Click to see the answer

question_answer

Q: Are climate change models accurate?

A: DescriptionClimate Models are basically an add-on of weather forecasting models. But these models ar...

Sorry about that. What wasn’t helpful?