-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject CMS.cpp
More file actions
356 lines (339 loc) · 10.5 KB
/
Copy pathProject CMS.cpp
File metadata and controls
356 lines (339 loc) · 10.5 KB
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
/*
* Lab Project
* Topic : Contact Managment System
* CSCL 1208 Lab : Object Oriented Programming Techniques
* Date: 2 - June / 2021
* Group Members : - Asher Fraz Anjum
* - Ameer Yousaf Ali
* - Muhammad Hamza
*
* Project Requirement:-
* 1) First Name ==>> Person [ Char array[12] ]
* 2) Last Name ==>> Surname [ Char array[10] ]
* 3) Country Code ==>> (+) 92 [ string ]
* 4) Phone Number ==>> 0312-3456789 [ string ]
* 5) Address ==>> House, Street - RWP [ string ]
* 6) Electronic-Mail ==>> CMS@project.com [ string ]
*/
# include <iostream>
# include <conio.h>
# include <string.h>
# include <fstream>
using namespace std;
// File Handling
fstream file("Contacts.txt" , ios::in | ios::out | ios::app );
// Forward Declarations
class Address;
class Handle_File;
/* Classes */
class Contacts {
private:
char option ;
string Keyword , data , usename1 , usename2 , usename3;
protected:
char fname[15] , lname[12] , P_number[16] , country_code[4];
public:
void addContact(){
system("cls");
cout<<"\n\n\t\t\t Contact Management System"<<endl;
cout<<"\n Creating New Contact "<<endl;
cout<<"\n\tEnter First Name : "; cin.ignore(); gets(fname);
cout<<"\n\tEnter Last Name : "; gets(lname);
cout<<"\n\tEnter Country Code : "; gets(country_code);
cout<<"\n\tEnter Phone Number : "; gets(P_number);
}
/* Search Contact */
void searchContact(){
bool found = false ;
system("cls");
ifstream file("Contacts.txt" , ios::in | ios::app );
cout<<"\n\n\t\t\t Contact Management System"<<endl<<endl;
cout<<"\n Searching Contact details in Phone-Book"<<endl;
cout<<" Which option you want to search:"<<endl;
cout<<"\n\t[1] First Name"<<endl
<<"\n\t[2] Last Name "<<endl
<<"\n\t[3] Phone Number "<<endl;
cout<<"\n Enter Option: "; cin>>option;
cout<<endl;
switch(option){
case '1' : {
// Search with First Name
cout<<"\t Enter First Name to Search: "; cin.ignore(); getline(cin,Keyword);
while( !file.eof() ){
getline(file,data);
if(Keyword == data){
cout<<"\nFirst Name \t "<<data<<endl;
getline(file,data);
cout<<"Last Name \t "<<data<<endl;
getline(file,data);
cout<<"Country Code \t "<<data<<endl;
getline(file,data);
cout<<"Phone Number \t "<<data<<endl;
getline(file,data);
cout<<"Email \t\t "<<data<<endl;
getline(file,data);
cout<<"Address \t "<<data<<endl<<endl
<<"\t Contact retrieved Successfully!"<<endl;
found = true;
}
}
if(found == false){
cout<<" Contact not exist in PhoneBook!"<<endl;
}
break;
}
case '2' : {
// Search with Last Name
cout<<"\t Enter Last Name to Search: "; cin.ignore(); getline(cin,Keyword);
while( !file.eof() ){
getline(file, usename1);
getline(file,data);
if(Keyword == data ){
cout<<"\nFirst Name \t "<<usename1<<endl;
cout<<"Last Name \t "<<data<<endl;
getline(file,data);
cout<<"Country Code \t "<<data<<endl;
getline(file,data);
cout<<"Phone Number \t "<<data<<endl;
getline(file,data);
cout<<"Email \t\t "<<data<<endl;
getline(file,data);
cout<<"Address \t "<<data<<endl<<endl
<<"\t Contact retrieved Successfully!"<<endl;
found = true;
}
}
if(found == false){
cout<<" Contact not exist in PhoneBook!"<<endl;
}
break;
}
case '3' : {
// Search with Phone Number
cout<<"\t Enter Phone Number to Search: "; cin.ignore(); getline(cin,Keyword);
while( !file.eof() ){
getline(file, usename1);
getline(file, usename2);
getline(file, usename3);
getline(file,data);
if(Keyword == data ){
cout<<"\nFirst Name \t "<<usename1<<endl;
cout<<"Last Name \t "<<usename2<<endl;
cout<<"Country Code \t "<<usename3<<endl;
cout<<"Phone Number \t "<<data<<endl;
getline(file,data);
cout<<"Email \t\t "<<data<<endl;
getline(file,data);
cout<<"Address \t "<<data<<endl<<endl
<<"\t Contact retrieved Successfully!"<<endl;
found = true;
}
}
if(found == false){
cout<<" Contact not exist in PhoneBook!"<<endl;
}
break;
}
default : { searchContact(); }
}
file.close();
}
};
class Address : public Contacts {
protected:
string addr , Email;
public:
/* Friend Class */
friend class Handle_File;
void help();
bool check_Email(string email);
void AddContact(){
addContact();
Re_Mail:
cout<<"\n\tEnter E-mail : "; getline(cin, Email);
if(!check_Email(Email) == true){ goto Re_Mail; }
cout<<"\n\tEnter Address : "; getline(cin, addr);
}
};
class Handle_File : public Contacts {
public:
/* Writting Data to File */
void Writing_file(){
Address Adr;
Adr.AddContact();
ofstream file("Contacts.txt" , ios::out | ios::app );
if(file.is_open()){
file<<Adr.fname<<endl;
file<<Adr.lname<<endl;
file<<Adr.country_code<<endl;
file<<Adr.P_number<<endl;
file<<Adr.Email<<endl;
file<<Adr.addr<<endl<<endl;
cout<<"\n\t\tContact Saved Successfully !"<<endl;
}
else
{
cout<<"\n\tError Opening File !"<<endl;
}
file.close();
}
/* Grabbing Data From Contacts.txt file */
void viewContact(){
ifstream file("Contacts.txt" , ios::in | ios::app );
system("cls");
cout<<"\n\n\t\t\t Contact Management System"<<endl<<endl;
cout<<"\n Viewing All Saved Contacts :";
cout<<"\n==============================================================================="<<endl;
while (!file.eof())
{ string data;
getline(file,data);
cout<<"First Name \t "<<data<<endl;
getline(file,data);
cout<<"Last Name \t "<<data<<endl;
getline(file,data);
cout<<"Country Code \t "<<data<<endl;
getline(file,data);
cout<<"Phone Number \t "<<data<<endl;
getline(file,data);
cout<<"Email \t\t "<<data<<endl;
getline(file,data);
cout<<"Address \t "<<data<<endl;
getline(file,data);
cout<<data<<endl;
}
cout<<"\n==============================================================================="<<endl;
file.close();
}
};
/* Functions Declarations */
int main();
int header_menu(void);
void Program_Restart(void);
void self_exit(void);
/* Main Block OR Driver Code */
int main(){
// Class Object
Handle_File Handle;
Address addr;
string restart;
char opt = header_menu();
switch(opt){
case '1': {
Handle.Writing_file();
break;
}
case '2': {
addr.searchContact();
break;
}
case '3': {
Handle.viewContact();
break;
}
case '4' : {
system("cls");
file.close();
cout<<"\n\n\t\t\t\t Contact Management System"<<endl<<endl;
cout<<"\n\n\t\t\t\a\"Are You Sure You Want To Delete Contacts Book\""<<endl;
cout<<"\n\n\n\t\t\t [ y ] Yes\t | \tNo [ n ] "<<endl<<"\t\t\t\t ===================\n\t\t\t\t\t ";
cin>>restart;
cout<<"\t\t\t\t ==================="<<endl;
if ( restart == "y" || restart == "Y" || restart == "yes" || restart == "Yes" ){
cout<<'\a'<<endl;
system("del contacts.txt");
}
else if (restart == "n" || restart == "no" || restart == "N" || restart == "No" ){
main();
}
break;
}
case '5': {
addr.help();
break;
}
case '6': {
self_exit();
break;
}
default:{
cout << "\n\tPress Any Key To Continue...";
system("pause");
main();
}
}
Program_Restart();
return 0;
}
/* Functions Definations */
int header_menu(void){
system("title Lab Project - Contact Management System ");
system("cls");
// system("mode con cols=85 lines=25");
system("color 0a");
cout<<"\n\n\t\t\t Contacts Management System"<<endl;
cout<<"\n\n\t [1] Create New Contact "<<endl;
cout<<"\n\t [2] Search Contact "<<endl;
cout<<"\n\t [3] View All Contacts "<<endl;
cout<<"\n\t [4] Delete Contacts Book "<<endl;
cout<<"\n\t [5] Documentation "<<endl;
cout<<"\n\t [6] Quit "<<endl;
char opt='0';
cout<<"\n\n\t \f Enter Choice : ";
cin>>opt;
return opt;
}
void self_exit(void){
system("cls");
cout<<"\n\n\t\t\t Contact Management System"<<endl;
cout<<"\n\n\t Exitting!... "<<endl;
_exit(0);
}
void Program_Restart(void){
string restart;
Program_Restart:
cout<<"\n\n\n You want to restart this program [ y ] Yes | No [ n ] : ";
cin>>restart;
if ( restart == "y" || restart == "Y" || restart == "yes" || restart == "Yes" ){
main();
}
else if (restart == "n" || restart == "no" || restart == "N" || restart == "No" ){
file.close();
self_exit();
}
else{
cout << "\n\n\tInvalid Input !";
cout << "\n\tPress Any Key To Continue...";
system("pause");
goto Program_Restart;
}
}
/* Classes Functions */
bool Address :: check_Email(string email){
for(int i=0 ; i<=email.length() ; i++){
if( email[i] == ' ' ){
Email[i] = '\0';
continue;
}
if(email[i] == '@' ){
return true;
}
}
}
void Address :: help(){
system("cls");
cout<<"\n\n\t\t\t Help / Documentation"<<endl
<<"\n\tProject No. 1"<<endl
<<"\n\t\tTopic : Contact Management System"<<endl
<<"\n\tCSCL 1208 Lab : Object Oriented Programming Techniques "<<endl
<<"\n\tDescription : This program help us to Add, Search & View contacts in our Phone Book."<<endl
<<"\n\tGroup Members : @asherfraz \t- Asher Fraz Anjum"<<endl
<<" @ameeryousufalibhatti \t- Ameer Yousaf Ali"<<endl
<<" @HamzahKhalid \t\t- Muhammad Hamza"<<endl<<endl
<<"\tProject Requirement:-"<<endl
<<"\t\t1) First Name\t\t==>> Person \t\t\t [ Char array[12] ] "<<endl
<<"\t\t2) Last Name\t\t==>> Surname \t\t\t [ Char array[12] ] "<<endl
<<"\t\t3) Country Code\t\t==>> (+) 92 \t\t\t\t\t [ string ] "<<endl
<<"\t\t4) Phone Number\t\t==>> 0312-3456789 \t\t\t\t [ string ] "<<endl
<<"\t\t5) Address\t\t\t==>> House 1 , Street 10 - Rawalpindi RWP \t [ string ] "<<endl
<<"\t\t6) Electronic-Mail\t\t==>> CMS@project.com \t\t\t [ string ] "<<endl;
}