summaryrefslogtreecommitdiff
path: root/chapter4/str_demo.cxx
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-04-07 23:18:32 -0700
committerFuwn <[email protected]>2024-04-07 23:18:32 -0700
commitc1b6ffe70bd281c6c230fd63fabcaac2aff47514 (patch)
treee8af3b1782a7cd0754590ed618fddc1bdb9b7385 /chapter4/str_demo.cxx
downloaddscode-c1b6ffe70bd281c6c230fd63fabcaac2aff47514.tar.xz
dscode-c1b6ffe70bd281c6c230fd63fabcaac2aff47514.zip
feat: initial commitHEADmain
Diffstat (limited to 'chapter4/str_demo.cxx')
-rw-r--r--chapter4/str_demo.cxx39
1 files changed, 39 insertions, 0 deletions
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 <iostream> // Provides cout and cin
+#include <cstdlib> // Provides EXIT_SUCCESS
+#include "mystring.h" // Or use the Standard Library <string>
+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;
+}