Getting my code to print out the sequential section

I am trying to print out the sequential part of my code. It is not working. Nothing is printing.

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
my.class.h
#ifndef MYCLASS_H
#define MYCLASS_H

#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <ostream>
enum myMode { SEQUENTIAL, PRIME, COMPOSITE, FIB};

using namespace std;

template<typename T>
class MyArray
{
private:
	int maxSize = 0; 
	T* myArray;
	int currentSize = 0;
	int size = 0;
	//int index;

public:
	MyArray(const int ARRAY_SIZE) {
		myArray = (T*)malloc(sizeof(T)*ARRAY_SIZE);
		maxSize = ARRAY_SIZE;
		currentSize = 0;
	};

	void push_back(T item) {
		myArray[currentSize] = item;
		currentSize++;
		/*for (int i = 0; i < currentSize.size(); i++) {
			currentSize;
		}*/
	};
	~MyArray() {}

	class Iterator
	{
	private:
		// Iterator data and functions
		int numbers = 0;
		int myMode = 0;
		int sizeTwo = 0;
		int pointerTwo = 0;
		T* vecWin;
		
	public:
		Iterator(T* vec) {
			vecWin = vec;
		};
		Iterator(T* vec, int size) {
			vecWin = vec;
			sizeTwo = size;
		};
		Iterator(T* vec, int size, int pointer) {
			vecWin = vec;
			pointerTwo = pointer;
			sizeTwo = size;
		};
		Iterator(T* vec, int size, int pointer, int mode) {
			vecWin = vec;
			pointerTwo = pointer;
			sizeTwo = size;
			myMode = mode;
		};
		bool operator!=(const Iterator& other) const {
			//need to be able to compare the iterator to other and have it do stuff
			/*if (other == mode) {

			}*/
			return false;
		};
	
		void operator++() {
			if (myMode == SEQUENTIAL) {
				//sizeTwo++;//this is the only if else statement that should theoritically do what it is suppose to. I really wonder if I am ever going to figure this out.
				//vecWin++;
				pointerTwo++;
			}
			else if (myMode == PRIME) {
				//need to be able to go through the prime numbers
				vecWin++;//temp 
			}
			else if (myMode == COMPOSITE) {
				//need to go through and 1 2 4 8 
				vecWin++;//temp
			}
			else if (myMode == FIB) {
				vecWin++;//temp
			}
		
		};
		//cout << i << endl interger
		//cout << *i << endl pointer
		//cout << &i << endl reference to the pointer -pointer pointer or the address of the address 
		T& operator*() const {
			return *vecWin;
		};
		T& operator[](int i) const {
			//return MyArray[i];//temp
			return vecWin[i];
		};
		string toString() const {
			stringstream ss;
			ss << "size=" << sizeTwo << " index=" << vecWin << " mode=" << myMode << endl;
			return ss.str(); 
		};
		friend ostream& operator<< (ostream& os, Iterator& iter) {
			os << iter.toString();// mode is working however size and index aren't
			return os;
		};
	};
	Iterator begin() {
		return Iterator(myArray, currentSize, 0);
	};
	Iterator begin(int mode) {
		return Iterator(myArray, currentSize, 0, mode);
	};
	Iterator end() {
		return Iterator(myArray, currentSize, 0);
	};
	
	string toString() const {
		ostringstream out;
		for (int i = 0; i < currentSize; i++) {
			out << myArray[i] << " ";
		}
		return out.str();
	};
	friend ostream& operator<< (ostream& os, const MyArray<T>& myArray) {
		os << myArray.toString();
		return os;
	};
};
#endif // MYCLASS_H
main.cpp
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include "myClass.h"
#define MAX_ARRAY_SIZE	1000
//enum myMode { SEQUENTIAL, PRIME, COMPOSITE, FIB };

using namespace std;

#ifdef _MSC_VER
#define _CRTDBG_MAP_ALLOC  
#include <crtdbg.h>
#define VS_MEM_CHECK _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#else
#define VS_MEM_CHECK;
#endif

/*********************************************************************
*********************************************************************/
int main(int argc, char * argv[]) {
	VS_MEM_CHECK;// checking for leaks
	//ifstream in(argv[1]);
	//ostream& out = (argc < 3);
	string inputFile = argv[1];
	string outputFile = argv[2];
	int data = 0;
	
	ifstream in(inputFile);//Opening the file

	if (!in.is_open()) return -1;
	ofstream out(outputFile);

	MyArray<int> numbers(MAX_ARRAY_SIZE);// doing the my array and printing out the array
	while (!in.eof()) {
		in >> data;
		numbers.push_back(data);
	}
	out << "myARRAY" << endl;
	out << numbers << endl << endl;

	out << "SEQUENTIAL" << endl;//Going through the array sequentially
	MyArray<int>::Iterator iter1 = numbers.begin();
	out << "iter1: " << iter1 << endl;
	for (MyArray<int>::Iterator iter1 = numbers.begin(); iter1 != numbers.end(); ++iter1) {
		out << *iter1 << ' ';
	}
	out << endl << endl;

	out << "PRIME" << endl;//Going through the prime numbers
	MyArray<int>::Iterator iter2 = numbers.begin(PRIME);
	out << "iter2: " << iter2 << endl;
	for (MyArray<int>::Iterator iter2 = numbers.begin(PRIME); iter2 != numbers.end(); ++iter2) {
		out << *iter2 << ' ';
	}
		out << endl << endl;

	out << "COMPOSITE" << endl;//Going through the composite
	MyArray<int>::Iterator iter3 = numbers.begin(COMPOSITE);
	out << "iter3: " << iter3 << endl;
	for (MyArray<int>::Iterator iter3 = numbers.begin(COMPOSITE); iter3 != numbers.end(); ++iter3) {
		out << *iter3 << ' ';
	}
	out << endl << endl;

	out << "FIBINOCCI" << endl;// Going through the finbinocci sequence
	MyArray<int>::Iterator iter4 = numbers.begin(FIB);
	out << "iter4: " << iter4 << endl;
	for (MyArray<int>::Iterator iter4 = numbers.begin(FIB); iter4 != numbers.end(); ++iter4) {
		out << *iter4 << "=" << iter4[-2] << "+" << iter4[-1] << ' ';
	}
		out << endl << endl;

	in.close();//Closing the files
	out.close();

	return 0;
};

1
2
3
4
5
6
7
8
9
bool operator!=(const Iterator& other) const {
   return false;
}

for (
   MyArray<int>::Iterator iter1 = numbers.begin();
   iter1 != numbers.end(); //alway false, so never enter the loop
   ++iter1
) {
Topic archived. No new replies allowed.