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