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
|
#include <iostream>
#include <string>
enum Gender {Male, Female};
enum Capitalized {Capital, NonCapital};
struct Person {
std::string name;
Gender gender;
Person (const std::string& newName, Gender sex) : name (newName), gender (sex) {}
} *you;
std::string youHeShe (const Person* person, Capitalized capital = NonCapital) {
return (capital == NonCapital) ?
( (person == you) ? "you" : (person->gender == Male) ? "he" : "she" ) :
( (person == you) ? "You" : (person->gender == Male) ? "He" : "She" );
}
std::string isAre (const Person* person) {
return (person == you) ? "are" : "is";
}
std::string verb (const Person* person, const std::string& verb) {
return (person == you) ? verb : verb + "s";
}
int main() {
std::string yourName;
std::cout << "What is your name? ";
std::getline (std::cin, yourName);
you = new Person (yourName, Male);
Person *mary = new Person ("Mary", Female), *bob = new Person ("Bob", Male);
Person* people[] = {you, mary, bob};
for (const Person* x : people)
std::cout << youHeShe(x, Capital) << " (" << x->name << ") " << isAre(x) <<
" awesome because " << youHeShe(x) << " " << verb(x, "rock") << "!" << std::endl;
std::cin.get();
}
|