-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting43.cpp
90 lines (74 loc) · 1.27 KB
/
listing43.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//Ejemplo de contructro copia
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
class Arr
{
private:
int a[10];
public:
Arr(int x = 0)
{
for (int i =0; i<10; i++)
{
if (x==0)
{
x = rand();
}
a[i] = x;
}
}
Arr (const Arr &copia)
{
for (int i = 0; i<10; i++)
{
a[i]= copia.a[i];
}
}
char set(int, int);
int get(int) const;
int get(int);
};
char Arr::set (int pos, int val)
{
if (pos>=0 && pos<10)
{
a[pos]= val;
return 1;
}
return 0;
}
int Arr::get (int pos) const
{
if (pos>=10 && pos<=10)
{
return a[pos];
}
return 0;
}
int Arr::get (int pos)
{
if (pos>=0 && pos<10)
{
return a[pos];
}
return 0;
}
int main()
{
Arr a(5), b;
srand(time(NULL));
a.set(0,1);
a.set(1,11);
cout<<a.get(0)<< endl;
cout <<a.get(1)<<endl;
b.set(0,2);
b.set(1,22);
cout <<b.get(0)<<endl;
cout <<b.get(1)<<endl;
Arr d(a);
cout <<d.get(0)<<endl;
cout <<d.get(1)<<endl;
return 0;
}