-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting50.cpp
70 lines (60 loc) · 1013 Bytes
/
listing50.cpp
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
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
class Arr{
private:
int a[10];
public:
Arr(int x = 0){
srand(time(NULL));
for (int i = 0; i <10; i++)
{
if (x==0)
{
x = rand()%100;
}
a[i] = x;
}
}
char set(int, int);
int get(int) const;
int get(int);
};
char Arr::set(int pos, int val) {
if (pos>=0 && pos<10)
{
return a[pos] = val;
}
return 0;
}
int Arr::get(int pos)const
{
if (pos>=0&&pos<10)
{
return a[pos];
}
return 0;
}
int Arr::get(int pos)
{
if (pos>=0 && pos<10)
{
return a[pos];
}
return 0;
}
int main()
{
const Arr a(5), b;
Arr c;
c.set(0,3);
c.set(1,33);
cout <<a.get(0)<< endl;
cout<<a.get(1)<<endl;
cout <<b.get(0)<< endl;
cout<<b.get(1)<<endl;
cout <<c.get(0)<<endl;
cout<<c.get(1)<<endl;
return 0;
}