aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Taormina <[email protected]>2021-11-11 19:47:30 -0800
committerTyler Taormina <[email protected]>2021-11-11 19:47:30 -0800
commitdea1e384f6b8cb52bccc6297c33a0ad70c110832 (patch)
tree0ecce326fa3d264b8a5779836ec83441b54d9369
parentAdding lab7.txt to origin (diff)
downloadcst116-lab7-till-t-dea1e384f6b8cb52bccc6297c33a0ad70c110832.tar.xz
cst116-lab7-till-t-dea1e384f6b8cb52bccc6297c33a0ad70c110832.zip
Problem 1 complete.
Nov 11, 2021
-rw-r--r--lab7.txt150
-rw-r--r--num1.cpp79
2 files changed, 228 insertions, 1 deletions
diff --git a/lab7.txt b/lab7.txt
index 76ccd84..d454d92 100644
--- a/lab7.txt
+++ b/lab7.txt
@@ -1,30 +1,178 @@
CST116
Module 7: Lab 7
12a
+
Write a program that includes a function to read (at least 100) strings into an array. Allow the
user to either add a string or print out the contents of the array. Be sure to stop “printing” at the
end of the entered values -- don’t “print” after the end of the user’s entered data. Be sure to give
the user the chance to leave the program.
+
10 pts
Submit: code & runs
+
+CODE:
+
+// Tyler Taormina
+// CST 116
+// Lab 7
+// Number 1
+
+#include <iostream>
+#include <iomanip>
+#include <string>
+
+using namespace std;
+
+void GatherStrings();
+void getString();
+void ClearBuffer();
+#define MAX 100
+
+
+int main()
+{
+ // program driver
+ GatherStrings();
+
+ return 0;
+}
+
+
+void GatherStrings()
+{
+ // Ask user for input of a string. Let user decide after each
+ // input whether or not they will add another string. Once
+ // they choose to not input, all previously entered strings
+ // will be printed.
+
+ string usr_data;
+ string array[MAX];
+
+ int i = 0;
+ int limit = 0;
+ int flag = 1;
+
+ while (flag && limit < MAX)
+ {
+ cout << setw(10) << left << "Please Enter a string to store in our database: ";
+ getline (cin, usr_data);
+ array[limit] = usr_data;
+ limit += 1;
+ cout << "\n\nEnter 1 to add another string to the data base." << endl;
+ cout << "OR" << endl;
+ cout << "Enter 0 to stop and see all the entries we have so far: ";
+ cin >> flag;
+ ClearBuffer();
+ }
+
+ cout << "\n\nThis is what we have in our database so far...\n\n" << endl;
+
+ while (i < limit)
+ {
+ cout << array[i] << endl;
+ i += 1;
+ }
+}
+
+
+void ClearBuffer()
+{
+ // clears buffer after menu choice so as not to interfere with the following user inputs.
+ char c;
+ do {
+ c = getchar();
+ } while (c != '\n' && c != EOF);
+}
+
+
+
+RUN:
+
+Please Enter a string to store in our database: string 1
+
+
+Enter 1 to add another string to the data base.
+OR
+Enter 0 to stop and see all the entries we have so far: 1
+Please Enter a string to store in our database: string 2
+
+
+Enter 1 to add another string to the data base.
+OR
+Enter 0 to stop and see all the entries we have so far: 1
+Please Enter a string to store in our database: this is sting 3
+
+
+Enter 1 to add another string to the data base.
+OR
+Enter 0 to stop and see all the entries we have so f 1 u Please Enter a string to store in our database: How many more times should I do this?
+
+
+Enter 1 to add another string to the data base.
+OR
+Enter 0 to stop and see all the entries we have so far: 1
+Please Enter a string to store in our database: Ill do 2 more
+
+
+Enter 1 to add another string to the data base.
+OR
+Enter 0 to stop and see all the entries we have so far: 1
+Please Enter a string to store in our database: One moreE!
+
+
+Enter 1 to add another string to the data base.
+OR
+Enter 0 to stop and see all the entries we have so far: 1
+Please Enter a string to store in our database: I'm done!
+
+
+Enter 1 to add another string to the data base.
+OR
+Enter 0 to stop and see all the entries we have so far: 0
+
+
+This is what we have in our database so far...
+
+
+string 1
+string 2
+this is sting 3
+How many more times should I do this?
+Ill do 2 more
+One moreE!
+I'm done!
+
+
===============================================================================
12b
+
Add to your program from part 12a:
An option in a function that can find a string or substring in a string in the array. This need just
be the first occurrence of the string or substring.
+
10 pts
Submit: code & runs
-===============================================================================
+CODE:
+
+RUN:
+
+==============================================================================
11c
+
Add to your program from part 12b:
An option in a function that can remove a string from the array (and compress the array) based
on its location in the array. Make sure that the “print” option reflects the removed string.
+
10 pts
Submit: code & runs
Total: 30 pts
+CODE:
+
+RUN:
+
diff --git a/num1.cpp b/num1.cpp
new file mode 100644
index 0000000..a74d007
--- /dev/null
+++ b/num1.cpp
@@ -0,0 +1,79 @@
+// Tyler Taormina
+// CST 116
+// Lab 7
+// Number 1
+
+#include <iostream>
+#include <iomanip>
+#include <string>
+
+using namespace std;
+
+void GatherStrings();
+void getString();
+void ClearBuffer();
+#define MAX 100
+
+
+int main()
+{
+ // program driver
+ GatherStrings();
+
+ return 0;
+}
+
+
+void GatherStrings()
+{
+ // Ask user for input of a string. Let user decide after each
+ // input whether or not they will add another string. Once
+ // they choose to not input, all previously entered strings
+ // will be printed.
+
+ string usr_data;
+ string array[MAX];
+
+ int i = 0;
+ int limit = 0;
+ int flag = 1;
+
+ while (flag && limit < MAX)
+ {
+ cout << setw(10) << left << "Please Enter a string to store in our database: ";
+ getline (cin, usr_data);
+ array[limit] = usr_data;
+ limit += 1;
+ cout << "\n\nEnter 1 to add another string to the data base." << endl;
+ cout << "OR" << endl;
+ cout << "Enter 0 to stop and see all the entries we have so far: ";
+ cin >> flag;
+ ClearBuffer();
+ }
+
+ cout << "\n\nThis is what we have in our database so far...\n\n" << endl;
+
+ while (i < limit)
+ {
+ cout << array[i] << endl;
+ i += 1;
+ }
+}
+
+
+void ClearBuffer()
+{
+ // clears buffer after menu choice so as not to interfere with the following user inputs.
+ char c;
+ do {
+ c = getchar();
+ } while (c != '\n' && c != EOF);
+}
+
+
+
+
+
+
+
+