MCPcopy Create free account
hub / github.com/Rustam-Z/cpp-programming / F_Second_Program

Function F_Second_Program

Lab_20/Person.cpp:134–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134void F_Second_Program()
135{
136
137 Person p; // global object for each cases
138
139 for (int k = 0; k < 1000; k++)
140 {
141 system("cls");
142 cout << " C O N T A C T S\n"
143 << "--------------------------------------\n"
144 << " 1. Search contact by Phone number\n"
145 << " 2. Search contact by Name\n"
146 << " 3. Delete a contact\n"
147 << " 4. Add a record to a specific position\n"
148 << " 0. Back\n"
149 << " Your choice: \n";
150
151 switch (_getch())
152 {
153 // case 49 for searching the contact by Phone Number
154 case 49:
155 {
156 system("cls");
157 cout << " SEARCH CONTACT BY PHONE NUMBER\n-------------------------------\n";
158
159 string search_by_tell_number;
160 bool isFound = 0;
161
162 ifstream in_contacts_list("contacts", ios::binary); // getting data from the file
163 cout << " List of all Contacts: \n";
164 cout << " Name Phone\n-------------------------------\n";
165 while (in_contacts_list.read((char *)&p, sizeof(Person)))
166 {
167 // displaying the data
168 p.displayData();
169 }
170 position = 1;
171 in_contacts_list.close();
172
173 cout << "\n Enter the phone number: ";
174 cin >> search_by_tell_number;
175
176 ifstream in_contacts("contacts", ios::binary); // getting data from the file
177 // in_contacts.seekg(0, ios::end);
178
179 // cheaking the list for the specific data
180 cout << " Found Contact(s): \n";
181 while (in_contacts.read((char *)&p, sizeof(Person)))
182 {
183 if (search_by_tell_number == p.getTellNumber())
184 {
185 isFound = 1;
186 p.displayData();
187 }
188 }
189 position = 1;
190 in_contacts.close(); // closing the file
191

Callers 1

mainFunction · 0.70

Calls 5

displayDataMethod · 0.80
getTellNumberMethod · 0.80
setDataMethod · 0.80
mainFunction · 0.70
getNameMethod · 0.45

Tested by

no test coverage detected