forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex6_42.cpp
More file actions
32 lines (27 loc) · 759 Bytes
/
ex6_42.cpp
File metadata and controls
32 lines (27 loc) · 759 Bytes
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;
}