Need help with assignment

I need help with the functions: is_duplicate and remove_all to work for my assignemt. Here is the code, been trying to get it to work for the past two hours. Any help would be nice

<code>
#include <iostream>
using std::cout; using std::cin; using std::endl;

class MyList
{
private:
const static int INC = 10;
const static int DCAP = 20;
int *a;
int csz;
int cap;
bool move();

public:
MyList();
MyList(int);
//destructor
~MyList();
bool add(int);
// bool remove(int);
bool empty();
bool clt();
bool full();
void erase();
int is_duplicate(int v);
bool remove_all();
bool present(int);
void display();
};

MyList::~MyList()
{
cout << "I'm being destroyed!!" << endl;
delete[] a;
}

bool MyList::move()
{
// cout << "Moving to a new array..." << endl;
int *p = new int[csz + INC];
for (int i = 0; i < csz; ++i)
p[i] = a[i];
delete[] a;
a = p;
cap = csz + INC;
// cout << "Done!" << endl;
return true;
}

bool MyList::clt()
{
cout << "Please enter the size of array:";
int size;
cin >> size;
csz=size;

for (int i=0; i <csz; i++)
{
cin >> a[i];
}
}


void MyList::display()
{
cout << "Capacity: " << cap << endl;
cout << "Current size: " << csz << endl;
cout << "Contents: " << endl;
for (int i = 0; i < csz; ++i)
cout << a[i] << " ";
cout << endl;
}

MyList::MyList()
{
//cout << "Default constructor is called." << endl;
csz = 0;
a = new int[DCAP];
if (a == nullptr)
cout << "failed!!" << endl;
cap = DCAP;
}

MyList::MyList(int ucap)
{
//cout << "Parameterized constructor is called." << endl;
csz = 0;
if (ucap <= 0)
cap = DCAP;
else
cap = ucap;
a = new int[cap];
}

bool MyList::full()
{
if (csz == cap)
return true;
else
return false;
}

bool MyList::add(int v)
{
if (full())
move();
a[csz] = v;
++csz;
return true;
}

bool MyList::empty()
{
if (csz == 0)
return true;
else
return false;
}

bool MyList::present(int v)
{
for (int i = 0; i < csz; ++i)
if (a[i] == v)
return true;
return false;
}


bool MyList::remove_all()
{
int number;
cin >> number;
cout << "Please enter duplicates" << number << "that are found";
for (int i= 0; i= csz; i++)
{
if (number == a[i])
{
for (int n= i; n < csz-1; ++n)
{
a[n]=a[i+1];
}
csz= csz-1;
}
}

}


void MyList::erase()
{

cout << "Array being erased now fucker";
for (int i =0; i < csz; i++)
{
a[i]=0;
}


}
int MyList::is_duplicate(int v)
{
int count = 0;
for(int i=0; i< csz ; i++)
{
int v;
if(a[i]==v)
{
count++;
}
}
return count;
}



int main()
{
MyList l1;
l1.clt();
//memory all MyListocated dynamicall
l1.display();
cout << "lets find the duplicates:";
l1.is_duplicate(int v);
cout <<"would you like to remove duplicates? Put 1 for yes, 2 for nah:";
int input;
cin >> input;
if (input == 1)
{
l1.remove_all();
}
else if (input == 2)
{
cout << "Okay have fun!:";
l1.erase();
}

l1.display();


}

</code>
You used the wrong style of code tags.
We use [ ] here, not <>
Perhaps:

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
#include <iostream>
using std::cout; using std::cin; using std::endl;

class MyList
{
private:
	const static int INC {10};
	const static int DCAP {20};
	int csz {};
	int cap {DCAP};
	int* a {};
	bool move();

public:
	MyList();
	MyList(int);
	~MyList();

	bool add(int);
	bool empty();
	bool clt();
	bool full();
	void erase();
	int is_duplicate(int v);
	bool remove_all(int v);
	bool present(int);
	void display();
};

MyList::~MyList()
{
	cout << "I'm being destroyed!!\n";
	delete[] a;
}

bool MyList::move()
{
	// cout << "Moving to a new array..." << endl;
	int* p {new int[csz + INC]};

	for (int i = 0; i < csz; ++i)
		p[i] = a[i];

	delete[] a;
	a = p;
	cap = csz + INC;
	// cout << "Done!" << endl;
	return true;
}

bool MyList::clt()
{
	cout << "Please enter the size of array:";
	cin >> csz;

	for (int i = 0; i < csz; ++i)
		cin >> a[i];

	return true;
}

void MyList::display()
{
	cout << "\nCapacity: " << cap << '\n';
	cout << "Current size: " << csz << '\n';
	cout << "Contents: " << '\n';

	for (int i = 0; i < csz; ++i)
		cout << a[i] << " ";

	cout << '\n';
}

MyList::MyList() : a(new int[DCAP])
{
	//cout << "Default constructor is called." << endl;
}

MyList::MyList(int ucap) : cap(ucap <= 0 ? DCAP : ucap), a(new int[cap])
{
	//cout << "Parameterized constructor is called." << endl;
}

bool MyList::full()
{
	return csz == cap;
}

bool MyList::add(int v)
{
	if (full())
		move();

	a[csz++] = v;
	return true;
}

bool MyList::empty()
{
	return csz == 0;
}

bool MyList::present(int v)
{
	for (int i = 0; i < csz; ++i)
		if (a[i] == v)
			return true;

	return false;
}

bool MyList::remove_all(int v)
{
	cout << "Removing all entries equal to " << v << '\n';

	for (int i = 0; i < csz; )
		if (v == a[i]) {
			for (int n = i; n < csz - 1; ++n)
				a[n] = a[n + 1];

			--csz;;
		} else
			++i;

	return true;
}

void MyList::erase()
{
	cout << "Array being erased now\n";

	for (int i = 0; i < csz; ++i)
		a[i] = 0;
}

int MyList::is_duplicate(int v)
{
	int count {};

	for (int i = 0; i < csz; ++i)
		count += a[i] == v;

	return count;
}


int main()
{
	MyList l1;

	l1.clt();
	l1.display();

	int v {};

	cout << "Enter number to find: ";
	cin >> v;

	cout << "lets find the duplicates: ";
	cout << "There are " << l1.is_duplicate(v) << '\n';

	int input {};

	cout << "would you like to remove duplicates? Put 1 for yes, 2 for nah: ";
	cin >> input;

	if (input == 1)
		l1.remove_all(v);
	else if (input == 2) {
		cout << "Okay have fun!:";
		//l1.erase();
	}

	l1.display();
}

Thank you so much for the help!
Topic archived. No new replies allowed.