-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexam 04.cpp
More file actions
42 lines (33 loc) · 965 Bytes
/
exam 04.cpp
File metadata and controls
42 lines (33 loc) · 965 Bytes
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
#include <iostream>
class Tree {
public:
// Constructor
Tree(int w, int h) : width(w), height(h) {
std::cout << "Tree object created with width " << width << " and height " << height << std::endl;
}
// Destructor
~Tree() {
std::cout << "Tree object destroyed" << std::endl;
}
// Set function to take input
void setValues(int w, int h) {
width = w;
height = h;
}
// Display function to show values
void display() {
std::cout << "Tree width: " << width << ", height: " << height << std::endl;
}
private:
int width;
int height;
};
int main() {
// Creating an object of Tree class using constructor
Tree myTree(10, 20);
// Using the setValues function to change the object's attributes
myTree.setValues(15, 25);
// Displaying the values using the display function
myTree.display();
return 0;
}