-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
143 lines (138 loc) · 3.87 KB
/
Copy pathSource.cpp
File metadata and controls
143 lines (138 loc) · 3.87 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include <string>
#include <ctime>
#include <fstream>
using namespace std;
class CCoins
{
private:
const char* sface = "Ëèöåâà ñòîðîíà";
const char* sback = "Òèëüíà ñòîðîíà";
int coins[3] = { 0,0,0 };
int* asd = coins;
double quantity = 0;
double all = 0;
double perc = 0;
public:
CCoins operator ++ (int)
{
CCoins ret(*this);
srand((int)time(0));
for (int i = 0; i < 3; i++) {
all++;
coins[i] = rand() % 2 + 1;
//cout << coins[i] << endl;
if (coins[i] == 1) {
quantity++;
} //ßêùî coins[i]==1, òîä³ öå ëèöåâà ñòîðîíà,³íàêøå òèëüíà.
}
return ret;
}
bool operator == (const CCoins& other)
{
int f = 0;
for (int i = 0; i < 3; i++) {
if (this->coins[i] == other.coins[i]) {
f++;
}
}
if (f == 3)
return true;
else
return false;
}
CCoins operator () ()
{
CCoins ret(*this);
for (int i = 0; i < 3; i++) {
if (coins[i] == 1)
cout << sface << endl;
else
cout << sback << endl;
}
cout << "Êiëüêiñòü ìîíåò ùî º ëèöåâèìè: " << quantity << endl;
return ret;
}
CCoins operator % (int)
{
CCoins ret(*this);
perc = 100 / all * quantity;
cout << perc << "%" << endl;
return ret;
}
int operator = (int)
{
quantity = 0;
all = 0;
for (int i = 0; i < 3; i++) {
coins[i] = 0;
}
return 0;
}
friend ostream& operator << (ostream& i, const CCoins val)
{
cout << "-----------------------------------------------------------------------------------------------------------" << endl;
cout << "Ïiäêèíóòè ìîíåòè.(íàòèñíiòü 1)" << endl;
cout << "Ïîòî÷íèé ñòàí?.(íàòèñíiòü 2)" << endl;
cout << "Ñêèíóòè êiëüêiñòü ëèöåâèõ ìîíåò.(íàòèñíiòü 3)" << endl;
cout << "Êèíóòè ìîíåòè çíîâó i ïåðåâiðèòè, ÷è çáiãàþòüñÿ ëèöåâi ñòîðîíè?(íàòèñiíiòü 4)" << endl;
cout << "Âiäñîòîê ìîíåò ç ëèöåâèìè ñòîðîíàìè.(íàòèñíiòü 5)" << endl;
cout << "Ïåðåâåðíóòè ìîíåòó.(íàòèñíiòü 6)" << endl;
cout << "Çóïèíèòè ïðîãðàìó.(íàòèñíiòü 7)" << endl;
cout << "-----------------------------------------------------------------------------------------------------------" << endl;
return i;
}
friend istream& operator>>(istream& i, CCoins& st)
{
int s;
cout << "ßêó ìîíåòó âè õî÷åòå ïåðåâåðíóòè? (Íàòèñíiòü 1 àáî 2 àáî 3)" << endl;
cin >> s;
cout << "ßêùî âè õî÷åòå ïåðåâåðíóòè íà ëèöåâó ñòîðîíó (íàòèñíiòü 1)" << endl;
cout << "ßêùî âè õî÷åòå ïåðåâåðíóòè íà òèëüíó ñòîðîíó (íàòèñíiòü 2)" << endl;
i >> st.coins[s - 1];
return i;
}
protected:
};
int main()
{
setlocale(LC_ALL, "ukr");
int func = 1;
CCoins num1;
CCoins num2;
cout << "Ùî âàì ïîòðiáíî?" << endl;
while (func != 7) {
cout << num1;
cin >> func;
if (func == 1) {
num1++;
}
if (func == 2) {
num1();
}
if (func == 3) {
num1 = 0;
if (func == 1) {
num1++;
}
if (func == 2) {
num1();
}
}
if (func == 4) {
num1();
num2++;
num2();
bool result = num1 == num2;
cout << result << endl;
}
if (func == 5) {
num1 % 1;
}
if (func == 6) {
cin >> num1;
}
}
cout << "Ïðîãðàìà çàâåðøèëà ïðàöþâàòè.";
return 0;
}