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]
3 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]3 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
Why would it be beneficial to preview a page before printing?
enyata [817]
To make sure it looks how you want it to look, or to make sure all the info is correct and we're it should be.
4 0
3 years ago
A network administrator notices that some newly installed Ethernet cabling is carrying corrupt and distorted data signals. The n
OleMash [197]

Answer: EMI(Electromagnetic interference)

               RFI(Radio frequency interference)

Explanation: Electromagnetic interference is the emission of the electromagnetic signal that can disturb the working of the other device.It invokes the disturbance that can create error, under-performance mechanism,distortion etc in the equipment.

Radio-frequency interference(RFI) is the radio-frequency signal that interferes the other device by creating noise and distortion. This leads to breaking of the operation and data error.

Other options are incorrect because cross talk is referred as undesired communication between signal ,attenuation is the degradation in the  amplitude of any signal and extended length of cabling is increasing the length of the cable.Thus the correct answer is RFI and EMI.

4 0
4 years ago
Octal numbers have a base of eight and the digits 0–7. Write the scripts octalToDecimal.py and decimalToOctal.py, which convert
Burka [1]

Answer:

See explaination

Explanation:

#input

o_t_n=int(input('Enter a string of octal digits: '))

#required variables

i = 1

dc = 0

#loop for conversion

while (o_t_n != 0):

#to find remainder

rmd = o_t_n % 10

o_t_n //= 10

dc += rmd * i

i *= 8

#print the results

print('The integer value is ',dc)

# decimalToOctal.py

#input

d_c_n=int(input('Enter a decimal integer: '))

print("Quotient Remainder Octal")

#required variables

i = 1

o_c_n = 0

num=""

#loop for conversion

while (d_c_n != 0):

#to find remainder

rm = d_c_n % 8

d_c_n //= 8

o_c_n = o_c_n + rm * i

i *= 10

num = str(rm)+num

print("%5d%8d%12s" % (d_c_n, rm, num))

#print the results

print('The octal representation is ',o_c_n)

4 0
4 years ago
To set up a slide show you should do all of the following except ______.
Harlamova29_29 [7]
To set up a slide show you should do all of the following except exit without saving
5 0
4 years ago
Can someone pls tell me how?​
sertanlavr [38]

Explanation:

yaaaaaaaaaassssssss

7 0
3 years ago
Other questions:
  • Explain why computer users should use the cloud?
    14·1 answer
  • Which business document is usually written in block style with the body tedt aligned along its left margin?
    9·1 answer
  • Describe three perimeter intrusion detection systems and give an example of one that you have seen deployed either at work or an
    8·1 answer
  • (a) [5 pts] Suppose you purchase a wireless router and connect it to your cable modem. Also suppose that your ISP dynamically as
    13·1 answer
  • 52. Which of the following numbering system is used by the computer to display numbers? A. Binary B. Octal C. Decimal D. Hexadec
    12·2 answers
  • What are the main dimensions of information system and their components
    13·1 answer
  • What is meant by editing a document​
    5·2 answers
  • Use a for loop to output the numbers from 50 to 65
    6·1 answer
  • Identify and state the value of hardware components​
    12·1 answer
  • Which web source citations are formatted correctly? check all that apply.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!