May 31, 2014 at 11:23pm UTC
Hello, I need to create a dynamically allocated, growable, queue of structs. I just need a little help getting started. From there, I know I can finish it on my own.
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
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
struct ABC{
string name;
unsigned empNo;
double salary;
};
class Queue{
public :
static const unsigned initSize = 4;
Queue();
Queue( const Queue & other );
~Queue();
Queue & add( const ABC & abc );
ABC remove();
unsigned getSize() const ;
Queue & operator =( const Queue & rhs );
private :
unsigned size;
unsigned totalSize;
unsigned front;
unsigned back;
ABC * ptr;
};
void die(const string & msg);
int main(){
Queue q;
}
void die(const string & msg){
cerr << "Fatal error: " << msg << endl;
exit(EXIT_FAILURE);
}
Queue::Queue(){
size = 0;
back = 0;
front = 0;
totalSize = initSize;
try {
ptr = new ABC[totalSize];
}
catch (const bad_alloc){
die("Alloc. failure" );
}
}
Queue::Queue(const Queue & other){}
Queue::~Queue(){}
Queue & Queue::add(const ABC & abc){}
ABC Queue::remove(){}
Queue & Queue::operator =( const Queue & rhs ){}
unsigned Queue::getSize() const {return size;}
Last edited on May 31, 2014 at 11:33pm UTC
May 31, 2014 at 11:35pm UTC
Last edited on May 31, 2014 at 11:35pm UTC