Respuesta :
Answer:
// Program in C++
#include <iostream>
using namespace std;
class PersonInfo {
private:
int numKids;
public:
void setNumKids(int personsKids) {
numKids = personsKids;
return;
}
void incNumKids() {
numKids = numKids + 1;
return;
}
int getNumKids() {
return numKids;
}
};
int main() {
PersonInfo person1;
person1.setNumKids(3);
cout << "Kids: " << person1.getNumKids() << endl;
person1.incNumKids();
cout << "New baby, kids now: " << person1.getNumKids() << endl;
return 0;
}
Explanation:
- Inside the main function, create an object of the PersonInfo class.
- Call the setNumKids method with the help of person1 object and pass 3 as an argument.
- Display the current number of kids using the getNumKids method.
- Increment the number of kids by calling the incNumKids method.
- Finally print the updated number of kids by calling the getNumKids method again.
Output:
Kids: 3
New baby, kids now: 4