+ 1

Possibly misunderstanding the "Queue management system" question

This is the code project in "Classes and Objects" in the C++ course. I feel I am misunderstanding the question, because as it is laid out it doesn't quite make sense to me. The question is: You are working on a Queue management system and need to create the class to hold the queue data, which are customer IDs (integers). You make a Queue class, which has a size attribute, and an array, to hold the data of the queue. The class has a remove() method to remove the front item of the queue, a print() method to output the queue. You need to create an add() method for the Queue class, that will take an item and add it to the end of the queue. The code needs to be fully working, so that the Queue declaration and manipulation code in main() works But the queue variable supplied is an array. I feel it would make more sense if it was a vector, if you want to remove items and tack numbers onto the end? I thought arrays were immutable in C++? Which version of C++ is used in the course? I am feeling a bit confused. Am I supposed to change the array to a vector?

7th Jan 2022, 9:09 PM
Mimsy
3 Réponses
+ 1
All you need to do is write the function so it adds a value to the array. Show us the code you tried.
7th Jan 2022, 11:34 PM
Slick
Slick - avatar
+ 1
I hadn't tried any code at the point I asked this question, I was just trying to understand the question, as my understanding was that arrays were constant values. I like to understand what is expected of me before I start to figure out an answer. Doesn't matter anymore, since I wrote a function with the assumption that the array could be changed and it worked. Moving right along now.
8th Jan 2022, 12:00 AM
Mimsy
+ 1
Using a vector would be easier as it would relocate the elements when you "pop-front". If you're using an array, you'll need to shift the elements yourself. using a simple "for" loop. Use dynamic memory allocation in the class constructer and pass the size of the array you want to make in to it. If you very new to this and you haven't done so already, then implement a "stack" first using a fixed sized array.
8th Jan 2022, 1:25 AM
rodwynnejones
rodwynnejones - avatar