-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoneBook.cpp
86 lines (66 loc) · 1.39 KB
/
PhoneBook.cpp
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
#include "PhoneBook.h"
PhoneBook::PhoneBook()
{
Name = "N/A";
PhoneNumber1= "N/A";
Address= "N/A";
id ="N/A" ;
}
void PhoneBook::AddRecord()
{
cout << "Enter Person Name: ";
cin.ignore();
getline(cin, Name);
cout << "Enter Person phonenumber: ";
cin.ignore();
getline(cin, PhoneNumber1);
cout << "Enter Person Address: ";
cin.ignore();
getline(cin, Address);
cout << "Enter A unique Id : ";
cin.ignore();
getline(cin, id);
}
void PhoneBook::ShowRecord()
{
std::cout << std::setw(5) << id << std::setw(20) << Name << std::setw(30) << PhoneNumber1 << std::setw(30) << Address << "\n";
}
void PhoneBook::UpdateRecord()
{
cout << "\t\n**Enter New Data**\n";
cout << "Enter Person Name: ";
getline(cin, Name);
cout << "Enter Person phonenumber: ";
getline(cin, PhoneNumber1);
cout << "Enter Person Address: ";
getline(cin, Address);
cout << "Enter A unique Id : ";
getline(cin, id);
}
void PhoneBook::AddtoFile(fstream& file)
{
file << Name<<"\n";
file << PhoneNumber1 << "\n";
file << Address << "\n";
file << id << "\n";
}
bool PhoneBook::GetFromFile(std::ifstream& file)
{
if (std::getline(file, Name) &&
std::getline(file, PhoneNumber1) &&
std::getline(file, Address) &&
std::getline(file, id))
{
// Data successfully read from the file
return true;
}
else
{
// Failed to read data from the file
return false;
}
}
string PhoneBook::GetId()
{
return id;
}