-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
175 lines (165 loc) · 6.39 KB
/
main.cpp
File metadata and controls
175 lines (165 loc) · 6.39 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <iostream>
#include <string>
#include "p3.h"
using namespace std;
int main(int argc, char *argv[]) {
bool printPrompts = true;
if (argc == 2 && string(argv[1]) == "no") {
printPrompts = false;
}
ContactList *list = new ContactList();
string cmd, first, last, infoName, infoVal;
while (1) {
if (printPrompts) cout << "Enter a command or \"help\" to get a command list: ";
cin >> cmd;
if (cmd == "quit") {
break;
}
else if (cmd == "addContact") {
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (!list->addContact(first, last)) {
cout << "Error: " << first << " " << last << " already exists" << endl;
}
}
else if (cmd == "addInfo") {
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (printPrompts) cout << "\tEnter info name: ";
cin >> infoName;
if (printPrompts) cout << "\tEnter info value: ";
cin >> infoVal;
if (!list->addInfo(first, last, infoName, infoVal)) {
cout << "Error: " << first << " " << last << " does not exist" << endl;
}
}
else if (cmd == "printContact") {
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (!list->printContact(cout, first, last)) {
cout << "Error: " << first << " " << last << " does not exist" << endl;
}
cout << endl;
}
else if (cmd == "count") {
cout << "\nThere are " << list->getCount() << " contacts" << endl;
}
else if (cmd == "print") {
list->print(cout);
cout << endl;
}
else if (cmd == "addContactOrdered") {
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (!list->addContactOrdered(first, last)) {
cout << "Error: " << first << " " << last << " already exists" << endl;
}
}
else if (cmd == "addInfoOrdered") {
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (printPrompts) cout << "\tEnter info name: ";
cin >> infoName;
if (printPrompts) cout << "\tEnter info value: ";
cin >> infoVal;
if (!list->addInfoOrdered(first, last, infoName, infoVal)) {
cout << "Error: " << first << " " << last << " does not exist" << endl;
}
}
else if (cmd == "removeInfo") {
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (printPrompts) cout << "\tEnter info name: ";
cin >> infoName;
if (!list->removeInfo(first, last, infoName)) {
cout << "Error: " << first << " " << last << " or " << infoName << " does not exist" << endl;
}
}
else if (cmd == "removeContact") {
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (!list->removeContact(first, last)) {
cout << "Error: " << first << " " << last << " does not exist" << endl;
}
}
else if (cmd == "destroy") {
delete list;
list = new ContactList();
}
else if (cmd == "copycon" || cmd == "copy=") {
ContactList *list2;
if (cmd == "copycon") {
list2 = new ContactList(*list);
}
else {
list2 = new ContactList();
*list2 = *list;
}
if (printPrompts) cout << "\tAdd contact to copied list:" << endl;
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (!list2->addContact(first, last))
{
cout << "Error: " << first << " " << last << " already exists" << endl;
}
if (printPrompts) cout << "\tAdd info to copied list:" << endl;
if (printPrompts) cout << "\tEnter first name: ";
cin >> first;
if (printPrompts) cout << "\tEnter last name: ";
cin >> last;
if (printPrompts) cout << "\tEnter info name: ";
cin >> infoName;
if (printPrompts) cout << "\tEnter info value: ";
cin >> infoVal;
if (!list2->addInfo(first, last, infoName, infoVal))
{
cout << "Error: " << first << " " << last << " or " << infoName << "does not exist" << endl;
}
cout << "Original list:" << endl;
list->print(cout);
cout << endl;
cout << "Copied list:" << endl;
list2->print(cout);
cout << endl;
delete list2;
}
else if (cmd == "help") {
cout << "Valid commands:" << endl;
cout << "***** addContact" << endl;
cout << "***** addInfo" << endl;
cout << "***** printContact" << endl;
cout << "***** count" << endl;
cout << "***** print" << endl;
cout << "***** addContactOrdered" << endl;
cout << "***** addInfoOrdered" << endl;
cout << "***** removeContact" << endl;
cout << "***** removeInfo" << endl;
cout << "***** destroy" << endl;
cout << "***** copycon" << endl;
cout << "***** copy=" << endl;
cout << "***** help" << endl;
cout << "***** quit" << endl;
}
else {
cout << "Invalid command specified - " << cmd << endl;
}
if (printPrompts) cout << endl;
}
return 0;
}