forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex6_42.cpp
33 lines (26 loc) · 813 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
33
//! @Alan
//!
//! 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>
#include <vector>
#include <iterator>
using namespace std;
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;
}