Writing Random Numbers
CSC404, Data Structures
Programming Assignment 2
Due January 25, 2001
You are to write a program that will
-
Input a string that will be an output file name F and an input an integer
N
-
Fill an array with N random numbers
-
Write those N random numbers to the output file F, one number on each line.
Each of those three instructions are to be done using functions.
-
Test your program to create a file with a variety of values for N, both
small and large values.
-
Use your program to create a file "Assignment2.txt" containing 100 random
integers.
-
E-mail your text file along with your source code to albert@crawfordenterprise.com
-
When I reply to your e-mail it must get to you
-
The "from" must be your name.
-
The subject must be "CSC404 Assignment 2, Writing Random Numbers"
Text file input and output:
-
Open a file for input
#include <fstream.h>
fstream FileVar;
FileVar.open(filename, ios::out);
-
Open a file for output
#include <fstream.h>
fstream FileVar;
FileVar.open(filename, ios::in);
-
Close a file
FileVar.close();
-
Read from a file
FileVar >> dataValue;
-
Write to a file
FileVar << value1 << value2;
FileVar << value1 << value2 << endl;
Random numbers
creating a random number: Page 157-158
randomizing: Page 160-162
String Input
Section 5.12.1 Fundamentals of Characters and String, pages
322-331