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
24 lines (20 loc) · 681 Bytes
/
ex6_42.cpp
File metadata and controls
24 lines (20 loc) · 681 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
//! @Yue Wang
//!
//! Exercise 6.42:
//! 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") << " " << make_plural(1, "failure") << endl;
cout << "plural : " << make_plural(2, "success") << " " << make_plural(2, "failure") << endl;
return 0;
}