Skip to content

Commit

Permalink
Update ex6_42.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooophy authored and pezy committed Jun 24, 2015
1 parent 5b3cd0a commit 4bc1138
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ch06/ex6_42.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
//! @Alan
//! @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;
cout << "singual: " << make_plural(1, "success") << " " << make_plural(1, "failure") << endl;
cout << "plural : " << make_plural(2, "success") << " " << make_plural(2, "failure") << endl;

return 0;
}

0 comments on commit 4bc1138

Please sign in to comment.