-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOop.cpp
More file actions
41 lines (35 loc) · 961 Bytes
/
Oop.cpp
File metadata and controls
41 lines (35 loc) · 961 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
#include <iostream>
class Human {
public:
// Default values
std::string name = "Unknown";
int age = 0;
bool isAlive = false;
void printInfo() {
std::cout << "Name: " << name << std::endl;
std::cout << "Age: " << age << std::endl;
std::cout << "Alive: " << isAlive << std::endl;
std::cout << "--------------------------------" << std::endl;
}
void setName(std::string name) {
this->name = name;
}
void setAge(int age) {
this->age = age;
}
void setAlive(bool isAlive = false) {
this->isAlive = isAlive;
}
};
int main() {
Human human1 = { "Rick", 70, true };
human1.printInfo();
Human human2;
human2.setName("Morty");
human2.setAge(14);
human2.setAlive(false);
human2.printInfo();
Human human3;
human3.printInfo();
return 0;
}