Help understanding / Implementation

I am looking for help and understanding on what I am to do on this assignment (I've posted on the class forum as well, but more knowledge shared will help me understand more). Also I am not looking for the answers, just understanding as I cannot make sense of the assignment and implementation and the end goal that I am striving for.

Thank you for any assistance in understanding.



1
2
3
4
5
6
7
8
9
10
11
  Implement two functions specified in list.h. You need to fill in the implementation in
list.cpp:
 bool insert(int val, int intList[], int& size)
the above function will insert “val” into “intList” and increment size. It returns false
if “intList” has val already and it won’t insert the duplicate.
 bool remove(int val, int intList[], int& size)
the above function will remove “val” from “intList” and decrement size. It returns
false if “intList” doesn’t have “val”
In app.cpp, the function print is used to print the integers in the list. You can use this
information to check the accuracy of your code. 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bool insert(int val, int intList[], int& size)
{
	//insert your code here and modify the following line
	return true;
}

bool remove(int val, int intList[], int& size)
{
	//insert your code here and modify the following line
	return true;
}

void print(const int intList[], int size)
{
	cout << endl << "[ ";
	for(int i=0; i<size; i++)
	{
		cout << intList[i] << " ";
	}
	cout << "]" << endl;
}
Last edited on
closed account (48T7M4Gy)
Implement two functions specified in list.h. You need to fill in the implementation in
list.cpp:

1. bool insert(int val, int intList[], int& size)
the above function will insert “val” into “intList” and increment size. It returns false
if “intList” has val already and it won’t insert the duplicate.

2. bool remove(int val, int intList[], int& size)
the above function will remove “val” from “intList” and decrement size. It returns
false if “intList” doesn’t have “val”

In app.cpp, the function print is used to print the integers in the list. You can use this
information to check the accuracy of your code.

First step is it helps if I can read it :)
closed account (48T7M4Gy)
1. You need to break the problem down and write pseudocode perhaps like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool insert(int val, int intList[], int& size)
{
      // insert your code here and modify the following line

      // if “intList” has val already and it won’t insert the duplicate. 
      //          So return false


      // insert “val” into “intList”


      // increment size.

	return true;
}


Once you've got to that you go ahead and program/test/debug each part. If a part is toio big break it down to smaller parts. :)
Last edited on
Sorry, I thought I would throw it in the code block to separate it. Made it more difficult of course. I guess my biggest problem is trying to decipher the end goal, what the program is supposed to do.

Here is the other .cpp that came with it. Am I just making something to input numbers into a list and remove them (Giving errors if in/not in list)? Or something else?

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
const int ARRAY_CAP = 100;
int main()
{
	int aList[ARRAY_CAP];
	int size = 0;

	print(aList, size);
	insert(10, aList, size);
	insert(10, aList, size);
	insert(4, aList, size);
	insert(40, aList, size);
	insert(25, aList, size);
	print(aList, size);
	if(!remove(5, aList, size))
	{
		cout << "the list doesn't have 5" << endl;
	}
	if(!remove(10, aList, size))
	{
		cout << "the list doesn't have 10" << endl;
	}
	if(!remove(40, aList, size))
	{
		cout << "the list doesn't have 40" << endl;
	}
	if(!remove(4, aList, size))
	{
		cout << "the list doesn't have 4" << endl;
	}
	print(aList, size);
	return 0;
}
Last edited on
closed account (48T7M4Gy)
You will notice that the main program has functions called print, insert, remove which are pretty much self evident in what they mean.

These functions are not off the shelf so your assignment is to program them. You use the starting lines given to you.

Once you've written them you test the program and get it working. Since you haven't started yet my advice is to take the insert function and my suggestion and program it.

The end goal is to be able to successfully run your list management program.

:)
Ok. Thank you for helping me understand this assignment. I think I understand a portion of what I am supposed to do now. I'll get working on it and perhaps it'll come into greater light. Thank you again.
closed account (48T7M4Gy)
OK Let us know if you need help later - it's great that you are prepared to try.
Topic archived. No new replies allowed.