-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinheritance.cpp
More file actions
48 lines (42 loc) · 1.06 KB
/
inheritance.cpp
File metadata and controls
48 lines (42 loc) · 1.06 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
/* inheritance.cpp */
#include <iostream>
using namespace std;
class person{
public:
string name;
};
class ticket{
public:
int id;
person* user;
ticket(){user = new person;}
};
class transTicket : public ticket {
public:
string origin;
string destination;
transTicket(): ticket(){};
};
int main()
{
int ticketNum;
cout << "チケットを何枚購入しますか? ";
cin >> ticketNum;
cout << "\n";
transTicket* tickets = new transTicket [ticketNum];
for(int i = 0; i < ticketNum; i++){
tickets[i].id = i+1;
cout << i+1 << "人目の利用者の名前を入力してください: ";
cin >> tickets[i].user->name;
cout << " 出発地を入力してください: ";
cin >> tickets[i].origin;
cout << " 到着地を入力してください: ";
cin >> tickets[i].destination;
}
cout << "\nチケット利用者一覧:\n";
for(int i = 0; i < ticketNum; i++){
transTicket t = tickets[i];
cout << " " << t.id << " : " << t.user->name << " : " << t.origin << " => " << t.destination << "\n";
}
cout << "\n";
}