Ai ya, is there any new ways to solve the function problem to store the name and ID for the class function without using composition.
Ai ya, is there any new ways to solve the function problem to store the name and ID for the class function without using composition.
I am asking user to input the size of the queue(eg. 20, 30, 40) and the program would used the size from the user. Of course i need the "new" pointer. As for, int part, iI already change but I received all these cant fixed error
No, you don't.
Fix the abovementioned problems and then repost your code....As for, int part, iI already change but I received all these cant fixed error
This is less about composition and more about simply using data types. It isn't difficult!
The first problem i encounter, if I change it to mydata instead of int in the queue.h to declare the list, all my "list" in main.cpp would be called as undeclared. So if it is right to change it. Give me some hints.
received more error if i declared a list[array] in main.cpp. Which problem must I fixed first?
Look back at my post #2, and work out how to make your code have the same visibility of the myData declaration.
It's a really simple one-line change that ought to really cut down on the amount of errors.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Because since some of the class function variables/func has been changed to myData, so I change it together with the queue.cpp, i think it is the queue.cpp above where i had write wrong code but not sure how to correct it.Code:#include "Queue.h" #include <cstdlib> #include <iostream> #include <string> using namespace std; bool Queue::IsEmptyQueue(void) const { return (count == 0); } bool Queue::IsFullQueue(void) const { return (count == maxQueuesize); } void Queue::initializeQueue(void) { front = 0; back = maxQueuesize - 1; count = 0; } int Queue::Myfront(void) const { if (!IsEmptyQueue()) { return list[front]; } /* else { return 0; } */ } int Queue::Myback(void) const { if (!IsFullQueue()) { return list[back]; } /* else { return 0; } */ } void Queue::addQueue(myData ) { if (!IsFullQueue()) { back = (back + 1) % maxQueuesize; count++; list[back] = element; } else { cout << "Unable to add a full queue: " << endl; } } myData Queue::removeQueue(void) { if (!IsEmptyQueue()) { count --; front = (front + 1) % maxQueuesize; } else { cout << "Cannot remove from an emty queue." << endl; } } Queue::Queue(int size) { if (size <= 0) { cout << "Size must be positive." << endl; //cout << "An array of size 10 is created for you." << endl; //maxQueuesize = 10; } else { maxQueuesize = size; } front = 0; back = maxQueuesize - 1; count = 0; list = new int[maxQueuesize]; } Queue::~Queue(void) { delete[] list; } void Queue::PrintNumber(void) { for (int i = 0; i < maxQueuesize; i ++) { cout << i << "\t:\t" << list[i] << endl; } } void Queue::PrintQueueNumber(void) { cout << "Your queue number is " << front << endl; cout << "Your queue number is #" << back << endl; }
I know that the class myData is to insert 2 variables string and a int value(something like a struct) so that all the other functions in queue.cpp can be used to group those 2 variables and solve my problem. But, i not sure where I had done wrong in queue.cpp here which I think I make a major mistake.