Question
Asked Sep 18, 2019
33 views

 

In C++ 

1. Create function called DoubleFillArray that takes in an empty array of size 100 and fills it with doubles between 0 and 1 (3 digits each).  Create another function called OutPutArrayToFIle that takes in the array and outputs it to a file called THEFILE. 

check_circle

Expert Answer

Step 1

Program Instructions:

  • In function DoubleFillArray, use rand() method to fill random numbers with doubles between 0 and 1 in the array.
  • In function OutPutArrayToFIle, create a file and save the values of the array in the file THEFILE.txt.
Step 2

Program:
#include <iostream>

#include<fstream>

using namespace std;

void OutPutArrayToFIle(double array[]){

     ofstream myfile;

     myfile.open ("THEFILE.txt");

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

          myfile <<array[i];

     }

}

void DoubleFillArray(double array[]){

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

          array[i] = (double)(rand() % 100) / 100 ;

     }

     cout<<"Contents of array:"<<endl;

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

          cout<<array[i]<<" ";

     }

     OutPutArrayToFIle(array);

}

int main(){

     double a[100];

     DoubleFillArray(a);

     return 0;

}

Step 3

Sample Output:

...
help_outline

Image Transcriptionclose

Contents of array: e.41 0.67 0.34 e e.69 e.24 0.78 0.58 0.62 0.64 e.05 e.45 .81 0.27 0.61 0.91 0.95 e.42 0.27 0. 36 0.91 0.04 e.02 e.53 e.9 2 0.82 0.21 0.16 e.18 e.95 e.47 0.26 e.71 0.38 e.69 0.12 0. 67 e.99 e.35 e.94 e.03 e.11 0.22 0.33 0.73 0.64 e.41 e.11 0.5 3 0.68 .47 e.44 0.62 .57 0.37 e.59 e.23 .41 0.29 0.78 e.16 0.35 .9 e.42 0.88 .06 0.4 0.42 0.64 e.48 e.46 0.05 e.96 29 0.7 0.5 e.06 e.01 e.93 e.48 . 29 e.23 e.84 e.54 0.56 0.4 e.66 e.76 e.31 0.e8 e.44 0.39 0.26 .23 e.37 e.38 e.18 e.82 e.29 e.41 Process exited after 1.554 seconds with return value Press any key to continue

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
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: 4.23 (Financial application: payroll) Write a program that reads the following information and print...

A: C code#include&lt;stdio.h&gt;#include&lt;string.h&gt; int main(){char employeeName[20]="";double hou...

question_answer

Q: Hence the grammar:         G: ({S, A, B}, {a, b}, S, { S →bbAbabB,  A → aA|B| λ  , B → bB|A| λ}) Dra...

A: Derive the string bbaababaa with the given grammar using either leftmost or right most derivation.De...

question_answer

Q: Hello,  I am trying to write a program in Pynthon. I do not know may be it is too much. Just need so...

A:  Program plan:Define a function named “main()”.Assign a file name or file path.Create an empty dicti...

question_answer

Q: Prove that the following languages are not regular: (b) L = {anblak : k ≠ n + l}.

A: First, assume the given language is regular.Then apply pumping lemma to prove the statement is not r...

question_answer

Q: Associate each of the following concepts with one of the languages we covered (pseudo code,FORTRAN, ...

A: Associating languages with given concepts:ALGOL 60: Pass by nameALGOL 60: Pass by valueFORTRAN: Assi...

question_answer

Q: Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles...

A: Program Instructions:Take car's miles/gallon and gas dollars/gallon as input using scanner class.Cal...

question_answer

Q: Question 2 3 4

A: Question 2:Given binary value = 11012   The given binary value does not represents the decimal numbe...

question_answer

Q: What type of technique is used when an image is transferred by forcing ink through fine mesh or silk...

A: SerigraphySerigraphy also known as screen printing or silkscreen printing is a printing technique wh...

question_answer

Q: I need help with the SQL query for the following question: 1.  Get the total number of reviews of mo...

A: The details about the table are given with table name and different entities. Here the table name is...