-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberFileGenerator.cpp
98 lines (80 loc) · 1.6 KB
/
NumberFileGenerator.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @file NumberFileGenerator.h
* @author Will Ashley
* @date 2015.11.03
* @Description: Generates either random, ascending, descending or signle values fof the number file depending on the
* user's choice.
* * */
#include "NumberFileGenerator.h"
void NumberFileGenerator::ascending(std::string fileName, int amount)
{
std::ofstream write(fileName);
if(write.good())
{
if(amount > 0)
{
write << amount << "\n";
for(int i = 1; i < amount; i++)
write << i << "\n";
}
}
else
{
}
write.close();
}
void NumberFileGenerator::descending(std::string fileName, int amount)
{
std::ofstream write(fileName);
if(write.good())
{
if(amount > 0)
{
write << amount << "\n";
for(int i = 1; i < amount; i++)
write << amount - i << "\n";
}
}
else
{
}
write.close();
}
void NumberFileGenerator::random(std::string fileName, int amount, int min, int max)
{
//Declare and seed a generator
std::default_random_engine generator(time(nullptr));
//Declare a distribution and define the range of the random numbers
std::uniform_int_distribution<int> distribution(min, max);
std::ofstream write(fileName);
if(write.good())
{
if(amount > 0)
{
write << amount << "\n";
for(int i = 1; i < amount; i++)
write << distribution(generator) << "\n";
}
}
else
{
}
write.close();
}
void NumberFileGenerator::singleValue(std::string fileName, int amount, int value)
{
std::ofstream write(fileName);
if(write.good())
{
if(amount > 0)
{
write << amount << "\n";
for(int i = 1; i < amount; i++)
write << value << "\n";
}
}
else
{
}
write.close();
}