r6010 abort() has been called

Hello,
i am having this following error and here bellow is my code!
The error i am getting is when b.ListA enters the function insert in the AList class.
Can anyone help?
I have no idea how and what is causing this error :(

The functions and classes:

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
  #include <iostream>
#include <string>
using namespace std;

int DefaultListSize = 20;

class Student
{
private:
	int id;
	string major;
public:
	Student(int a = 0, string b = " ")
	{
		id = a;
		major = b;
	}
	int GetId()
	{
		return id;
	}
	string GetMajor()
	{
		return major;
	}
	void SetStudent()
	{
		int a;
		string b;
		cout << "\nPlease enter the id of the student:\n";
		cin >> a;
		cout << "\nPlease enter the major of the student:\n";
		cin >> b;
		id = a;
		major = b;
	}
	void SetStudent(int a, string b)
	{
		id = a;
		major = b;
	}
	void print()
	{
		cout << "\nThis student has the following id: " << id << " and the following major: " << major << ".\n";
	}
};

template <class Elem>
class List
{
public:
	virtual void clear() = 0;
	virtual bool insert(const Elem&) = 0;
	virtual bool append(const Elem&) = 0;
	virtual bool remove(Elem&) = 0;
	virtual void setStart() = 0;
	virtual void setEnd() = 0;
	virtual void prev() = 0;
	virtual void next() = 0;
	virtual int leftLength() const = 0;
	virtual int rightLength() const = 0;
	virtual bool setPos(int pos) = 0;
	virtual bool getValue(Elem&) const = 0;
	virtual void print() const = 0;
};

template <class Elem> // Array-based list
class AList : public List<Elem>
{
private:
	int maxSize;     // Maximum size of list
	int listSize;    // Actual elem count
	int fence;       // Position of fence
	Elem* listArray; // Array holding list
public:
	AList(int size = DefaultListSize)
	{
		maxSize = size;
		listSize = fence = 0;
		listArray = new Elem[maxSize];
	}
	AList(const AList &obj) //copy constructor
	{
		maxSize = obj.maxSize;
		listSize = fence = 0;
		listArray = new Elem[maxSize];
		*listArray = *obj.listArray;
	}
	~AList() { delete[] listArray; }
	void clear()
	{
		delete[] listArray;
		listSize = fence = 0;
		listArray = new Elem[maxSize];
	}
	void setStart() { fence = 0; }
	void setEnd() { fence = listSize; }
	void prev()   { if (fence != 0) fence--; }
	void next()   {
		if (fence < listSize)
			fence++;
	}
	int leftLength() const  { return fence + 1; }
	int rightLength() const
	{
		return listSize - fence - 1;
	}
	bool setPos(int pos)
	{
		if ((pos >= 0) && (pos < listSize))
			fence = pos;
		return (pos >= 0) && (pos < listSize);
	}

	bool getValue(Elem& it) const
	{
		if (rightLength() < 0) return false;
		else {
			it = listArray[fence + 1];
			return true;
		}
	}
	bool insert(const Elem& item)
	{
		if (listSize == maxSize) return false;

		for (int i = listSize + 1; i>fence; i--)
			// Shift Elems up to make room
			listArray[i] = listArray[i - 1];

		listArray[fence + 1] = item;
		listSize++; // Increment list size
		return true;
	}
	bool append(const Elem& item) //??? what's the problem
	{
		if (listSize == maxSize) return false;

		listArray[listSize++] = item;

		return true;
	}
	bool remove(Elem& it)
	{
		if (rightLength() < 0) return false;

		it = listArray[fence + 1]; // Copy Elem

		for (int i = fence + 1; i<listSize; i++)
			// Shift them down
			listArray[i] = listArray[i + 1];

		// Decrement size
		listSize--;
		return true;
	}
	virtual void print() const
	{
		Elem a;
		if (getValue(a)) a.print();
	}
};

class Major
{
private:
	string code;
	string description;
public:
	AList<Student> ListA;
	Major(string a = " ", string b = " ")
	{
		code = a;
		description = b;
	}
	string GetCode()
	{
		return code;
	}
	string GetDescription()
	{
		return description;
	}
	void SetMajor()
	{
		string a;
		string b;
		cout << "\nPlease enter the code of the new major:\n";
		cin >> a;
		cout << "\nPlease enter the description of the new major:\n";
		cin.ignore();
		getline(cin, b);
		code = a;
		description = b;
	}
	void SetMajor(string a)
	{
		string b;
		cout << "\nPlease enter the description of the new major:\n";
		cin.ignore();
		getline(cin, b);
		code = a;
		description = b;
	}
	void SetMajor(string a, string b)
	{
		code = a;
		description = b;
	}
	void print()
	{
		cout << "\nThis major has the following code: " << code << " and the following description: " << description << ".\n";
	}
};

int SearchMajor(AList<Major> &A, string b)
{
	int i = 0;
	for (A.setStart(); i != A.leftLength() + A.rightLength(); A.next(), i++)
	{
		Major c;
		if (A.getValue(c)) if (c.GetCode() == b) return i;
	}
	return -1;
}

int SearchStudent(AList<Student> &A, int b)
{
	int i = 0;
	for (A.setStart(); i != A.leftLength() + A.rightLength(); A.next(), i++)
	{
		Student c;
		if (A.getValue(c)) if (c.GetId() == b) return i;
	}
	return -1;
}

void SortStudent(AList<Student> &A)
{
	int i = 0;
	Student a, c;
	A.remove(a);
	for (A.setStart(); i != A.leftLength() + A.rightLength(); A.next(), i++)
	{
		if (A.getValue(c)) if (c.GetId() > a.GetId()) break;
	}
	A.insert(a);
}


this is the 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
int main()
{
	AList<Major> ListM;

	cout << "Hello dear user,\nDuring this program you will be able to do the following at any time:\n";
	cout << "1- Add a new student\n2- Print students in any given major\n3- Print students in all majors\n4- Remove any student from any major\n";

	cout << "\nFirst how about adding your first student?\n";

	Student a;
	Major b;
	a.SetStudent();
	b.SetMajor(a.GetMajor());
	b.ListA.insert(a);
	if (!ListM.insert(b)) cout << "Impossible to add major.\n";

	int j = 0;
	string s;

	while (j != -1)
	{
		int x = 0, y = 0, count = 0;
		cout << "\nWhenever you want to exit please enter - 1.\nWhich operation do you wish to use?\nPlease input the number of the chosen operation:\n";
		cout << "1- Add a new student\n2- Print students in any given major\n3- Print students in all majors\n4- Remove any student from any major\n";

		cin >> j;

		switch (j)
		{
		case 1:
			a.SetStudent();
			x = SearchMajor(ListM, a.GetMajor());
			if (x == -1)
			{
				b.SetMajor(a.GetMajor());
				x = ListM.leftLength() + ListM.rightLength();
				ListM.setPos(x);
				if (b.ListA.insert(a)) SortStudent(b.ListA);
				else
				{
					if (!ListM.insert(b)) cout << "Impossible to add major.\n";
				}
			}
			else
			{
				ListM.remove(b);
				b.ListA.setEnd();
				if (b.ListA.insert(a)) SortStudent(b.ListA);
				ListM.insert(b);
			}
			break;
		case 2:
			cout << "\nEnter the major of the students you want to print:\n";
			cin >> s;
			x = SearchMajor(ListM, s);
			if (x == -1) cout << "Major does not exist.\n";
			else
			{
				if (ListM.getValue(b))
				{
					cout << "\nThe people in " << b.GetCode() << " are:\n";
					for (b.ListA.setStart(); count != b.ListA.leftLength() + b.ListA.rightLength(); b.ListA.next(), count++)
						b.ListA.print();
				}
			}
			break;
		case 3:
			for (ListM.setStart(); count != ListM.leftLength() + ListM.rightLength(); ListM.next(), count++)
			{
				if (ListM.getValue(b))
				{
					x = 0;
					cout << "\nThe people in " << b.GetCode() << " are:\n";
					for (b.ListA.setStart(); x != b.ListA.leftLength() + b.ListA.rightLength(); b.ListA.next(), x++)
						b.ListA.print();
				}
			}
			break;
		case 4:
			cout << "\nEnter the id of the student you want to remove:\n";
			cin >> x;
			cout << "Enter the major of the student you want to remove:\n";
			cin >> s;
			count = SearchMajor(ListM, s);
			if (count == -1) cout << "Major does not exist.\n";
			else
			{
				if (ListM.getValue(b))
				{
					x = SearchStudent(b.ListA, x);
					if (x == -1) cout << "Student does not exist.\n";
					else
					{
						b.ListA.setPos(x);
						if (b.ListA.remove(a)) cout << "Removal of student " << a.GetId() << " majoring in " << a.GetMajor() << " successful.\n";
					}
				}
			}
			break;
		case -1:
			break;
		default: cout << "\nWrong input.\n";
		}
	}

	system("pause");
	return 0;
}
Last edited on
anyone?
The error i am getting is when b.ListA enters the function insert in the AList class.


What error are you having exactly?
When i try for example the print function, i get this weird error:
r6010 abort() has been called
I kept debugging with no lead :/ any help?
Unhandled exception at 0x75FDC42D in EECE 330 Assignments.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x002FE608
is the error i get when debugging
BUMP
bump
Are you sure about this liine ? for (int i = listSize + 1; i>fence; i--) kinda buggin me uh.. What does fence use for ?
all my functions (getvalue, insert...) work on the right of the fence.
fence is like a position i set and the for loop that you are mentioning is to shift all the elements to the right to make room for the extra elemennt
the AList class worked fine for ListM (the list of majors) and i did a previous version of this where i used a list of students (AList<Student>) and it worked too.
It stopped working when i introduced this object : AList<Student> ListA in the class Major.
I tried debugging and following the program but it seems so weird! i mean the values just disappear or something or for some reason i am writing on unreserved space

But the thing is i didn't touch any of the functions and listsize and fence seem to be just about right when i get this error so i have no idea where it came from
Last edited on
Topic archived. No new replies allowed.