質問編集履歴

2

2018/07/17 14:04

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- オブジェクト指向を用いたプログラムについて
1
+ オブジェクト指向プログラミング
test CHANGED
@@ -1,261 +1 @@
1
- オブジェクト指向の3大要素をもちいて簡単なプログラムを作成ています。
1
+ オブジェクト指向プログラミングで三大要素について説明おねがいします。
2
-
3
- 下記のプログラムに予想を2位を追加して乱数の結果も1位、2位とした時の、結果を表示させたいのですがどうしたらいいでしょうか?力を貸してくださいよろしくお願いします。
4
-
5
- ーーーーーーーーーーーーーーー
6
-
7
-
8
-
9
- #include <stdio.h>
10
-
11
- #include <stdlib.h>
12
-
13
- #include <time.h>
14
-
15
- #pragma warning(disable:4996);
16
-
17
- #define P0 0
18
-
19
- #define P1 1
20
-
21
- #define P2 2
22
-
23
- #define P3 3
24
-
25
- #define P4 4
26
-
27
- #define P5 5
28
-
29
- #define P6 6
30
-
31
- #define P7 7
32
-
33
- #define P8 8
34
-
35
-
36
-
37
- #define USER 0
38
-
39
- #define GAME 1
40
-
41
- class HorsePlayer
42
-
43
- {
44
-
45
- public:
46
-
47
- int RacePlan();
48
-
49
- };
50
-
51
- int HorsePlayer::RacePlan()
52
-
53
- {
54
-
55
- int yosou;
56
-
57
- printf("9頭の中から1位の馬を予想する。\n");
58
-
59
- printf("0:藤瀬、1:中野、2:志土地、3:青山、4:内田、5:中島、6:遠藤、7:実藤、8:田中、9:江島 \n");
60
-
61
- printf("あなたが1位と予想したのは");
62
-
63
- scanf("%d", &yosou);
64
-
65
- return yosou;
66
-
67
- }
68
-
69
-
70
-
71
- class HorseGame
72
-
73
- {
74
-
75
- public:
76
-
77
- int RacePlan();
78
-
79
- };
80
-
81
-
82
-
83
- int HorseGame::RacePlan()
84
-
85
- {
86
-
87
- int yosou;
88
-
89
- srand(time(NULL));
90
-
91
- yosou = rand() % 9;
92
-
93
- printf("1位になった馬= %d\n", yosou);
94
-
95
- return yosou;
96
-
97
- }
98
-
99
-
100
-
101
- class Raceresult
102
-
103
- {
104
-
105
- public:
106
-
107
- int TakeHorse(int a, int b);
108
-
109
- void ShowHorsel(int c);
110
-
111
- };
112
-
113
-
114
-
115
- int Raceresult::TakeHorse(int a, int b)
116
-
117
- {
118
-
119
- int yosou;
120
-
121
- if (a == b)
122
-
123
- {
124
-
125
- yosou = USER;
126
-
127
- }
128
-
129
- else if ((a == P0) && (b == P1))
130
-
131
- {
132
-
133
- yosou = GAME;
134
-
135
- }
136
-
137
- else if ((a == P0) && (b == P2))
138
-
139
- {
140
-
141
- yosou = GAME;
142
-
143
- }
144
-
145
- else if ((a ==P0) && (b == P3))
146
-
147
- {
148
-
149
- yosou = GAME;
150
-
151
- }
152
-
153
- else if ((a == P0) && (b == P4))
154
-
155
- {
156
-
157
- yosou = GAME;
158
-
159
- }
160
-
161
- else if ((a == P0) && (b == P5))
162
-
163
- {
164
-
165
- yosou = GAME;
166
-
167
- }
168
-
169
- else if ((a == P0) && (b == P6))
170
-
171
- {
172
-
173
- yosou = GAME;
174
-
175
- }
176
-
177
- else if ((a == P0) && (b == P7))
178
-
179
- {
180
-
181
- yosou = GAME;
182
-
183
- }
184
-
185
- else if ((a == P0) && (b == P8))
186
-
187
- {
188
-
189
- yosou = GAME;
190
-
191
- }
192
-
193
- else
194
-
195
- {
196
-
197
- yosou = GAME;
198
-
199
- }
200
-
201
- return yosou;
202
-
203
- }
204
-
205
-
206
-
207
- void Raceresult::ShowHorsel(int c)
208
-
209
- {
210
-
211
- if (c == USER)
212
-
213
- {
214
-
215
- printf("的中!お見事!!\n");
216
-
217
- }
218
-
219
- else if (c == GAME)
220
-
221
- {
222
-
223
- printf("はずれ!残念!!\n");
224
-
225
- }
226
-
227
- return;
228
-
229
- }
230
-
231
-
232
-
233
- int main(){
234
-
235
- int a, b, show;
236
-
237
- HorsePlayer user;
238
-
239
- HorseGame game;
240
-
241
- Raceresult result;
242
-
243
-
244
-
245
- a = user.RacePlan();
246
-
247
-
248
-
249
- b = game.RacePlan();
250
-
251
-
252
-
253
- show = result.TakeHorse(a, b);
254
-
255
-
256
-
257
- result.ShowHorsel(show);
258
-
259
- return 0;
260
-
261
- }

1

2018/07/17 14:04

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -14,8 +14,6 @@
14
14
 
15
15
  #pragma warning(disable:4996);
16
16
 
17
- // カードの絵を表す定数
18
-
19
17
  #define P0 0
20
18
 
21
19
  #define P1 1
@@ -36,14 +34,10 @@
36
34
 
37
35
 
38
36
 
39
- // 勝者を表す定数
40
-
41
37
  #define USER 0
42
38
 
43
39
  #define GAME 1
44
40
 
45
- // ユーザーを表すクラス
46
-
47
41
  class HorsePlayer
48
42
 
49
43
  {
@@ -54,8 +48,6 @@
54
48
 
55
49
  };
56
50
 
57
- // ユーザーの選ぶ絵のメンバ関数
58
-
59
51
  int HorsePlayer::RacePlan()
60
52
 
61
53
  {
@@ -74,7 +66,7 @@
74
66
 
75
67
  }
76
68
 
77
- // ゲームを表すクラス
69
+
78
70
 
79
71
  class HorseGame
80
72
 
@@ -86,7 +78,7 @@
86
78
 
87
79
  };
88
80
 
89
- // ゲームの選ぶ絵のメンバ関数
81
+
90
82
 
91
83
  int HorseGame::RacePlan()
92
84
 
@@ -104,7 +96,7 @@
104
96
 
105
97
  }
106
98
 
107
- // 判定を表すクラス
99
+
108
100
 
109
101
  class Raceresult
110
102
 
@@ -118,7 +110,7 @@
118
110
 
119
111
  };
120
112
 
121
- // 勝者を判定するメンバ関数
113
+
122
114
 
123
115
  int Raceresult::TakeHorse(int a, int b)
124
116
 
@@ -210,7 +202,7 @@
210
202
 
211
203
  }
212
204
 
213
- // 勝敗を表示するメンバ関数
205
+
214
206
 
215
207
  void Raceresult::ShowHorsel(int c)
216
208
 
@@ -236,7 +228,7 @@
236
228
 
237
229
  }
238
230
 
239
- // プログラムのメイン関数
231
+
240
232
 
241
233
  int main(){
242
234
 
@@ -248,19 +240,19 @@
248
240
 
249
241
  Raceresult result;
250
242
 
251
- // ユーザーが絵を選択する。
243
+
252
244
 
253
245
  a = user.RacePlan();
254
246
 
255
- // ゲームが絵を選択する。
247
+
256
248
 
257
249
  b = game.RacePlan();
258
250
 
259
- // 勝敗を判定する。
251
+
260
252
 
261
253
  show = result.TakeHorse(a, b);
262
254
 
263
- // 勝敗を表示する。
255
+
264
256
 
265
257
  result.ShowHorsel(show);
266
258