-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectors.cpp
97 lines (73 loc) · 1.61 KB
/
vectors.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
91
92
93
94
95
96
97
#include <iostream>
#include <vector>
using namespace std;
class Pixel
{
private:
int r;
int g;
int b;
public:
Pixel();
Pixel(int, int, int);
};
class Image
{
private:
vector<Pixel> pixels;
public:
Image(vector<Pixel> pixels);
};
Pixel::Pixel(int r, int g, int b)
{
this->r = r;
this->g = g;
this->b = b;
}
Image::Image(vector<Pixel> pixels)
{
this->pixels = pixels;
}
void print(vector<int> roll)
{
for (int i = 0; i < 10; i++)
{
cout << " Element @ " << i << ": " << roll[i] << endl;
}
}
int main()
{
vector<int> roll;
roll.resize(13);
print(roll);
cout << "Roll @ 10: " << roll.at(10) << endl;
cout << "Empty? " << roll.empty() << endl;
for (int i = 0; i < 10; i++)
{
roll.push_back((i + 1) * 200);
}
print(roll);
cout << "Size: " << roll.size() << endl;
cout << "Empty? " << roll.empty() << endl;
roll.resize(5);
cout << "Size: " << roll.size() << endl;
cout << "Empty? " << roll.empty() << endl;
print(roll);
// vector of pointers.
int image_h = 10;
int image_w = 10;
vector<Pixel> pixels;
srand(time(0));
for (int i = 0; i < image_h * image_w; i++)
{
Pixel pixel(rand(), rand(), rand());
pixels.push_back(pixel);
}
Image image(pixels);
cout << "The size of the image: " << pixels.size() << endl;
cout << "The max_size: " << pixels.max_size() << endl;
// pixels.resize(5);
// cout << "The size of the image: " << pixels.size() << endl;
// cout << "The max_size: " << pixels.max_size() << endl;
return 0;
}