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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
const string null = "";
class shortName {
string firstName;
string lastName;
public:
shortName();
shortName(string, string);
void setFirst(string First) { firstName = First;}
void setLast(string Last) { lastName = Last;}
string getFirst() { return firstName;}
string getLast() { return lastName;}
string toString();
};
shortName::shortName()
{
firstName = null;
lastName = null;
}
shortName::shortName(string First, string Last)
{
firstName = First;
lastName = Last;
}
string shortName::toString()
{
string Form;
Form = firstName + " " + lastName;
return Form;
}
class shortPhone {
string AreaCode;
string Prefix;
string Number;
public:
shortPhone();
shortPhone(string, string, string);
void setArea(string Area) { AreaCode = Area; }
void setPrefix(string Pref) { Prefix = Pref; }
void setNumber(string Num) { Number = Num; }
string getArea() { return AreaCode; }
string getPrefix() { return Prefix; }
string getNumber() { return Number; }
string toString();
};
shortPhone::shortPhone()
{
AreaCode = null;
Prefix = null;
Number = null;
}
shortPhone::shortPhone(string Area, string Pre, string Num)
{
AreaCode = Area;
Prefix = Pre;
Number = Num;
}
string shortPhone::toString()
{
string Form;
Form = "(" + AreaCode +") " + Prefix + "-" + Number;
return Form;
}
class Record {
shortName Name;
shortPhone Phone;
public:
Record();
void Menu();
int addRecord(Record*, int);
void showRecords(Record*, int);
void Delete(Record*, int, string);
void Find(Record*, int, string);
Record(shortName, shortPhone);
Record(string, string, string, string, string);
void setFirst(string First) { Name.setFirst(First); }
void setLast(string Last) { Name.setLast(Last); }
void setArea(string Area) { Phone.setArea(Area); }
void setPrefix(string Prefix) { Phone.setPrefix(Prefix); }
void setNumber(string Number) { Phone.setNumber(Number); }
string getFirst() { return Name.getFirst(); }
string getLast() { return Name.getLast(); }
string getArea() { return Phone.getArea(); }
string getPrefix() { return Phone.getPrefix(); }
string getNumber() { return Phone.getNumber(); }
string toString();
};
Record::Record()
{
;
}
Record::Record(shortName N, shortPhone P)
{
Name = N;
Phone = P;
}
string Record::toString()
{
string Form;
Form = "Name: \n" + Name.toString() + "\n" +
"Phone: \n" + Phone.toString() + "\n";
return Form;
}
int main()
{
Record List[25];
int Size, maxSize = 25;
string Command;
Record obj;
obj.Menu();
while(true) {
cout << "Enter Command: ";
cin >> Command;
if(Command == "Quit")
break;
else if(Command == "Help")
obj.Menu();
else if(Command == "Add")
Size = obj.addRecord(List, maxSize);
else if(Command == "Show")
obj.showRecords(List, Size);
else if(Command == "Find") {
string FindValue;
cout << "Enter Last Name: ";
cin >> FindValue;
obj.Find(List, Size, FindValue);
}
else if(Command == "Delete") {
string DeleteValue;
cout << "Enter Last Name: ";
cin >> DeleteValue;
obj.Delete(List, Size, DeleteValue);
}
else
cout << "Command not found. Enter Help to display Command List." <<endl;
cin.ignore(200, '\n');
}
}
void Record::Menu()
{
cout << endl;
cout << "Command List:" << endl;
cout << "============================================" << endl;
cout << "Add :Adds Records" << endl;
cout << "tDelete :Deletes Records" << endl;
cout << "tFind :Finds Records by Last Name" << endl;
cout << "Show :Shows Records" << endl;
cout << "Help :Displays Command List" << endl;
cout << "Quit :Ends Program" << endl;
cout << "============================================" << endl;
cout << endl;
}
int Record::addRecord(Record* List, int maxSize)
{
int K;
string First, Last, Area, Prefix, Number;
cout << "Enter Values Below, Stop To Quit" << endl;
for(K = 0 ; K < maxSize ; K++) {
cout << "First Name: ";
cin >> First;
if(First == "Stop")
break;
cout << "Last Name: ";
cin >> Last;
cout << "Area Code: ";
cin >> Area;
cout << "Prefix: ";
cin >> Prefix;
cout << "Number: ";
cin >> Number;
List[K].setFirst(First);
List[K].setLast(Last);
List[K].setArea(Area);
List[K].setPrefix(Prefix);
List[K].setNumber(Number);
cin.ignore(200, '\n');
}
return K;
}
void Record::Delete(Record* List, int Size, string DeleteValue)
{
int K;
for(K = 0 ; K < Size ; K++)
if(List[K].getLast() == DeleteValue) {
cout << endl;
cout << "==============================================" << endl;
cout << "\tTHIS RECORD HAS BEEN DELETED" << endl;
cout << endl;
cout << List[K].toString() << endl;
List[K].toString() = "DELETED";
cout << "==============================================" << endl;
cout << endl;
return;
}
else;
cout << "Record with Last Name: " <<DeleteValue << " was Not Found!" << endl;
}
void Record::Find(Record* List, int Size, string FindValue)
{
int K;
int NotFoundFlag = 0;
for(K = 0 ; K < Size ; K++)
if(List[K].getLast() == FindValue) {
cout << endl;
cout << "==============================================" << endl;
cout << "\tRecord with Last Name: "<< List[K].getLast() << endl;
cout << endl;
cout << List[K].toString() << endl;
cout << "==============================================" << endl;
cout << endl;
NotFoundFlag = 1;
}
if(NotFoundFlag == 0)
cout << "Record with Last Name: " << FindValue << " was Not Found!" << endl;
}
void Record::showRecords(Record* List, int Size)
{
for(int K = 0 ; K < Size ; K++)
{
cout << "======================" << endl;
cout << List[K].toString() << endl;
cout << "======================" << endl;
}
}
|