cant understand why this program not runing

Write your question here.
main
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
 #include"ArrayList.h"
#include<iostream>
using namespace std;
template<class T>

void func(ArrayList<T>&object) {
	int opt = 0;
	while (opt != 7) {
		cout << "1 to add element" << endl;
		cout << "2 add element + index" << endl;
		cout << "3 minmun value" << endl;
		cout << " 4 Maximun value" << endl;
		cout << "5 array size" << endl;
		cout << "print array values" << endl;
		cout << "exit" << endl;
		cin >> opt
			if (opt == 1) {
				T value = 0;
				bool input = false;
				while (!input) {
					cout << "ADD value " << endl;
					if (cin >> value) {
						object.addElement(value);
						input = true;
					}
					else {
						cout << "wrong input" << endl;
						input = false;
					}
					cin.clear();
					cin.ignore(INT_MAX, '\n');
				}

			}
			else if (opt == 2) {
				cout << "ADD value and index" << endl;
				int index = 0;
				T value;
				char c;
				bool flag = false;
				while (!flag) {
					cout << "Add value" << endl;
					if (cin >> value >> c >> index && index >= 0 && index <= object.getSize()) {
						object.addElement(value, index);
						flag = true;
					}
					else {
						cout << "wrong input" << endl;
						flag = false;

						cin.clear();
						cin.ignore(INT_MAX, '\n');
					}

				}

			}
			else if (opt == 3) {
				if (object.getSize() > 0) {
					cout << object.popMin() << endl;
				}
				else {
					cout << "cant find any value in the Array" << endl;
				}

			}

			else if (opt == 4) {
				if (object.getSize() > 0) {
					cout << object.popMax() << endl;
				}
				else {
					cout << "cant find any value in the Array" << endl;
				}

			}
			else if (opt == 5) {
				cout << object.getSize() << endl;
				cin.clear();
				cin.ignore(INT_MAX, '\n');
			}
			else if (opt == 6) {
				object.print();
				cin.clear();
				cin.ignore(INT_MAX, '\n');
			}
			else if (opt == 7) {
				cout << "Exit" << endl;


				cin.clear();
				cin.ignore(INT_MAX, '\n');
				break;
			}
			else {
				opt = 0;
				cin.clear();
				cin.ignore(INT_MAX, '\n');

			}

	}//end while
}









int main() {



	int option = 0;
	while (option != 3) {
		cout << "1- for integers Array" << endl;
		cout << "2-for char Array" << endl;
		cout << "3 to exit program" << endl;
		cin >> option;
		if (option == 1) {
			ArrayList<int>intArrayList;
			func(intArrayList);
			break;
		}
		else if (option == 2) {
			ArrayList<char>charArrayList;
			func(charArrayList);
			break;
		}
		else if (option == 3) {
			cout << "Exit program" << endl;
			break;
		}
		else {
			cout << "Not an option" << endl;
			option = 0;
			cin.clear();
			cin.ignore(INT_MAX, '\n');

		}
	}
	return 0;


}

header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once


template<class T>
class ArrayList {
private:
	T* storage;
	int size;
public:
	ArrayList();                                          //deafult constractor
	ArrayList(const ArrayList& copy);                   //copy constractor
	~ArrayList();                                      //destractor
	void addElement(T toAdd);                         //add new value to the array at the end of the array
	void addElement(T toAdd, int index);             //add new value to the current idex
	T popMin();                                     //return the min value
	T popMax();                                    //return max value
	int getSize()const;                           //return size of array
	void print()const;                         //print array values
};

cpp file
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
#include"ArrayList.h"
#include<iostream>
using namespace std;

template<class T>                                   //deafult constractor
ArrayList<T>::ArrayList() {
	this->size = 0;
}
template<class T>                                      //destractor
ArrayList<T>::~ArrayList() {

	delete[] this->storage;

}


template<class T>
ArrayList<T>::ArrayList(const ArrayList&copy) {         // copy constractor
	this->size = copy.getSize()
		this->storage = new T[this->size];
	for (int i = 0; i < this->size; i++) {
		this->storage[i] = copy.storage[i];
	}
}

template<class T>                                   //return the size of the array
int ArrayList<T>::getSize()const {
	return this->size;

}




template<class T>                                    //print
void ArrayList<T>::print()const {
	for (int i = 0; i < this->size; i++) {
		cout << this->storage[i] << endl;

	}
	cout << endl;

}


template<class T>
void ArrayList<T>::addElement(T toAdd) {                         //to add the first value to an empty array
	if (this->size == 0) {
		this->storage = new T[1];
		this->storage[0] = toAdd;
		this->size = this->size + 1;
	}
	else {


		T* newArray = new T[this->size];                           //first we declare new array with the same size of the previous array  and copy the values index by index 
		for (int j = 0; j < this->size; j++) {                     //and put the new value in the end of the new array .
			newArray[j] = this->storgae[j];

		}
		delete[] storage;
		this->storage = new T[this->size + 1];
		for (int i = 0; i < this->size; i++) {
			storage[i] = newArray[i];
		}
		storage[this->size] = toAdd;
		this->size = this->size + 1;



	}

}
template<class T>
void ArrayList<T>::addElement(T toAdd, int index) {
	if (index<0 || index>this->size) {
		cout << "ERROR" << endl;
	}

	else {                                                                                        //we do this only if index is Good 
		T* newArray = new T[this->size + 1];
		for (int i = 0; i < index; i++) {
			newArray[i] = this->storage[i];
		}

		for (int y = index + 1; y <= this->size; y++) {
			newArray[y] = this->storage[y - 1];
		}
		delete this->storage;
		this->storage = new T[this->size + 1];
		for (int i = 0; i < this->size; i++) {
			this->storage[i] = newArray[i];
		}
		this->size++;
	}



}
template<class T>                                                          //find maximum value
T ArrayList <T>::popMax() {

	if (this->size > 0) {
		T maxVal = this->storage[0];
		int maxId = 0;
		for (int i = 0; i < this->size; i++) {
			if (this->storage[i] > maxVal) {
				max = this->storage[i];
				maxId = i;
			}
		}


		T* newArray = new T[this->size - 1];                                         //open new array without the max value
		int s = 0;
		for (int j = 0; j < this->size - 1; j++) {
			if (j != maxId) {
				newArray[j] = this->storage[s];
			}
			else {
				s++;
				newArray[j] = this->storage[s];
			}

			s++;
		}
		delete[] this->storage;
		this->storage = new T[size - 1];


		for (int i = 0; i < this - size - 1; i++) {
			this->storage[i] = newArray[i]
		}
		delete[]newArray;
		this->size--;
		return maxVal;
	}
	else {
		cout << "ERROR" << endl;
		return 0;

	}
}

template<class T>
T ArrayList<T>::popMin() {
	if (this->size == 0) {
		cout << "ERROR" << endl;
		return 0;
	}
	else {
		T minVal = this->storage[0];
		int minId = 0;
		for (int i = 0; i < this->size; i++) {
			if (this->storage[i] > minVal) {
				minVal = this->storage[i];
				minId = i;
			}
		}
		T minArray = new T[this->size - 1];
		int t = 0;
		for (int i = 0; i < this->size - 1; i++) {
			if (i != t) {
				minArray[i] = this->storage[t];
			}
			else {
				t++;
				minArray[i] = this->storage[t];
			}
			t++;
		}
		delete[] this->storage;
		this->storage = new T[this->size - 1];
		for (int j = 0; j < this->size - 1; j++) {
			this->storage[j] = minArray[j];
		}
		delete[]minArray;
		this->size--;
		return min;

	}


}







for almsot 6 hours trying to understand why this program not running ..
visual says: the system canot find file spesifect
can you try to run it? did it run? what should i do?
First of all its a bad habit to post the entire code you have and just ask "why is it not running".
The best place to start is to give us a proper error message.
UNABLE TO START project
the system cant find the file specifect
Last edited on
#include"ArrayList.h"
Does that file really exist?
yes calss ArrayList
the header file
cant understand why this program not runing

sorry, neither could i after trying to read 350+ lines of your code
start over. Build a new project in your tool and bring the code into it, see if you can get the message to clear up. It sounds a little like a corrupted project file, but you didn't give us much to go on. (You don't have to change any code for this, its an attempt to see if you have a tool error only -- you can save what you have).
Last edited on
When you do have a viable project move all the template code into a header file.

https://isocpp.org/wiki/faq/templates#templates-defn-vs-decl
i try to do the projet again keep getting error
moved all the template function to the header file still problem
even delete visual studio and install again same problem.
..
its says unable to start project ...
and says the system cannot find the file specified .
(popup error)
is the file in the same folder ?
> UNABLE TO START project
> the system cant find the file specifect
post the full error message, just copy-paste it so there won't be typos.
also, ¿when does this happen?


http://stackoverflow.com/questions/17946772/the-system-cannot-find-the-file-specified-in-visual-studio
> the system cannot find the file specified usually means the build failed
> (...) but you have the 'run anyway' option checked which means it runs an
> executable that doesn't exist
¿what's the rationale behind this `run anyway' option?
Last edited on
¿what's the rationale behind this `run anyway' option?


I'm not sure what the rationale is, but the default is to ask the user if they want to run anyway.

This references an older version of VS, but it still works the same:
http://stackoverflow.com/a/596269
Topic archived. No new replies allowed.