aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab7/CST116F2021-Lab7.cpp
blob: 2356ed07920d1df5d3f83174e6caa94e8dff7ca5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
CST 116 Austin Guertin
Module 7: Lab 7
  
  12a
  
  #include <iostream>
#include <string>

using namespace std;

//function to read input
void read(string str[], int idx)
{
	getline(cin, str[idx]);
}

int main()
{

	string str[100];
	int choice, size = 0;


	while (1)
	{
	
		cout << "\nPress 1: To add a string\n";
		cout << "Press 2: To print the strings\n";
		cout << "Press 3: Exit the program\n\n";
		cout << "Enter your choice down below: ";
		cin >> choice;

	
		if (choice == 1)
		{
			cin.ignore(80, '\n');
			cout << "\nEnter a string: ";
			read(str, size++);
		}


		else if (choice == 2)
			break;


		else if (choice == 3)
			return 0;
		else
			cout << "\n\nInvalid input!\n\n";
	}


	cout << endl << "The input strings are: \n\n";
	for (int i = 0; i < size; i++)
	{
		if (str[i] == "don't print")
			break;
		cout << str[i] << endl;
	}

	return 0;
}
  
  12b
  
  #include <iostream>
#include <string>

using namespace std;

void read(string str[], int idx)
{
	getline(cin, str[idx]);
}

int main()
{
	string str[100];
	int choice, choice2, size = 0;
	string FindS;

	while (1)
	{
		cout << "\nPress 1: To add a string\n";
		cout << "Press 2: To print the strings\n";
		cout << "Press 3: Exit the program\n\n";
		cout << "Enter your choice down below: ";
		cin >> choice;

		if (choice == 1)
		{
			cin.ignore(80, '\n');
			cout << "\nEnter a string: ";
			read(str, size++);
		}

		else if (choice == 2)
			break;

		else if (choice == 3)
			return 0;
		else
			cout << "\n\nInvalid input!\n\n";
	}

	cout << endl << "The input strings are: \n\n";
	for (int i = 0; i < size; i++)
	{
		if (str[i] == "don't print")
			break;
		cout << str[i] << endl;
	}

	cout << "Would you like to find a specific string or substring in this array? ('1' for yes or '2' for no)\n";
	cin >> choice2;

	if (choice2 == 1)
	{
		cout << "\nWhat is the word you want to look for?\n\n";
		cin >> FindS;

		for (int i = 0; i < size; i++)
		{
			size_t found = str[i].find(FindS);
			if (found != std::string::npos)
				cout << "\nThe word " << FindS << " starts at position: " << found + 1 << "\n\n";
		}

		return 0;
	}
}
  
  11c

	  #include <iostream>
#include <string>

using namespace std;

void read(string str[], int idx)
{
	getline(cin, str[idx]);
}

int main()
{
	string str[100];
	int choice, choice2, size = 0;
	string FindS;
	int EraseStart=0, EraseAmount=0;

	while (1)
	{
		cout << "\nPress 1: To add a string\n";
		cout << "Press 2: To print the strings\n";
		cout << "Press 3: Exit the program\n\n";
		cout << "Enter your choice down below: ";
		cin >> choice;

		if (choice == 1)
		{
			cin.ignore(80, '\n');
			cout << "\nEnter a string: ";
			read(str, size++);
		}

		else if (choice == 2)
			break;

		else if (choice == 3)
			return 0;
		else
			cout << "\n\nInvalid input!\n\n";
	}

	cout << endl << "The input strings are: \n\n";
	for (int i = 0; i < size; i++)
	{
		if (str[i] == "don't print")
			break;
		cout << str[i] << endl;
	}

	cout << "Would you like to find a specific string or substring in this array or delete a part of the string? ('1' for yes or '2' for delete or '3' for none)\n";
	cin >> choice2;

	if (choice2 == 1)
	{
		cout << "\nWhat is the word you want to look for?\n\n";
		cin >> FindS;

		for (int i = 0; i < size; i++)
		{
			size_t found = str[i].find(FindS);
			if (found != std::string::npos)
				cout << "\nThe word " << FindS << " starts at position: " << found + 1 << "\n\n";
		}

		return 0;
	}
	 if (choice2 == 2)
	{
		for (int i = 0; i < size; i++)
		{
			cout << "\nWhat's the starting position you want to start erasing?\n\n";
			cin >> EraseStart;

			cout << "\nWhat's the amount of characters you want to erase?\n\n";
			cin >> EraseAmount;

			str[i].erase(EraseStart + 1, EraseAmount + 1);
			cout << "\nYour new sentence is: " << str[i]<<"\n\n";
		}

	}
}