-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAssignment01_SampleCode.cpp
executable file
·53 lines (45 loc) · 1.17 KB
/
Assignment01_SampleCode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ----- Headers.
// C headers come first.
#include <cmath>
#include <cstdlib>
#include <ctime>
// C++ headers come next.
#include <iostream>
#include <fstream>
// ----- Global declarations.
using namespace std;
const double PI = 3.14159265;
// ----- Function prototypes.
void line_maker(); // Draws lines of random length in file "linegraph.txt".
void graph_maker(); // Draws a sine graph as text in file "graph.txt".
// ----- Main program.
int main()
{
// Seed random number generator and draw lines.
srand(time(NULL));
line_maker();
// Return with success.
return 0;
}
// ----- Function definitions.
// Draws a sine graph as text in file "graph.txt".
void graph_maker()
{
// ... your code here.
}
// Draws lines of random length in file "linegraph.txt".
void line_maker()
{
// Open file for writing.
ofstream myfile("linegraph.txt");
// Write 10 lines of random length to file.
for (int count = 0; count < 10; count++) {
int random = rand() % 10; // random in [0,9]
cout<<random<<" ";
for (int i = 0; i<random; i++)
myfile<<"*";
myfile<<"\n";
}
// Close file.
myfie.close();
}