-
Notifications
You must be signed in to change notification settings - Fork 3
/
1045_seminar05.cpp
102 lines (84 loc) · 1.84 KB
/
1045_seminar05.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
#include<iostream>
#include<string>
using namespace std;
class Telefon {
private:
const int cod;//nu este unic
static int tva;
string model;
int nrSenzori;
double * pretSenzori;
public:
Telefon():cod(0), nrSenzori(2) {
model = "Samsung";
pretSenzori = new double[nrSenzori];
pretSenzori[0] = 100;
pretSenzori[1] = 130;
}
Telefon(string model, int nrSenzori, double *pretSenzori,
int codNou) :cod(codNou) {
this->model = model;
this->nrSenzori = nrSenzori;
this->pretSenzori = new double[nrSenzori];
for (int i = 0; i < nrSenzori; i++) {
this->pretSenzori[i] = pretSenzori[i];
}
}
~Telefon() {
delete []pretSenzori;
}
string getModel() {
return model;
}
void setModel(string model) {
if (model.length() > 0) {
this->model = model;
}
}
void setNrSenzori(int nrSenzori, double *pretSenzori) {
this->nrSenzori = nrSenzori;
delete[] this->pretSenzori;
this->pretSenzori = new double[nrSenzori];
for (int i = 0; i < nrSenzori; i++) {
this->pretSenzori[i] = pretSenzori[i];
}
}
int getNrSenzori() {
return nrSenzori;
}
double* getPretSenzori() {
return pretSenzori;
}
double getPretSenzorPozitie(int index) {
if (index >= 0 && index < nrSenzori) {
return this->pretSenzori[index];
}
else {
throw "index incorect";
}
}
static int getTVA() {
return tva;
}
};
int Telefon::tva = 19;
void main() {
Telefon t;
cout << t.getModel()<<endl;
t.setModel("S9");
cout << t.getModel() << endl;
cout << t.getPretSenzorPozitie(0) << endl;
try {
cout << t.getPretSenzorPozitie(-1) << endl;
}
catch (int a) {
}
catch (const char* mesaj) {
cout << mesaj;
}
catch (...) {
cout << "Am intampinat o eroare";
}
cout << t.getTVA()<<endl;
cout << Telefon::getTVA() << endl;
}