Write a program MakeFile.cpp that creates a file random.dat that contains 200 ra
ID: 3554392 • Letter: W
Question
Write a program MakeFile.cpp that creates a file random.dat that contains 200 random numbers where each number is the sum of 12 random values rand( )%9. When we add a sufficient number of uniformly distributed numbers the result is approximately normally distributed. Close your file.
How do I do the bold part?
#include<iostream>
#include <fstream>
#include <ctime> // time()
using namespace std;
void randomize(void) // Home-made randomize
{
srand(time(NULL)); // Current time (seconds) used as a random seed
}
int main()
{
ofstream OS("random.dat", ios::out);
cout << " Start of program MakeFile ";
randomize();
for(int i=0; i<200; i++) OS << rand()%9 << ' ';
OS.close();
cout << "File random.dat created End of program MakeFile ";
return 0;
}
Explanation / Answer
please rate - thanks
#include<iostream>
#include <fstream>
#include <ctime> // time()
using namespace std;
void randomize(void) // Home-made randomize
{
srand(time(NULL)); // Current time (seconds) used as a random seed
}
int main()
{int sum;
ofstream OS("random.dat", ios::out);
cout << " Start of program MakeFile ";
randomize();
for(int i=0; i<200; i++)
{sum=0;
for(int j=0;j<12;j++)
sum+=(rand()%9);
OS << sum<< ' ';
}
OS.close();
cout << "File random.dat created End of program MakeFile ";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.