-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStructureInsideClass.cpp
45 lines (41 loc) · 1.34 KB
/
StructureInsideClass.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
/*
* project : https://github.com/Robin005cr/Professional_CPP
* file name : StructureInsideClass.cpp
* author : Robin CR
* mail id : [email protected]
* LinkedIn : https://www.linkedin.com/in/robin-cr/
* portfolio : https://robin005cr.github.io/
*
* Note : If any mistakes, errors, or inconsistencies are found in the code, please feel free to mail me.
* Suggestions for improvements or better methods are always welcome and appreciated.
* I value constructive feedback and aim to continuously improve the quality of the work.
*
*/
#include <iostream>
using namespace std;
class MyClass {
public:
struct MyStruct {
int x;
int y;
};
MyStruct myStruct; // creating a structure variable
// Method to set the values of the structure members
void setStructValues(int a, int b) {
myStruct.x = a;
myStruct.y = b;
}
// Method to display the values of the structure members
void displayStructValues() {
cout << "x: " << myStruct.x << ", y: " << myStruct.y << endl;
}
};
int main() {
MyClass obj; // Create an instance of the class
obj.setStructValues(5, 10); // Set values for the structure members
obj.displayStructValues(); // Display the values of the structure members
obj.myStruct.x = 15;
obj.myStruct.y = 10;
obj.displayStructValues();
return 0;
}