aboutsummaryrefslogtreecommitdiff
path: root/Homework8/MyStructures/MenuHelper.hpp
blob: 81d11e03a3f341f97b24265ef654d74d24badb70 (plain) (blame)
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
#ifndef MENU_HELPER_HPP
#define MENU_HELPER_HPP

#define _CRT_SECURE_NO_WARNINGS
#include "ContactList.hpp"

using namespace MyStructures;


void MainMenu();

Contact InputContact();

char* PromptCharInput(const char* prompt, long long maxlen);

int InputInt(const char* prompt);

void PrintContact(ContactList<Contact>& contacts);

Contact NewContact();

void PrintContact(ContactList<Contact>& contacts);



void MainMenu()
{
	char Options = '\0';
	

	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'):

			break;
		case('2'):
			//PrintContact(contacts);
			break;
		case('3'):
			//contacts.DeleteContact("Which contact would you like to delete?", contacts);
			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;



}

void PrintContact(ContactList<Contact>& contacts)
{
	contacts.PrintList();
}



Contact NewContact()
{
	Contact newContact;

	return newContact;
}



char* PromptCharInput(const char* prompt, long long maxlen)
{
	std::cout.flush();
	std::cout << prompt << std::endl;
	
	char* input = new char[maxlen];
	
	do
	{
		std::cin.clear();
		cin.get(input, maxlen, '\n');
		cin.ignore(MAX_STREAM_SIZE, '\n');

	} while (!std::cin);

	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