1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
arsen [322]
2 years ago
10

Write a program that writes 10 random numbers into a file named numbers using loops.

Computers and Technology
1 answer:
MariettaO [177]2 years ago
3 0

Answer:

The program in cpp for the given scenario is shown below.

#include <stdio.h>

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

   //object created of file stream

   ofstream out;

   //file opened for writing

   out.open("numbers.txt");

   std::cout << "File opened." << std::endl;

   //inside for loop, random numbers written to numbers.txt using rand()

   for(int n=0; n<10; n++)

   {

       out<<rand()<<endl;

   }

   //file closed

   out.close();

   std::cout << "File closed." << std::endl;

   return 0;

}

Explanation:

1. An object of the ofstream is created. The ofstream refers to output file stream. This is used to create file for write and append operations.

ofstream out;

2. The file named, numbers.txt, is opened using the open() method with the object of ofstream.

out.open("numbers.txt");

3. The message is displayed to the user that the file is opened.

4. Inside a for loop, which executes 10 times, a random number is generated. This random number is written to the file and a new line inserted.

5. The random number is generated using rand() method. Every number is written on  new line.

out<<rand()<<endl;

6. Every execution of the for loop repeats steps 4 and 5.

7. When the loop ends, the file is closed using close() method with the object of ofstream.

out.close();

8. A message is displayed to the user that the file is closed.

9. The header file, fstream, is included to support file operations.

10. The extension of the file can be changed from .txt to any other type of file as per requirement.

11. The program can be tested for writing more numbers to the file.

12. The program can be tested for writing any type of numeric data to the file.

13. The program is written in cpp due to simplicity.

14. In other languages such as java or csharp, the code is written inside classes.

15. In cpp, all the code is written inside main() method.

16.    The screenshot of the output messages displayed is attached.

You might be interested in
____ convert a program design developed by a systems analyst or software developer using one of many computer languages.
erica [24]

Answer:

"Programmer " is the correct answer for the following question.

Explanation:

A programmer is a person who created the software They are basically a coder who develop a code for the program or the software. They are specialists in some in the programming code area. The programmer are writing the program for a different kind of software.

The main objective programmer they convert the program design which is developed  by a systems analyst or system designer using a different kind of computer language  

4 0
3 years ago
Which of the following identifies the patterns used for each data series in a chart?
Lady_Fox [76]
The answer is A)Legend.
7 0
3 years ago
Which of the following forces all traffic, communications, and activities through a single pathway or channel that can be used t
Ad libitum [116K]

Answer:

Option b. Choke point

Explanation:

In firewall, a choke point can be defined as a single point which allows all of the network traffic including incoming and outgoing to be funneled. As the passage of the whole traffic through the choke point regulates the flow as it focus monitoring  and controls bandwidth consumption, provides authentication, control efforts like Internet firewalls.

7 0
2 years ago
The fast movement of briefly flashed images in an animated motion picture produces what effect? subliminal messaging convergence
REY [17]

Answer:

The answer is Stroboscopic movement

Explanation:

Stroboscopic movement occurs when we do not see a motion continuously but in discrete shots. It is an effect in which we see an object at one place and after another instant the object seems to have shifted it's position.

Auto kinetic effect is an effect in which a stationary point of light appears to move.It occurs as our brains can perceive motion relative to some other object and cannot observe ,motion along a featureless terrain or environment.

Phi effect causes an observer to perceive motion in stationary objects.

3 0
2 years ago
Is there an answer to these picture?
Tomtit [17]

Answer:

yes there is an answer to this question

6 0
3 years ago
Other questions:
  • True or False. It is required to restart the client computer after the DLP agent has been installed.
    9·2 answers
  • Buildings must be wired to comply with the latest National Electrical Code to ensure that, with adequate maintenance, the instal
    11·1 answer
  • A collision between gas atoms and electrons raises the energy levels of oxygen and nitrogen in the _________.
    8·2 answers
  • Why should you need to have skills and an understanding about programming?
    8·1 answer
  • When are number list generally used ?
    10·1 answer
  • What is the cell reference for the cell located in the second column and fifth row of a worksheet?
    9·1 answer
  • What stylistic device does Reverend Jesse Jackson use in the following statement: "We must relate instead of debate; we must ins
    10·1 answer
  • The force required to slide an object is equal to _____.
    13·1 answer
  • Using the drop-down menu, complete these sentences to describe algorithms. Algorithms are instructions to solve a problem. Algor
    12·2 answers
  • computer is an electronic machine that is used for data processing to produce meaningful information explain in statement​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!