Address Book

I am making an address book. need to know if everything is OK in this code. Need Help

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
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;

#define Address_book 3000

struct Address_Book
	{
	    char first[20]; /*First Name*/
	    char last[30]; /*Last Name*/
	    char number[7]; /*Telephone Number*/
	    char email[60]; /*E-Mail*/
	    char address[60]; /*Home Address*/
	};
	 
	class AddressBook
		{
			Address_Book Addressbook;
			public:
			bool CreateMe()
				{
					if(Addressbook.first[0]=='\\') return true; else return false;
				};
			void NewAddress();
			void Delete()
				{
					Addressbook.first[0]='\\';
				};
			void Print(bool showall);
			bool SearchContact(char SearchThis[60]);
		};
	 
	void AddressBook::NewAddress()
		{
			cout << endl << "FirstName: ";
			cin >> Addressbook.first;
			cout << endl << "LastName: ";
			cin >> Addressbook.last;
			cout << endl << "PhoneNumber: ";
			cin >> Addressbook.number;
			cout << endl << "e-mail: ";
			cin >> Addressbook.email;	 
			cout << endl << "HomeAddress: ";
			cin >> Addressbook.address;
			cout << endl << endl;
			cout << "WELL DONE your Created." << endl << endl;

			ofstream writeFile;
			writeFile.open ("RipTide.txt");
			writeFile 
				<< "Full Name: " << " " << Addressbook.first << " " << Addressbook.last << "\n"
				<< "PhoneNumber: " << " " << Addressbook.number << "\n"
				<< "E-mail: " << " " << Addressbook.email << "\n"	 
				<< "HomeAddress: " << " " << Addressbook.address << "\n";
			writeFile.close();

		}
	 
	void AddressBook::Print(bool showall)
		{
			cout << endl << "FirstName: " << Addressbook.first
	        << endl << "LastName: " << Addressbook.last;
			
			if(showall)
				{
					cout << endl << endl << "Number: " << Addressbook.number << endl << "e-mail: " << Addressbook.email
					<< endl << "HomeAddress: " << Addressbook.address << endl << "---" << endl <<  "DONE." << endl;
				}
		}
	 
	 bool AddressBook::SearchContact(char searchThis[60])
		{
			if(!strcmp(Addressbook.first, searchThis)){ return true; }
			else if(!strcmp(Addressbook.last, searchThis)){ return true; }
			else if(!strcmp(Addressbook.number, searchThis)){ return true; }
			else if(!strcmp(Addressbook.email, searchThis)){ return true; }
			else if(!strcmp(Addressbook.address, searchThis)){ return true; }
			else {return false;};
		}
	 
	inline void clearscreen()
		{
			system("CLS"); /* Clear the screen */
			cout << "Address Book for Rip Tide" << endl
				 << "--------------------------" << endl << endl;
		}
	 
	int main()
		{
			AddressBook book[Address_book];
			char Menuoption='0';
			int i;
			char buff[60];
			bool found;
	 
	    for(int j=0; j<Address_book; j++)
	        book[j].Delete();
	 
			clearscreen();
	 
	    while(Menuoption != '6')
			{
	            found=false;
	            i=0;	 
	            cout << "1. Create New " << endl;
	            cout << "2. Modifying data" << endl;
	            cout << "3. Delete " << endl;
	            cout << "4. Search " << endl;
	            cout << "5. Changing all " << endl;
	 
	        cout << endl << "Selection: ";
	        cin >> Menuoption;
	 
				switch(Menuoption)
					{
						case '1':
	 
							do
								{
									if(book[i].CreateMe()){
									book[i].NewAddress();
									found = true;
								}
								i++;
								}while(i < Address_book && !found);
								break;
	 
						case '2':
							cout << "Please, give me a name" << endl;
							cin >> buff;
							if(book[i].SearchContact(buff) && !book[i].CreateMe())
								{
									cout << endl << "MODIFYING: ";
									book[i].Print(false);
									book[i].NewAddress();
								}
							else
								{
									i++;
								}
								break;
	 
						case '3':
							cout << "Please, give me a name" << endl;
							cin >> buff;

							if(book[i].SearchContact(buff) && !book[i].CreateMe())
								{
									cout << endl << "DELETING: ";
									book[i].Print(true);
									cout << endl << "Are you sure? (y/n)";
									cin >> buff[0];
									if(buff[0]=='y') book[i].Delete();
								}
							else
								{
									i++;
								}
								break;
	 
						case '4':
							cout << endl << "Write the Name: " << endl;
							cin >> buff;
	 
							if(book[i].SearchContact(buff) && !book[i].CreateMe())
								{
									book[i].Print(true);
									cout << endl;
								}
							else
								{
									i++;
								}
								break;
								cout << endl << "Type a number to continue ";
								cin >> i;
	 
					case '5':	
						Address_Book newPerson;
					    cout << "Enter first Name:  ";
					    cin >> newPerson.first;
					    cout << endl << endl;
	            
					    cout << "Enter Last Name:  ";
					    cin >> newPerson.last;
					    cout << endl << endl;
	            
					    cout << "Enter Phone Number:  ";
					    cin >> newPerson.number;
					    cout << endl << endl;
	            
					    cout << "Enter Email Address:  ";
					    cin >> newPerson.email;
					    cout << endl << endl;
	            
					    cout << "Enter Address:  ";
					    cin >> newPerson.address;
					    cout << endl << endl;
	            
					    cout << "Your Change name is " << endl;
					    cout << newPerson.first <<" " << newPerson.last << endl;
					    cout << newPerson.number <<endl;
					    cout << newPerson.email << endl;
						cout <<newPerson.address  << endl;
					    cout << endl << endl;
					break;
					}
			}

	    cout << endl << endl << "END. " << endl;

	    getch();
	    return 0;
}
Topic archived. No new replies allowed.