-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOttenere-e-settare.cpp
More file actions
71 lines (47 loc) · 1.2 KB
/
Ottenere-e-settare.cpp
File metadata and controls
71 lines (47 loc) · 1.2 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
#include <iostream>
#include <string>
using namespace std;
// Get/set
// Link: https://youtu.be/1GdzmKdBf9s
// Title: Что такое геттеры и сеттеры для класса. Методы get и set. Инкапсуляция это. Пример. C++ Урок #76
// Creator: #SimpleCode
//
class Point
{
public:
int GetY ()
{
return y;
}
void SetY (int valueY)
{
y = valueY * 2;
}
int GetX ()
{
return x;
}
void SetX (int valueX) // non si può (per ora) utilizzare lo stesso paramentro
// come il nome della variabuile x = x non va bene!
{
x = valueX;
}
void Print ()
{
cout << "X = " << x << "\t Y = " << y << endl << endl;
}
private: // per limitare l'uso se verrà usato da qualcun altro programmatore
// puoi fare tutto ciò che io avevo previsto attraverso public:
int x;
int y;
};
int main() {
setlocale(LC_ALL, "italian");
Point a;
a.SetY(10); // possiamo stabilire dei valori alle varibili solo attraverso il set
a.SetX(5); // si stabilisce un valore alla variabile x di oggetto a
a.Print();
int result = a.GetX(); // con il get si ottiene il valore che è presente nella x
cout << result << endl;
return 0;
}