Not sure why it will not run. First part is the .h file Second part is the main.
ID: 3755115 • Letter: N
Question
Not sure why it will not run. First part is the .h file Second part is the main.
// .h header file
#include<iostream>
using namespace std;
class arrayQueueType
{
public:
bool isEmptyQueue();
bool isFullQueue();
void initializeQueue();
void queueFront(int newItem);
void queueBack();
void addQueue(int queueElement);
void deleteQueue();
int queueSize = 100;
int count;
~arrayQueueType();
private:
int maxQueueSize;
int queueFront;
int queueBack;
queueType *list;
};
bool::isEmptyQueue()
{
return(count == 0);
}
bool::isFullQueue()
{
return (count == maxQueueSize);
}
void initializeQueue()
{
queueFront = 0;
queueBack = maxQueueSize - 1;
count = 0;
}
void::queueFront()
{
assert(!isEmptyQueue());
return list[queueFront];
}
void::queueBack()
{
assert(!isEmptyQueue());
return list[queueBack];
}
void::addQueue(int newItem)
{
if (!isFullQueue())
{
queueBack = (queueBack +1) % maxQueueSize;
count++;
list[queueBack] = newItem;
}
else
cout << "Cannot add to a full queue." << endl;
}
__________________________________________________________
//main
#include<iostream>
using namespace std;
#include "arrayHeader.h"
int main()
{
arrayQueueType queue;
int x, y;
queue.initializeQueue();
x = 20;
y = 35;
queue.addQueue(x);
queue.addQueue(y);
x = queue.front();
queue.deleteQueue();
queue.addQueue(x + 7);
queue.addQueue(78);
queue.addQueue(x);
queue.addQueue(y - 6);
cout << "Queue Elements: ";
while (!queue.isEmptyQueue())
{
cout << queue.front() << " ";
queue.deleteQueue();
}
cout << endl;
return 0;
}
Explanation / Answer
Please find my comments which will help you to resolve the errors:- (Your program has too many errors!!)
1. queueType *list:- queueType is not defined anywhere in your header file. What is the data type of queueType(i believe it is user defined, but you are nowhere declaring in code for the list type)
2. queueFront:- Both variable declaration(int queueFront;) and function prototype (void queueFront(int newItem);) has the same name. You need to change it so that variable name and function name differs
3. queueBack:- Same reason as 2
4. ~arrayQueueType():- Destructor is only declared, no where in the code you are implemnting the functionality of the Destructor. Better remove if unused.
5. Syntax Errors(lots u have):- Check this 1 example:-
bool::isEmptyQueue() - This should be bool arrayQueueType::isEmptyQueue(). Check how to write the function definition outside the class in which its declared. Similarly all your functions have wrong syntax:-
bool::isFullQueue():- should be bool arrayQueueType::isFullQueue()
Change all the functions that you have implemented in the similiar way as I have shown above.
6. void deleteQueue() - This function prototype is present in code, but where is the body of the function present when you are trying to call from main(). Implement the body of this function.
7. void queueFront(int newItem) - Function prototype mismatched when you are trying to implement the body of this function. Check this code piece:- (It has 0 params, but in prototype it has 1 param, fix it accordingly)
void::queueFront()
{
assert(!isEmptyQueue());
return list[queueFront];
}
8. In void::addQueue(int newItem):- Have u dynamically allocated memory to list before you add elements to it. Your program will terminate abruptly since in this addQueue() you are trying to insert elements into the list (list[queueBack] = newItem;) but without first allocating memory to it. Check how malloc works:-
list[queueBack] = newItem; // Then you should add the element into the list, otherwise list is always NULL.
9. Missing #include<cassert> header file:- You are using addert in code, so include this header file first, else it throws error.
Please let me know in case of any clarifications required. Thanks!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.