-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdeleteFriends.cpp
More file actions
77 lines (62 loc) · 1.3 KB
/
deleteFriends.cpp
File metadata and controls
77 lines (62 loc) · 1.3 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
#include <iostream>
using namespace std;
class person{
public:
string address;
string id;
string name;
};
class addressbook{
person* friends;
int numberOfFriends;
public:
addressbook();
~addressbook();
void listFriends();
void addFriend(string name);
person find(string query);
};
// constructor
addressbook::addressbook(){
numberOfFriends = 0;
friends = new person [100];
}
addressbook::~addressbook(){
delete[] friends;
}
void addressbook::addFriend(string name){
friends[numberOfFriends].name = name;
numberOfFriends++;
}
void addressbook::listFriends(){
for(int i = 0; i < numberOfFriends; i++){
cout << friends[i].name << "\n";
}
}
person addressbook::find(string query){
for(int i = 0; i < numberOfFriends; i++){
if(friends[i].name == query){
return friends[i];
}
}
person noone;
return noone;
}
int main()
{
addressbook abook;
string name;
string query;
while(1){
cout << "住所録に登録する名前を入力してください(終了するにはquitと入力してください): ";
cin >> name;
if(name == "quit"){break;}
abook.addFriend(name);
}
cout << "\n名前リスト:\n";
abook.listFriends();
cout << "検索:";
cin >> query;
person res = abook.find(query);
cout << res.address;
}