/
类的继承
72 lines (72 loc) · 884 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
srand((unsigned)time(0));
class Random
{
int x;
public:
void random(int n)
{
x=rand() % n;
}
};
class RandomNumber:public Random
{
int a,b,c,d;
public:
void random(int n)
{
a = rand() % n;
b = rand() % n;
c = rand() % n;
d = rand() % n;
}
void showA()
{
cout << a;
}
void showB()
{
cout << b;
}
void showC()
{
cout << c;
}
void showD()
{
cout << d;
}
};
class RandomOperation:public RandomNumber
{
char x, y, z,a[3];
public:
void random(int n)
{
for(int i=0;i<3;i++)
switch (rand() % 3)
{
case 0:a[i] = '+';break;
case 1:a[i] = '-';break;
case 2:a[i] = '*';break;
case 3:a[i] = '/';break;
}
}
void val()
{
x = a[0];y = a[1];z = a[2];
}
void showOper()
{
showA();
cout << x;
showB();
cout << y;
showD();
cout << z;
showD();
}
};