-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
268 lines (205 loc) · 5.09 KB
/
main.cpp
File metadata and controls
268 lines (205 loc) · 5.09 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void fizzBuzzFunction(int loopData);
class Node {
public:
//default constructor & loaded
Node();
Node(int & newNumber, Node *& NewNode);
//int: getter & setter
int getNumber() const;
void setNumber(int newNumber);
//node: getter & setter
Node * getNext();
void setNext(Node * newNext);
int nodesCreated();
private:
int numbers = 0, nodeQt = 0;
Node * nextNode = nullptr;
};
Node::Node() {
numbers = 0;
nextNode = nullptr;
}
Node::Node(int &newNumber, Node *&NewNode) {
numbers = newNumber;
nextNode = NewNode;
}
int Node::getNumber() const {
return numbers;
}
Node *Node::getNext() {
return nextNode;
}
void Node::setNext(Node *newNext) {
nextNode = newNext;
}
void Node::setNumber(int newNumber) {
numbers = newNumber;
}
//return the number of nodes
int Node::nodesCreated() {
Node * sizeValue = nextNode;
while(sizeValue != nullptr)
{
nodeQt++;
sizeValue = sizeValue->getNext();
}
return nodeQt;
}
class NodeList{
public:
NodeList();
void addNode(int nodeValue);
void printNodes();
private:
Node * headNode;
int nodeQt = 0;
void printNodes(Node *h);
};
NodeList::NodeList() {
headNode = nullptr;
}
void NodeList::addNode(int nodeValue) {
//baseCase
if(headNode == nullptr || headNode == 0)
{
headNode = new Node();
headNode->setNumber(nodeValue);
headNode->setNext(nullptr);
}
//generalCase
else
{
Node * tempNode = headNode;
while (tempNode->getNext() !=0)
{
tempNode = tempNode->getNext();
}
tempNode->setNext(new Node);
tempNode->getNext()->setNumber(nodeValue);
tempNode->getNext()->setNext(0);
}
}
//prints the nodes made
void NodeList::printNodes(Node * h) {
Node * tempNode = headNode;
while(tempNode != nullptr)
{
cout << tempNode->getNumber() << " " << endl;
tempNode = tempNode->getNext();
}
}
string fizzBuzz(int number)
{
unsigned newData = number;
//empty string to add either fizz || buzz
string fizzString;
//for loop based on the input
for(int i = 1; i <= newData; i++)//condition on the amount of loops
{
if(i % 3 == 0 && i % 5 == 0)//modules of 3 && 5 == 0(FizzBuzz)
{
fizzString = "FizzBuzz";
}
else if(i % 3 == 0)//modules of 3 == 0(Fizz)
{
fizzString = "Fizz";
}
else if(i % 5 == 0)//modules of 5 == 0(Buzz)
{
fizzString = "Buz1z";
}
else
{
fizzString = to_string(i); //if not int the number sequence print the number
}
cout << fizzString << endl;//printing & changing the string to a new
}
return "";
}
int main()
{
//cout << fizzBuzz(33)<< endl;
Node * first = nullptr;
Node * second = nullptr;
Node * third = nullptr;
//being added on the heap
first = new Node();
second = new Node();
third = new Node();
first->setNumber(1);
second->setNumber(2);
third->setNumber(3);
first->setNext(second);
second->setNext(third);
third->setNext(nullptr);
cout << "Number: "<<first->nodesCreated();
NodeList p;
p.printNodes(first);
/*
//fizzBuzzFunction(15);//calling function
vector<int> newVec;
int count = 0, number = 0, find = 0;
newVec.push_back(1);
newVec.push_back(5);
newVec.push_back(10);
newVec.push_back(15);
newVec.push_back(20);
newVec.push_back(25);
newVec.push_back(30);
cout << "Find data: "<<endl;
cin >> number;
for(int i = 0; i <newVec.size(); i++)
{
cout <<"File: "<< newVec[i] << endl;
if(newVec[i] == number)
{
//count++;
i = find;
cout << "Items: "<< newVec.at(find) << endl;
if(i == find)
{
continue;//continues through the loop even after a name was found(in case more ducks)
}
}
else
{
cout << "not here"<< endl;
find = -1;
}
}
*/
return 0;
}
//fizzBuzz function generator
void fizzBuzzFunction(int loopData)
{
//if number entered by user is < 0 then make it a positive
unsigned int positiveNumber = loopData;
//empty string to add either fizz || buzz
string fizzString;
//for loop based on the input
for(int i = 1; i <= positiveNumber; i++)//condition on the amount of loops
{
if(i % 3 == 0 && i % 5 == 0)//modules of 3 && 5 == 0(FizzBuzz)
{
fizzString = "FizzBuzz";
}
else if(i % 3 == 0)//modules of 3 == 0(Fizz)
{
fizzString = "Fizz";
}
else if(i % 5 == 0)//modules of 5 == 0(Buzz)
{
fizzString = "Buzz";
}
else
{
fizzString = to_string(i); //if not int the number sequence print the number
}
cout << fizzString << endl;//printing & changing the string to a new
}
}