-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrangeGen.h
More file actions
140 lines (130 loc) · 4.89 KB
/
rangeGen.h
File metadata and controls
140 lines (130 loc) · 4.89 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//Adsero Mason
//rangeGen.h
//24 February 2020
//Windows
//
//Revision History:
// Jan 20:
// Created rangeGen class and most member functions and variables
// and implemented constructor copy constructor and copy assignment.
// Jan 21:
// added helper functions NumGen and random number generator.
// Jan 22:
// implemented the three main functionality of RangeGen and a helper
// copy function.
// Feb 23:
// added all overloaded functionality declarations to the header.
//interface invariants:
// 1. RangeGen creates numGen with randomized numbers where every
// numGen has two distinct values.
// 2. RangeGen can create as many numGens as the user wishes.
// 3. User input into RangeGen constructor is positive and non zero.
// 4. UserInput variable must be equal to or smaller than the size.
// 5. User can toggle the state of the object between active and inactivee.
// 6. User will only recieve valid values while RangeGen is Active.
// 7. The number the user inputs for finding the sum, numdivisible
// and xth value is no larger than the size use inputs
// 8. Default constructor supported.
// 9. User can track active state through the function getActive()
// 10. addition and subtraction add the numGens of a rangeGen object.
// the object of larger sizes numGens are appended to the result
// once the smaller object has run out of numGens to subtract.
// 11. comparisons compare the size of rangeGens as comparing there numGens makes
// little since and would be a non-sensicle comparison.
// 12. mixed mode subtraction is supported and will invert the call
// 1 - rangeArray[i] to rangeArray[i] - 1 as you cannot subtract a rangeGen
// from a number.
//Class invariants:
// 1. All user input is postitive in construction
// 2. numGens are in a dynamically allocated array.
// 3. RangeGen will prevent numGen objects from containing duplicates.
// 4. RangeGen supports copying and move semantics
// 5. RangeGen also checkts if a Numgen is active and resets it if
// it is inactive before running primary functionaluty to prevent
// the return of invalid data.
// 6. Designed to take user input size and number to use in rangeGen functionality.
// 7. Copy semantics supported so an object may take responsibility for another.
// 8. Client must track the state of activity which they change through the toggle
// active function.
// 9. addition, subtraction and mixed modes of these are supported.
// 10. comparisons are widely supported and compare size of RangeGen objects.
// 11. rangeGen + a numGen is supported. However you cannot
// add a rangeGen to a numGen as this makes little senses. Subtraction is
// supported in this context.
// 12. Multiplication and division are not supported.
#ifndef RANGEGEN_H
#define RANGEGEN_H
#include <ctime>
#include <cstdlib>
#include <iostream>
#include "numGen.h"
using namespace std;
class RangeGen
{
public:
RangeGen(unsigned int rangeNum = DEFAULT_SIZE, unsigned int userNum =
DEFAULT_INPUT);
RangeGen(const RangeGen& one);
RangeGen& operator=(const RangeGen& one);
RangeGen(RangeGen&& src);
RangeGen& operator=(RangeGen&& src);
~RangeGen();
//Precondition: RangeGen Is Active
int sumOfNumGen();
//Precondition: RangeGen is active
int valueOfXth();
//Preconditions: rangeGen is active
int numDivisible();
//Postconditions: object is made active of inactive
void toggleActive();
bool getActive();
RangeGen operator+(const RangeGen& src);
RangeGen operator+(int number);
RangeGen operator+(const NumGen& src);
RangeGen operator-(const RangeGen& src);
RangeGen operator-(int number);
RangeGen operator-(const NumGen& src);
RangeGen operator++();
RangeGen operator++(int dummy);
RangeGen operator--();
RangeGen operator--(int dummy);
RangeGen operator+=(const RangeGen& one);
RangeGen operator+=(int number);
RangeGen operator+=(const NumGen& src);
RangeGen operator-=(const RangeGen& one);
RangeGen operator-=(int number);
RangeGen operator-=(const NumGen& src);
bool operator==(const RangeGen& one);
bool operator!=(const RangeGen& one);
bool operator<(const RangeGen& one);
bool operator>(const RangeGen& one);
bool operator<=(const RangeGen& one);
bool operator>=(const RangeGen& one);
friend ostream& operator<<(ostream& output, const RangeGen& d);
private:
static const unsigned int DEFAULT_SIZE = 6, MAX = 25, DEFAULT_INPUT = 3;
NumGen * rangeArray;
int numOne, numTwo;
unsigned int rangeNum, userInput, size;
bool isActive;
int randomNumGenerator();
void resetNumGenIndex(int i);
void copy(const RangeGen& one);
};
inline RangeGen operator-(int number, RangeGen& one)
{
return one - number;
}
inline RangeGen operator+(int number, RangeGen& one)
{
return one + number;
}
inline RangeGen operator+(NumGen& src, RangeGen& one)
{
return one + src;
}
inline RangeGen operator-(NumGen& src, RangeGen& one)
{
return one - src;
}
#endif