-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drob.cpp
120 lines (110 loc) · 2.42 KB
/
Drob.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "Drob.h"
#include <iostream>
using namespace std;
Drob::Drob()
{
chis = 0;
znam = 1;
}
Drob::Drob(int a, int b)
{
chis = a;
znam = b;
}
Drob::~Drob()
{
}
void Drob::Print(Drob x) //Prited Drob/Ïå÷àòàåò äðîáü
{
if (x.chis == 0 or x.znam == 0)
cout << "Drob = 0" << endl;
else
cout << " Chisl = " << chis << " Znam = " << znam << endl;
}
void Drob::Input_one()//Ââîä ïåðâîé äðîáè
{
cout << "Drob one! Enter chislitel and znamenatel:";
cin >> chis >> znam;
cout << endl;
}
void Drob::Input_two() //Ââîä âòîðîé äðîáè
{
cout << "Drob two! Enter chislitel and znamenatel:";
cin >> chis >> znam;
cout << endl;
}
Drob Drob::Plus(Drob x) //Ñóììà äðîáåé/Sum Drobs
{
Drob result;
result.znam = this->znam * x.znam;
result.chis = this->chis * x.znam + this->znam * x.chis;
return result;
}
Drob Drob::Minus(Drob x) //Âû÷èòàíèå äðîáåé/Subtraction Drobs
{
Drob result;
result.znam = this->znam * x.znam;
result.chis = this->chis * x.znam - this->znam * x.chis;
return result;
}
Drob Drob::Multiplication(Drob x)//Multiplication Drobs/Óìíîæåíèå äðîáåé
{
Drob result;
result.znam = this->znam * x.znam;
result.chis = this->chis * x.chis;
return result;
}
Drob Drob::Division(Drob x)//Division Drobs/Äåëåíèå äðîáåé
{
Drob result;
result.znam = this->znam * x.chis;
result.chis = this->chis * x.znam;
return result;
}
Drob Drob::Reduction(Drob x) //Ñîêðàùåíèå äðîáè/Reduction Drob
{
Drob result;
int tmp=0;
int chis1 = x.chis;
int znam1 = x.znam;
while (znam1!=0)
{
tmp = chis1;
chis1 = znam1;
znam1 =tmp%znam1;
}
result.znam = this->znam / chis1;
result.chis = this->chis / chis1;
return result;
}
char Drob::Choose_Àrithmetics_Operation() //Âûáîð àðèôìåòè÷åñêîé îïåðàöèè
{
char operation;
cout << "Please choose operation:";
cin >> operation;
cout << endl;
return operation;
}
int Drob::Drob_Integer(Drob x)//How much Integer piece/Ñêîëüêî öåëûõ ÷àñòåé â äðîáè
{
int result;
result = this->chis / this->znam;
return result;
}
Drob Drob::Drob_Right(Drob x,int a)//Ïåðåâîä Äðîáè â ïðàâèëüíóþ Äðîáü
{
Drob result;
Drob result1;
result1.znam = x.znam;
result1.chis = x.znam * a;
result = x.Minus(result1);
result = result.Reduction(result);
return result;
}
bool Drob::Proverka_Na_Nol(Drob x)//Ïðîâåðÿåò åñòü ëè â äðîáè íîëü
{
if (x.chis == 0 or x.znam == 0)
return true;
else
return false;
}