質問編集履歴

2

2018/07/23 02:04

投稿

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

1

2018/07/23 02:04

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes