This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timp.cpp
126 lines (126 loc) · 2.02 KB
/
timp.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
121
122
123
124
125
126
#include "timp.h"
timp::timp()
{
ora = 0;
minut = 0;
flag = false;
}
timp::timp(int ora) : timp()
{
if (ora > -1 && ora < 24)
this->ora = ora;
else
flag = true;
}
timp::timp(int ora, int minut) : timp(ora)
{
if (minut > -1 && minut < 60)
this->minut = minut;
else
flag = true;
}
timp::timp(const timp& t)
{
ora = t.ora;
minut = t.minut;
flag = t.flag;
}
timp& timp::operator=(const timp& t)
{
if (this != &t)
{
ora = t.ora;
minut = t.minut;
flag = t.flag;
}
return *this;
}
ostream& operator<<(ostream& out, timp t)
{
if (t.flag == false)
{
if (t.ora < 10)
out << "0";
out << t.ora << ":";
if (t.minut < 10)
out << "0";
out << t.minut;
}
else
out << "Timpul nu este valid";
return out;
}
istream& operator>>(istream& in, timp& t)
{
cout << "Ora: ";
in >> t.ora;
while (t.verificaOra() == false)
{
cout << "Ora nu este valida. Introduceti o ora valida: ";
in >> t.ora;
}
cout << "Minut: ";
while (t.verificaMinut() == false)
{
cout << "Minutul nu este valid. Introduceti un minut valid: ";
in >> t.minut;
}
in >> t.minut;
t.verificaTimp();
return in;
}
timp& timp::operator-(const timp& t)
{
timp* rezultat = new timp();
if (this->flag == false && t.flag == false)
{
rezultat->minut = this->minut - t.minut;
if (rezultat->minut < 0)
{
rezultat->minut = 60 + rezultat->minut;
rezultat->ora--;
}
rezultat->ora += (this->ora - t.ora);
if (rezultat->ora < 0)
rezultat->ora = 24 + rezultat->ora;
}
else
rezultat->flag = true;
return *rezultat;
}
bool timp::operator<=(const timp& t)
{
if (this->flag == false && t.flag == false)
{
if (this->ora < t.ora)
return true;
else if (this->ora == t.ora)
if (this->minut <= t.minut)
return true;
}
return false;
}
bool timp::getFlag()
{
return flag;
}
bool timp::verificaOra()
{
if (ora > -1 && ora < 24)
return true;
else
return false;
}
bool timp::verificaMinut()
{
if (minut > -1 && minut < 60)
return true;
else
return false;
}
bool timp::verificaTimp()
{
if (flag)
return false;
return true;
}