forked from yogykwan/cpp-primer-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex6_42.cpp
32 lines (27 loc) · 769 Bytes
/
ex6_42.cpp
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
//! @creator by Wang Yue
//! @refactor by pezy
//!
//! @date 27, July. 2015
//!
//! @question
//! Give the second parameter of make_plural (§ 6.3.2, p. 224) a default
//! argument of 's'. Test your program by printing singular and plural versions
//! of the words success and failure.
//!
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::endl;
string make_plural(size_t ctr, const string& word, const string& ending = "s")
{
return (ctr > 1) ? word + ending : word;
}
int main()
{
cout << "singual: " << make_plural(1, "success", "es") << " "
<< make_plural(1, "failure") << endl;
cout << "plural : " << make_plural(2, "success", "es") << " "
<< make_plural(2, "failure") << endl;
return 0;
}