-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestHQ.cpp
44 lines (41 loc) · 1.35 KB
/
testHQ.cpp
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
//----------------------------------------------------------------------
//
// Test Program for Lab_DerivedClass.
//
//----------------------------------------------------------------------
#include <iostream>
#include <cstdlib>
using namespace std;
#include "heteroQueue.h"
/* Specify 5 types: Base, Hqueue, INT, CHAR and PhoneNumber in heteroQueue.h
Implement these types in heteroQueue.cpp
*/
int main(int argc,char** argv)
{ char c{0}; Hqueue hq;
while (c!='Q'&&c!='q'&&cin)
{ cout <<"INT, CHAR, PhoneNumber or Quit (I/C/P | Q): ";
cin >> c;
if (c=='I'||c=='i')
{ int i; cout << "Enter an integer: "; cin >> i;
hq.enqueue(new INT(i));
}
else if (c=='C'||c=='c')
{ char c; cout << "Enter a character: "; cin >> c;
hq.enqueue(new CHAR(c));
}
else if (c=='P'||c=='p')
{ PhoneNumber* ii{new PhoneNumber};
cout << "Enter a PhoneNumber(Format: a string and a number): "; cin >> *ii;
hq.enqueue(ii);
}
else if (c!='Q'&&c!='q') cout << "Wrong Selection, Retry. ";
}
if (cin)
try
{ cout << endl << "Dequeue:" << endl;
while (!hq.isEmpty()) hq.dequeue(); cout << endl;
}
catch(Hqueue::bad_op bi)
{ cerr << bi.type <<", exit " << endl; }
return 0;
}