From c1b6ffe70bd281c6c230fd63fabcaac2aff47514 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 7 Apr 2024 23:18:32 -0700 Subject: feat: initial commit --- chapter4/str_demo.cxx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 chapter4/str_demo.cxx (limited to 'chapter4/str_demo.cxx') diff --git a/chapter4/str_demo.cxx b/chapter4/str_demo.cxx new file mode 100644 index 0000000..df7877e --- /dev/null +++ b/chapter4/str_demo.cxx @@ -0,0 +1,39 @@ +// FILE: str_demo.cxx +// This is a small demonstration program showing how the string class is used. +#include // Provides cout and cin +#include // Provides EXIT_SUCCESS +#include "mystring.h" // Or use the Standard Library +using namespace std; +using namespace main_savitch_4; + +// PROTOTYPES for functions used by this demonstration program: +void match(const string& variety, const string& mine, const string& yours); +// The two strings, mine and yours, are compared. If they are the same, then a +// message is printed saying they are the same; otherwise mine is printed +// in a message. In either case, the string variety is part of the message. + +int main( ) +{ + const string BLANK(" "); + string me_first("Demo"), me_last("Program"); + string you_first, you_last, you; + + cout << "What is your first name? "; + cin >> you_first; + match("first name", me_first, you_first); + cout << "What is your last name? "; + cin >> you_last; + match("last name", me_last, you_last); + + you = you_first + BLANK + you_last; + cout << "I am happy to meet you, " << you << "." << endl; + return EXIT_SUCCESS; +} + +void match(const string& variety, const string& mine, const string& yours) +{ + if (mine == yours) + cout << "That is the same as my " << variety << "!" << endl; + else + cout << "My " << variety << " is " << mine << "." << endl; +} -- cgit v1.2.3