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
|
#ifndef MENU_HELPER_HPP
#define MENU_HELPER_HPP
#define _CRT_SECURE_NO_WARNINGS
#include "ContactList.hpp"
namespace MyStructures
{
void MainMenu();
Contact InputContact();
char* PromptCharInput(const char* prompt, long long maxlen);
int InputInt(const char* prompt);
void MainMenu()
{
char Options = '\0';
size_t i = 0;
ContactList<Contact> AddressBook(3);
do
{
std::cout << "Welcome to the contacts menu\n"
<< "1)Add New Contact\n"
<< "2)Print All Contacts\n"
<< "3)Delete Contact\n"
<< "4)Exit\n";
std::cin >> Options;
switch (Options)
{
case('1'):
AddressBook.Append(InputContact());
break;
case('2'):
AddressBook.PrintList();
break;
case('3'):
AddressBook.DeleteContact(InputInt("Which Contact Would you like to delete?")-1);
break;
case('4'):
std::cout << "Thank you, have a great day!" << std::endl;
break;
default:
std::cout << "Invalid Input, Try Again!" << std::endl;
}
} while (Options != '4');
}
Contact InputContact()
{
Contact newContact;
newContact.SetFirstName(PromptCharInput("What is your first name?", 101));
newContact.SetLastName(PromptCharInput("What is your last name?: ", 101));
newContact.SetStreet(PromptCharInput("What is your street address?: ", 101));
newContact.SetEmail(PromptCharInput("What is your email?: ", 101));
newContact.SetState(PromptCharInput("What is your state?: ", 101));
newContact.SetCity(PromptCharInput("What is your city?: ", 101));
newContact.SetZip(InputInt("What is your zip?"));
return newContact;
}
char* PromptCharInput(const char* prompt, long long maxlen)
{
std::cout.flush();
std::cout << prompt << std::endl;
char* input = new char[maxlen];
cin >> input;
while (!std::cin)
{
cout << prompt << std::endl;
cin.clear();
cin.ignore(MAX_STREAM_SIZE, '\n');
cin.get(input, MAX_STREAM_SIZE, '\n');
}
return input;
}
int InputInt(const char* prompt)
{
std::cout << prompt << std::endl;
std::cout.flush();
int data = 0;
std::cin >> data;
while (!std::cin)
{
std::cout << prompt << std::endl;
std::cin.clear();
cin.ignore(MAX_STREAM_SIZE, '\n');
std::cin >> data;
}
return data;
}
};
#endif
|