Mode:
Duration:
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
#include <iostream>
#include <vector>
#include <string>
class Person {
private:
std::string name;
int age;
public:
Person(const std::string& name, int age)
: name(name), age(age) {}
void introduce() const {
std::cout << "Hi, I'm " << name << " and I'm " << age << " years old." << std::endl;
}
int getAge() const { return age; }
};
int main() {
std::vector<Person> people = { Person("Alice", 25), Person("Bob", 30) };
for (const auto& person : people) {
person.introduce();
}
return 0;
}Coding works best on desktop or with an external keyboard.