aboutsummaryrefslogtreecommitdiff
path: root/Homework6ReeceWarner/contacts.cpp
blob: 81992fe96ee7ad2acb55efe7c065c56ed136ef4a (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
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
#include "contacts.h"
#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;

contact contacts[MAX] = {};
contact emptycontact[MAX] = {}; //this is what I am comparing strings with in the print function
int numberofcontacts = 0;

contact InputNewContact()
{
	cout << "Avoid Using Spaces While Entering Your Street Name" << endl;
	contact newcontact = {};
	cout << "First Name: ";
	cin >> newcontact.FirstName;

	cout << "Last Name: ";
	cin >> newcontact.LastName;

	cout << "Email: ";
	cin >> newcontact.Email;

	cout << "Street Number: ";
	cin >> newcontact.StreetNumber;

	cout << "Street Name: ";
	cin >> newcontact.StreetName;

	cout << "City: ";
	cin >> newcontact.city;

	cout << "State: ";
	cin >> newcontact.State;

	cout << "Zip: ";
	cin >> newcontact.Zip;
	
	cout << "\n" << endl;

	return newcontact;

}


void printcontacts()
{
	for (int x = 0; x < numberofcontacts; x++)
	{
		contact empty = emptycontact[x];

		contact existingcontacts = contacts[x];
		int result;
		result = strcmp(existingcontacts.FirstName, empty.FirstName); //Compares the cString with an empty one, when it is equal, it prints nothing!!!
		if (result == 0)
		{
			cout << " ";
		}
		else
		{
			_strupr_s(existingcontacts.FirstName); //permanently changing the string to uppercase
			_strupr_s(existingcontacts.LastName);
			cout << "Name " << x << ": " << existingcontacts.FirstName << " " << existingcontacts.LastName << endl;
		}
		result = strcmp(existingcontacts.Email, empty.Email);
		if (result == 0)
		{
			cout << " ";
		}
		else
		{
			_strupr_s(existingcontacts.Email);
		
			cout << "Email " << x << ": " << existingcontacts.Email << endl;
		}
		result = strcmp(existingcontacts.StreetNumber, empty.StreetNumber);
		if (result == 0)
		{
			cout << " ";
		}
		else
		{
			_strupr_s(existingcontacts.StreetName);
			cout << "Street Address " << x << ": " << existingcontacts.StreetNumber << " " << existingcontacts.StreetName << endl;
		}
		result = strcmp(existingcontacts.city, empty.city);
		if (result == 0)
		{
			cout << " ";
		}
		else
		{
			_strupr_s(existingcontacts.city);
			cout << "City " << x << ": " << existingcontacts.city << endl;
		}
		result = strcmp(existingcontacts.State, empty.State);
		if (result == 0)
		{
			cout << " ";
		}
		else
		{
			_strupr_s(existingcontacts.State);
			cout << "State(xx) " << x << ": " << existingcontacts.State << endl;
		}
		if (existingcontacts.Zip == 0)
		{
			cout << " " << endl;
		}
		else
		{
			cout << "Zip Code " << x << ": " << existingcontacts.Zip << endl;
			cout << "//////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////" << endl; //little divider
		} 
			
	}

}


contact UpdateContact()
{
	printcontacts();

	cout << "\n\nWhich contact would you like to update?" << endl;

	int i = 0;
	cin >> i;
		while (i >= numberofcontacts)					//This while loop prevents the user from overwriting onto an undefined array. I tested it without it and I could write onto any integer that I input															
		{
			cout << "Invalid Input, Try again" << endl;
			cin >> i;
		}
	
		contacts[i] = InputNewContact();
		contact updatedcontacts = contacts[i];
		cout << "\n" << endl;

		return updatedcontacts;
	
}


contact DeleteContactInformation()
{
	printcontacts();

	cout << "\n\nWhich contact would you like to delete?" << endl;

	int i = 0;						//I didn't add the while loop from the update contact here because there were no negative consequences from inputing an integer larger than the numberofcontacts counter
	cin >> i;
	contact deletedcontact = contacts[i];
	contacts[i] = {NULL};
	
	for (i; i < numberofcontacts; i++)	//shifts deleted contact to the top
	{
		contacts[i] = contacts[i + 1];
	}

	return deletedcontact;

}


void menu() {
	char options = '\0';

	do
	{
		cout << "Welcome to the contacts menu\n"
			<< "1)Add New Contact\n"
			<< "2)Update Contact\n"
			<< "3)Print All Contacts\n"
			<< "4)Delete Contact\n"
			<< "5)Exit\n";
		cin >> options;
		switch (options)
		{
		case('1'):
			contacts[numberofcontacts++] = InputNewContact();
			break;
		case('2'):
			UpdateContact();
			break;
		case('3'):
			printcontacts();
			break;
		case('4'):
			DeleteContactInformation();

			break;
		case('5'):
			cout << "Have a wondeful day!" << endl;
			break;
		default:
			cout << "Invalid Input, Try Again!" << endl;
		}

	} while (options != '5');

};