Getting proper grammer

Does someone know of a better way to get proper grammer in sentences than this method of mine? I don't want to continue with this for my entire huge program if there is a much more elegant way.
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();
}

Output:
1
2
3
4
What is your name? John Doe
You (John Doe) are awesome because you rock!
She (Mary) is awesome because she rocks!
He (Bob) is awesome because he rocks!


Any better way than using a bunch of if-statements like I'm doing?
Last edited on
Something along the lines of
1
2
3
4
5
6
7
8
9
10
11
12
class Pronoun {
	// ???
} You, HeShe;

// other grammatical classes

template <typename... ARGS>
struct sentence {
	std::string operator()(Person* person, const ARGS&... args) {  // recursive step
		// ???
	}
};

so that Person* needs only be called once, or would that be of no greater benefit?
Last edited on
Topic archived. No new replies allowed.