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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
#include "Contact_list.h"
#include <string.h>
#include <iostream>
#include <list>
#include <vector>
#include <stdio.h>
using std::cin;
using std::cout;
using std::endl;
// constructors and destructors for contact
// constructors and destructors for contact_list
contact_list::~contact_list()
{
delete[] contacts_;
contacts_ = nullptr;
}
contact* contact_list::allocateContactList(const size_t& size)
{
contact* contacts_ = nullptr;
length_ = size;
contacts_ = new contact[size]{};
return contacts_;
}
contact_list::contact_list(const size_t& size)
{
length_ = size;
contacts_ = allocateContactList(size);
}
//standard functions for contact and contact_list classes
//copy (contact_list)
void contact_list::CopyList(contact* contacts,size_t size)
{
length_ = size;
//contacts_ = allocateContactList(size);
contact* newContacts = new contact[size];
for (auto i = 0u; i < size; ++i)
{
newContacts[i] = contacts_[i];
}
cout << "Class copied!" << endl;
cout << "printing!" << endl;
for (auto i = 0u; i < size; i++)
{
cout << "Contact number: " << i << endl;
newContacts[i].print();
}
}
//copy operator (contact)
contact& contact::operator=(contact& rhs)
{
if (this != &rhs)
{
_firstName = rhs._firstName;
_lastName = rhs._lastName;
_streetAddress = rhs._streetAddress;
_city = rhs._city;
_state = rhs._state;
_zip = rhs._zip;
_email = rhs._email;
}
return *this;
}
//move (contact)
contact::contact(contact&& move) noexcept
{
*this = move;
//also *this = std::move(move);
}
contact& contact::operator=(contact&& rhs) noexcept
{
if (this != &rhs)
{
_firstName = rhs._firstName;
_lastName = rhs._lastName;
_streetAddress = rhs._streetAddress;
_city = rhs._city;
_state = rhs._state;
_zip = rhs._zip;
_email = rhs._email;
}
return *this;
}
//getters n setters
void contact::Set_firstName(string firstName)
{
_firstName = firstName;
}
string contact::Get_firstName()
{
return _firstName;
}
void contact::Set_lastName(string lastName)
{
_lastName = lastName;
}
string contact::Get_lastName()
{
return _lastName;
}
void contact::Set_streetAddress(string streetAddress)
{
_streetAddress = streetAddress;
}
string contact::Get_streetAddress()
{
return _streetAddress;
}
void contact::Set_city(string city)
{
_city = city;
}
string contact::Get_city()
{
return _city;
}
void contact::Set_state(string state)
{
_state = state;
}
string contact::Get_state()
{
return _state;
}
void contact::Set_zip(int zip)
{
_zip = zip;
}
int contact::Get_zip()
{
return _zip;
}
void contact::Set_email(string email)
{
_email = email;
}
string contact::Get_email()
{
return _email;
}
void contact_list::set_length(size_t MAX)
{
length_ = MAX;
}
size_t contact_list::get_length()
{
return length_;
}
void contact_list::set_size(size_t size)
{
size_ = size;
}
size_t contact_list::get_size()
{
return size_;
}
void contact::Set_a(size_t a)
{
_a = a;
}
size_t contact::Get_a()
{
return _a;
}
void contact::Set_id(size_t id)
{
_id = id;
}
size_t contact::Get_id()
{
return _id;
}
void contact::print()
{
//cout << "Contact number: " << _id << endl;
cout << "Full name: " << _firstName << " " << _lastName << endl;
cout << "Street Address: " << _streetAddress << endl;
cout << "City: " << _city << endl;
cout << "State: " << _state << endl;
cout << "Zip code: " << _zip << endl;
cout << "Email: " << _email << endl;
}
//functions
//void addContact(contact newContact, size_t MAX, contact_list contacts[])
//{
//for(auto i = 0u; i < MAX; ++i)
//{
// char firstName[30];
// char lastName[30];
// char Email[105];
// char StreetAddress[45];
// char City[35];
// char State[4];
// int Zip = 0;
// newContact.Set_a(0);
// newContact.Set_id(i + 1);
// //newContact[i].count = t;
// cin.ignore(1000, '\n');
// cout << "Please enter each piece of information when you are prompted to" << endl;
// cout << "enter first name: " << endl;
// cin >> firstName;
// newContact.Set_firstName(firstName);
// cout << "enter last name: " << endl;
// cin >> lastName;
// newContact.Set_lastName(lastName);
// cout << "enter Email: " << endl;
// cin >> Email;
// newContact.Set_email(Email);
// cout << "enter Street Address: " << endl;
// cin >> StreetAddress;
// newContact.Set_streetAddress(StreetAddress);
// cout << "enter city: " << endl;
// cin >> City;
// newContact.Set_city(City);
// cout << "enter State as two letter abbreviation: " << endl;
// cin >> State;
// newContact.Set_state(State);
// cout << "Please enter the next value as a series of numbers" << endl;
// cout << "enter Zip: " << endl;
// cin >> Zip;
// newContact.Set_zip(Zip);
// size_t id = i + 1;
// newContact.Set_id(id);
// break;
//}
//}
void contact_list::AddContact(contact contact[], size_t& t, contact_struct save)
{
//CURRENTLY TESTING
contact_struct _save;
for (size_t i = 0; i < size_, i++;)
{
size_t a = contacts_[i].Get_a();
for (a = 1; ++i;)
{
contacts_[i].Set_a(0);
size_t temp = contacts_[i].Get_id();
for (auto j = temp; j < size_; j++)
{
if (contacts_[i].Get_id() != 0)
{
i = i + 1;
}
contacts_[i].Set_a(0);
contacts_[i].Set_id(i);
//newContact[i].count = t;
cin.ignore(1000, '\n');
cout << "Please enter each piece of information when you are prompted to" << endl;
cout << "enter first name: " << endl;
cin >> save.firstName;
contacts_[i].Set_firstName(save.firstName);
cout << "enter last name: " << endl;
cin >> save.lastName;
contacts_[i].Set_lastName(save.lastName);
cout << "enter Email: " << endl;
cin >> save.Email;
contacts_[i].Set_email(save.Email);
cout << "enter Street Address: " << endl;
cin >> save.StreetAddress;
contacts_[i].Set_streetAddress(save.StreetAddress);
cout << "enter city: " << endl;
cin >> save.City;
contacts_[i].Set_city(save.City);
cout << "enter State as two letter abbreviation: " << endl;
cin >> save.State;
contacts_[i].Set_state(save.State);
cout << "Please enter the next value as a series of numbers" << endl;
cout << "enter Zip: " << endl;
cin >> save.Zip;
contacts_[i].Set_zip(save.Zip);
}
break;
}
}
for (size_t i = t; i < size_;)
{
contacts_[i].Set_a(0);
contacts_[i].Set_id(i + 1);
//newContact[i].count = t;
cin.ignore(1000, '\n');
cout << "Please enter each piece of information when you are prompted to" << endl;
cout << "enter first name: " << endl;
cin >> save.firstName;
contacts_[i].Set_firstName(save.firstName);
cout << "enter last name: " << endl;
cin >> save.lastName;
contacts_[i].Set_lastName(save.lastName);
cout << "enter Email: " << endl;
cin >> save.Email;
contacts_[i].Set_email(save.Email);
cout << "enter Street Address: " << endl;
cin >> save.StreetAddress;
contacts_[i].Set_streetAddress(save.StreetAddress);
cout << "enter city: " << endl;
cin >> save.City;
contacts_[i].Set_city(save.City);
cout << "enter State as two letter abbreviation: " << endl;
cin >> save.State;
contacts_[i].Set_state(save.State);
cout << "Please enter the next value as a series of numbers" << endl;
cout << "enter Zip: " << endl;
cin >> save.Zip;
contacts_[i].Set_zip(save.Zip);
break;
}
//cout << newContact[i]->Name << "\n" << newContact[i]->Email << "\n" << newContact[i]->StreetAddress << "\n" << newContact[i]->City << "\n" << newContact[i]->State << "\n" << newContact[i]->Zip << endl;
}
// not required update function below.
//void contact_list::Update(const contact& contact)
//{
// //uses input based on list number from print (though when delete is made will be using that id/name print) to update the values of.
// //CURRENTLY TESTING
// char firstName[30];
// char lastName[30];
// char Email[105];
// char StreetAddress[45];
// char City[35];
// char State[4];
// int Zip = 0;
// cout << "select a contact to update based on their position in the list (check print all contacts for list position)" << endl;
// int c = 0;
// cin >> c;
// int t = c - 1;
// for (size_t i = t; i < size_;)
// {
// cin.ignore(1000, '\n');
// cout << "Please enter each piece of information when you are prompted to" << endl;
// newContact[i].Set_id(c);
// cout << "enter first name: " << endl;
// cin >> firstName;
// newContact[i].Set_firstName(firstName);
// cout << "enter last name: " << endl;
// cin >> lastName;
// newContact[i].Set_lastName(lastName);
// cout << "enter Email: " << endl;
// cin >> Email;
// newContact[i].Set_email(Email);
// cout << "enter Street Address: " << endl;
// cin >> StreetAddress;
// newContact[i].Set_streetAddress(StreetAddress);
// cout << "enter city: " << endl;
// cin >> City;
// newContact[i].Set_city(City);
// cout << "enter State as two letter abbreviation: " << endl;
// cin >> State;
// newContact[i].Set_state(State);
// cout << "Please enter the next value as a series of numbers" << endl;
// cout << "enter Zip: " << endl;
// cin >> Zip;
// newContact[i].Set_zip(Zip);
// break;
// }
//}
void contact_list::Print() const
{
//prints all info but count and bool for every existing (non trash value filled) contact struct
//CURRENTLY not working
for (auto i = 0u; i < size_; ++i)
{
size_t check = contacts_[i].Get_a();
if (check == 1)
{
i = i + 1;
}
if (contacts_[i].Get_id() == 0) {
break;
}
if (contacts_[i].Get_id() < 0) {
break;
}
if (contacts_[i].Get_id() > size_) {
break;
}
cout << "Contact number: " << contacts_[i].Get_id() << endl;
cout << "Full name: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << endl;
cout << "Email: " << contacts_[i].Get_email() << endl;
cout << "Street Address: " << contacts_[i].Get_streetAddress() << endl;
cout << "City: " << contacts_[i].Get_city() << endl;
cout << "State: " << contacts_[i].Get_state() << endl;
cout << "Zip code: " << contacts_[i].Get_zip() << endl;
//contacts_[i].print;
//if (contacts_[i].Get_id() == 0) {
// break;
//}
}
}
// depreciated contact double function below.
//contact contact_double(contact*& newContact, size_t& MAX, size_t t)
//{
// /*hell on earth is in this condenced comment*/
// //supposedly doubles length. doesn't work.
// //current ideas: add if loop to whole main with the id counter t and if length of newContact = max double the length.
// //current problems: using const size_t max prevents editing size for the whole function, and it resets as soon as the while loop loops or leaves the scope of the if statement.
// //contact* doubleContact = new contact[MAX * 2];
// //for (auto a = 0u; a < MAX; ++a)
// //{
// // doubleContact[a].a = newContact[a].a;
// // doubleContact[a].id = newContact[a].id;
// // doubleContact[a].count = newContact[a].count;
// // doubleContact[a].Name[25] = newContact[a].Name[25];
// // doubleContact[a].Email[100] = newContact[a].Email[100];
// // doubleContact[a].StreetAddress[35] = newContact[a].StreetAddress[35];
// // doubleContact[a].City[30] = newContact[a].City[30];
// // doubleContact[a].State[3] = newContact[a].State[3];
// // doubleContact[a].Zip = newContact[a].Zip;
// // cout << "List number: " << doubleContact[a].id << endl;
// // cout << "name: " << doubleContact[a].Name << endl;
// // cout << "Email: " << doubleContact[a].Email << endl;
// // cout << "Address: " << doubleContact[a].StreetAddress << endl;
// // cout << "city: " << doubleContact[a].City << endl;
// // cout << "state: " << doubleContact[a].State << endl;
// // cout << "Zip: " << doubleContact[a].Zip << endl;
// //}
// //newContact = doubleContact;
// //delete[] doubleContact;
// ////delete[] newContact;
// //MAX = MAX * 2;
// ////printAll(&doubleContact[MAX], MAX);
// ////printAll(&newContact[MAX], MAX);
// //return newContact[MAX];
//
// //contact* doubleContact = new contact[MAX * 2];
// //for (auto a = 0u; a < MAX; ++a)
// //{
// // doubleContact[a] = newContact[a];
// //}
// //delete[] newContact;
// //newContact = doubleContact;
// //MAX = MAX * 2;
// //return newContact[MAX - 1];
// return;
//}
void contact_list::DeleteContact(contact* contact[])
{
//Work in progress, add BOOL (true) to struct, when this is selected print id list with respective names
//then take input of id list number and set bool to false
//add to new part to addNew: if bool != 0 then copy and paste update code w/addNew couts
cout << "The list of contacts and their names will now print" << endl;
for (auto i = 0u; i < size_; i++)
{
/* if (contacts_[i].Get_id() == 0) {
break;
}*/
if (contacts_[i].Get_id() < 0) {
break;
}
if (contacts_[i].Get_id() > size_) {
break;
}
if (contacts_[i].Get_a() == 1)
{
break;
}
cout << "Id number: " << contacts_[i].Get_id() << " is under the name: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << endl;
}
for (auto i = 0u; i < size_; i++)
{
size_t delete_choice = 0;
cout << "\n";
cin.ignore(1000, '\n');
cout << "Enter the id number of the contact you'd like to delete" << endl;
cin >> delete_choice;
if (delete_choice != contacts_[i].Get_id())
{
i = i + 1;
}
if (delete_choice == contacts_[i].Get_id())
{
contacts_[i].Set_a(1);
contacts_[i + 1].Set_id(i);
cout << "the contact for: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << " (id number: " << contacts_[i].Get_id() << "Has been deleted. (bool check = " << contacts_[i].Get_a() << endl;
break;
}
}
}
|