aboutsummaryrefslogtreecommitdiff
path: root/12a/12a.cpp
diff options
context:
space:
mode:
Diffstat (limited to '12a/12a.cpp')
-rw-r--r--12a/12a.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/12a/12a.cpp b/12a/12a.cpp
new file mode 100644
index 0000000..c191b6b
--- /dev/null
+++ b/12a/12a.cpp
@@ -0,0 +1,88 @@
+// 12a.cpp : This file contains the 'main' function. Program execution begins and ends there.
+//
+
+#include <iostream>
+#include <string>
+#include "12a.h"
+
+using namespace std;
+
+#define ARRAY_SIZE 100
+
+void GetChoice(int& choice);
+
+void PrintList(string strs[ARRAY_SIZE], int& strct);
+
+void AddStr(string strs[ARRAY_SIZE], int& strct);
+
+int main()
+{
+ string strs[ARRAY_SIZE]{};
+ string substring;
+
+ int strct = 0, choice = 0;
+
+ while (choice != 3)
+ {
+ GetChoice(choice);
+ switch (choice)
+ {
+ case 1:
+ AddStr(strs, strct);
+ break;
+ case 2:
+ PrintList(strs, strct);
+ break;
+ case 3:
+ cout << "Exiting Program...";
+ break;
+ default:
+ cout << "Unknown choice: " << choice;
+ break;
+ }
+ }
+}
+
+void GetChoice(int& choice)
+{
+ string menu = "\t\t--String program--\n\
+\t1. Add a string\n\
+\t2. Print out string list\n\
+\t3. Exit Program\n\n\
+Input your choice: ";
+
+ cout << menu;
+ cin >> choice;
+
+ while (!cin)
+ {
+ cout << "Input was not an integer. Please try again." << endl;
+ cin.clear();
+ cin.ignore();
+ cout << menu;
+ cin >> choice;
+ }
+}
+
+void AddStr(string strs[ARRAY_SIZE], int& strct)
+{
+ string newstr;
+ cout << "Input a string: ";
+ cin.clear();
+ cin.ignore();
+ getline(cin, newstr);
+
+ strs[strct++] = newstr;
+
+ cout << newstr << " added to list.\n";
+}
+
+void PrintList(string strs[ARRAY_SIZE], int& strct)
+{
+ cout << "Outputing string list:" << endl;
+
+ for (int i = 0; i < strct; i++)
+ {
+ cout << strs[i] << endl;
+ }
+} \ No newline at end of file