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
| #include <iostream>
#include <string>
#define _DataBase "D:\\PhoneBook.txt"
#define _MAX_LEN 1000
using namespace std;
class PhoneBook
{
private:
char *_Name;
char *_Sur_Name;
char *_PatroNymic;
char *_Cell_Phone;
char *_Home_Phone;
char *_E_mail;
char *_Home_Address;
public:
PhoneBook();
~PhoneBook();
int PhoneBook_Count(PhoneBook *obj, FILE *fp, char *_DBuff);
void _Add_Data(PhoneBook *obj, FILE *fp, char *_TempBuff, char *_TStr);
void _Delete_Data(PhoneBook *obj, FILE *fp, char *_DBuff);
void _Display_Data(PhoneBook *obj, FILE *fp, char *_DBuff);
void _Edit_data(PhoneBook *obj, FILE *fp, char *_DBuff);
void _Menu_of_PhoneBook(PhoneBook *obj, FILE *fp, char *_DBuff, char *_TempBuff, char *_TStr, int choise);
friend ostream & operator << (ostream &stream, PhoneBook obj);
};
int main ()
{
FILE *fp = 0;
char _DBuff[1000], _TempBuff[10], _TStr[50];
int choise = 0;
PhoneBook *obj = 0;
obj = new PhoneBook();
obj ->_Menu_of_PhoneBook(obj,fp,_DBuff,_TempBuff,_TStr,choise);
delete obj;
return 0;
}
PhoneBook::PhoneBook()
{
this ->_Name = new char [_MAX_LEN];
this ->_Sur_Name = new char [_MAX_LEN];
this ->_PatroNymic = new char [_MAX_LEN];
this ->_Cell_Phone = new char [_MAX_LEN];
this ->_Home_Phone = new char [_MAX_LEN];
this ->_E_mail = new char [_MAX_LEN];
this ->_Home_Address = new char [_MAX_LEN];
}
PhoneBook::~PhoneBook()
{
delete [] this ->_E_mail;
delete [] this ->_Home_Phone;
delete [] this ->_Cell_Phone;
delete [] this ->_PatroNymic;
delete [] this ->_Sur_Name;
delete [] this ->_Name;
delete [] this ->_Home_Address;
}
void PhoneBook::_Add_Data(PhoneBook *obj, FILE *fp, char *_TempBuff, char *_TStr)
{
int Kol = 0;
cout << "Enter the number of additions:" << endl;
cin >> Kol;
itoa(Kol,_TempBuff,10);
gets(_TempBuff);
for (int i = 0; i < Kol; i++)
{
if (fp = fopen(_DataBase, "a+"))
{
cout << "Enter the number of the order:" << endl;
gets(_TStr);
strcat(_TStr, "\n");
fputs(_TStr,fp);
cout << "Enter a name:" << endl;
gets(_Name);
strcat(_Name, "\n");
fputs(_Name,fp);
cout << "Enter a surname:" << endl;
gets(_Sur_Name);
strcat(_Sur_Name, "\n");
fputs(_Sur_Name,fp);
cout << "Enter a first name:" << endl;
gets(_PatroNymic);
strcat(_PatroNymic, "\n");
fputs(_PatroNymic,fp);
cout << "Enter Enter your mobile phone:" << endl;
gets(_Cell_Phone);
strcat(_Cell_Phone, "\n");
fputs(_Cell_Phone,fp);
cout << "Enter Enter your home phone:" << endl;
gets(_Home_Phone);
strcat(_Home_Phone, "\n");
fputs(_Home_Phone,fp);
cout << "Enter Enter your E-mail adress:" << endl;
gets(_E_mail);
strcat(_E_mail, "\n");
fputs(_E_mail,fp);
cout << "Enter Enter your home address:" << endl;
gets(_Home_Address);
strcat(_Home_Address, "\n");
fputs(_Home_Address,fp);
}
else
cout << "Error opening file for writing." << endl;
}
fclose (fp);
fp = 0;
}
void PhoneBook::_Delete_Data(PhoneBook *obj, FILE *fp, char *_DBuff)
{
}
void PhoneBook::_Display_Data(PhoneBook *obj, FILE *fp, char *_DBuff)
{
if (fp = fopen (_DataBase, "r"))
{
fgets(_DBuff,1000,fp);
fgets(_DBuff,1000,fp);
strcpy(this ->_Name,_DBuff);
this ->_Name = char(0);
fgets(_DBuff,1000,fp);
strcpy(this ->_Sur_Name,_DBuff);
this ->_Sur_Name = char(0);
fgets(_DBuff,1000,fp);
strcpy(this ->_PatroNymic,_DBuff);
this ->_PatroNymic = char(0);
fgets(_DBuff,1000,fp);
strcpy(this ->_Cell_Phone,_DBuff);
this ->_Cell_Phone = char(0);
fgets(_DBuff,1000,fp);
strcpy(this ->_Home_Phone,_DBuff);
this ->_Home_Phone = char(0);
fgets(_DBuff,1000,fp);
strcpy(this ->_E_mail,_DBuff);
this ->_E_mail = char(0);
fgets(_DBuff,1000,fp);
strcpy(this ->_Home_Address,_DBuff);
this ->_Home_Address = char(0);
}
else
{
cout << "Error opening file for reading." << endl;
}
fclose (fp);
fp = 0;
}
ostream & operator << (ostream &stream, PhoneBook obj)
{
stream << obj._Name << endl;
stream << obj._Sur_Name << endl;
stream << obj._PatroNymic << endl;
stream << obj._Cell_Phone << endl;
stream << obj._Home_Phone << endl;
stream << obj._E_mail << endl;
stream << obj._Home_Address << endl;
return stream;
}
void PhoneBook::_Menu_of_PhoneBook(PhoneBook *obj, FILE *fp, char *_DBuff, char *_TempBuff, char *_TStr, int choise)
{
cout << "\tMENU:" << endl;
cout << "1. Add data to the database:" << endl;
cout << "2. Delete data from the database:" << endl;
cout << "3. Display the data in the database:" << endl;
cout << "4. Exit:" << endl << endl;
cout << "Please make your choice:" << endl;
cin >> choise;
switch (choise)
{
case 1:
obj ->_Add_Data(obj,fp,_TempBuff,_TStr);
break;
case 2:
obj ->_Delete_Data(obj,fp,_DBuff);
break;
case 3:
obj ->_Display_Data(obj,fp,_DBuff);
cout << obj;
break;
default:
cout << "Selected the wrong menu item." << endl;
}
system("pause > nul");
} |