-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTLrandom_shuffle.cpp
84 lines (65 loc) · 1.34 KB
/
STLrandom_shuffle.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
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <array>
#include <ctime>
using namespace std;
class Animals
{
public:
virtual void Speak() = 0;
};
class Cat : public Animals{
public:
virtual void Speak() override;
};
void Cat::Speak()
{
cout << "Mrrrrrr......." << endl;
}
class Dog :public Animals {
public:
virtual void Speak() override;
};
void Dog::Speak()
{
cout << "GAFFF!!!!!!!" << endl;
}
class Parrot : public Animals {
public:
virtual void Speak() override;
};
void Parrot::Speak()
{
cout << "Temirlan alkash! Temirlan alkash! Temirlan alkash!" << endl;
}
int main() {
array <int, 5> arr{ 4, 3, 7, 8, 5 };
for (auto& item : arr) {
cout << item << endl;
}
cout << "Random:" << endl;
srand(time(NULL));
random_shuffle(begin(arr), end(arr));
for (auto& item : arr) {
cout << item << endl;
}
cout << "__________________" << endl;
cout << "class Animals: " << endl;
Animals *animals[]{new Cat(), new Dog(), new Parrot()};
for (auto& item : animals) {
item->Speak();
}
cout << endl;
cout << "Random: " << endl;
random_shuffle(begin(animals), end(animals));
for (auto& item : animals) {
item->Speak();
}
cout << endl;
//delete[] animals;
//*animals = 0;
return 0;
}