Parental care

#include <iostream> #include <vector> #include <iomanip> using namespace std; class Child { public: string name; int age; bool cries; bool laughs; bool looks_interested; bool wonders; bool crawls; bool sleeps; double sleep_duration_hours; bool plays_with_toys; bool is_naughty; bool is_tired; bool is_ill; bool is_hungry; bool is_dirty; bool has_fever; bool needs_fresh_air; Child(string name, int age): name(name), age(age), cries(false), laughs(false), looks_interested(false), wonders(false), crawls(false), sleeps(false), plays_with_toys(false), is_naughty(false), is_tired(false), is_ill(false), is_dirty(false), has_fever(false), needs_fresh_air(false) {}; void show_info() { cout << boolalpha << "Cries: " << cries << endl << "Laughs: " << laughs << endl << "Looks interested: " << looks_interested << endl << "Wonders: " << wonders << endl << "Crawls: " << crawls << endl << "Sleeps: " << sleeps << endl << "Plays with toys: " << plays_with_toys << endl << "Is naughty: " << is_naughty << endl << "Is tired: " << is_tired << endl << "Is ill: " << is_ill << endl << "Is dirty: " << is_dirty << endl << "Has fever: " << has_fever << endl << "Needs fresh air: " << needs_fresh_air << endl; } }; class Parent { private: string name; public: Parent(string name) : name(name) {}; void wash(Child& child) {child.is_dirty = false;}; void walk_outside(Child& child) {child.needs_fresh_air = false;} void entertain(Child& child) {child.laughs = true;} void put_to_sleep(Child& child) {child.sleeps = true;} void smile_at(Child& child) {child.laughs = true;} void read_to(Child& child) {child.looks_interested = false;} void play_some_music(Child& child) {child.cries = false;} void show_kid_movie(Child& child) {child.cries = false; child.looks_interested = true;} void give_toy_to(Child& child) {child.plays_with_toys = true; child.laughs = true;} void lower_temperature(Child& child) {child.has_fever = false;} void explain_whats_right(Child& child) {child.is_naughty = false;} void surprise(Child& child) {child.wonders = false;} void feed(Child& child) {child.is_hungry = false;} void wake_up(Child& child) {child.sleeps = false;} void give_colouring_book(Child& child) {child.plays_with_toys = false;} void bring_to_doctor(Child& child) {child.is_ill = false;} }; int main() { Child johanna("Johanna", 2), peter("Peter", 3), dennis("Dennis", 4); Parent parent("Jennifer"); // State before parent actions johanna.is_dirty = true; johanna.laughs = true; johanna.crawls = true; johanna.needs_fresh_air = true; johanna.is_naughty = true; peter.looks_interested = false; peter.wonders = true; dennis.is_tired = true; dennis.has_fever = true; dennis.cries = true; dennis.is_hungry = true; vector<Child> children = {peter, dennis, johanna}; // The parent determines actions on a per-case basis based on the child's needs for(Child child : children) { if(child.is_ill) {parent.bring_to_doctor(child);} else { if(child.cries) { if(!child.looks_interested) {parent.show_kid_movie(child);} else {parent.play_some_music(child);} } if(!child.laughs) {parent.entertain(child);} if(!child.looks_interested && child.wonders) { if(!child.is_tired) {parent.read_to(child);} else {parent.surprise(child);} } if(child.is_dirty) {parent.wash(child);} if(child.needs_fresh_air) {parent.walk_outside(child);} if(child.is_tired) {parent.put_to_sleep(child);} if(child.has_fever) {parent.lower_temperature(child);} if(child.is_naughty) {parent.explain_whats_right(child); parent.smile_at(child);} if(child.plays_with_toys) {parent.give_colouring_book(child);} if(child.is_hungry) {parent.feed(child);} if(child.sleeps && child.sleep_duration_hours > 8 && !child.is_tired) {parent.wake_up(child);} } cout << child.name << endl; child.show_info(); cout << endl; } // State after parent actions /* Peter Cries: false Laughs: true Looks interested: false Wonders: true Crawls: false Sleeps: false Plays with toys: false Is naughty: false Is tired: false Is ill: false Is dirty: false Has fever: false Needs fresh air: false Dennis Cries: false Laughs: true Looks interested: true Wonders: false Crawls: false Sleeps: true Plays with toys: false Is naughty: false Is tired: true Is ill: false Is dirty: false Has fever: false Needs fresh air: false Johanna Cries: false Laughs: true Looks interested: false Wonders: false Crawls: true Sleeps: false Plays with toys: false Is naughty: false Is tired: false Is ill: false Is dirty: false Has fever: false Needs fresh air: false */ return 0; }