aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab6/LAB6Answers.txt
blob: 1e1c9903470cf5012b0bff1eabe654995d99b2e1 (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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
11a
10.10 Learn by Doing Exercises
pp 282-283
10 pts #1
Submit: code & runs



CODE:

// LAB6Ansari-V2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void acceptStringInfo(string array1[10][2]);
void acceptNumInfo(int studentNum[10], int moneyForClub[10], string array1[10][2]);
int main() {

	int x = 2;


	string clubInfo[10][2];
	int studentNum[10];
	int moneyForClub[10];

	acceptStringInfo(clubInfo);
	acceptNumInfo(studentNum, moneyForClub, clubInfo);

	cout << "CLUB : PRESIDENT : STUDENTS : BUDGET" << endl;
	for (int z = 0; z < 10; z++) {
	
		cout << clubInfo[z][0] << " : " << clubInfo[z][1] << " : " << studentNum[z] << " : " << moneyForClub[0] << endl;
	
	}


}

void acceptStringInfo(string array1[10][2]) {

	string club;
	string clubPresident;




	for (int i = 0; i < 10; i++) {


		cout << "Enter club name: ";
		getline(cin, club);
		cout << endl;
		array1[i][0] = club;

		cout << "Enter club president name: ";
		getline(cin, clubPresident);
		cout << endl;
		array1[i][1] = clubPresident;
		

	}

}


void acceptNumInfo(int studentNum[10], int moneyForClub[10], string array1[10][2]) {

	int members;
	
	for (int i = 0; i < 10; i++) {
		cout << "How many people are in the club " << array1[i][0] << ": ";
		cin >> members;
		cout << endl;
		studentNum[i] = members;
		moneyForClub[i] = members * 75;
	}

	

}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file



OUTPUT(corrected):

Enter club name: Computer Systems Society

Enter club president name: Kim Cares

Enter club name: Society of Women Engineers

Enter club president name: Jeanie Queen

Enter club name: Sigma Tau Gamma

Enter club president name: Storm Drain

Enter club name: Trekkies

Enter club president name: C.Kirk

Enter club name: Home Brewers

Enter club president name: Ross Coe

Enter club name: High Altitude ballooning

Enter club president name: Justin Time

Enter club name: Rugby

Enter club president name: Ryan Johns

Enter club name: IEEE

Enter club president name: Marc Bansmere

Enter club name: International Club

Enter club president name: Kong Mbonkum

Enter club name: Dance Club

Enter club president name: Will Shaver

How many people are in the club Computer Systems Society: 49

How many people are in the club Society of Women Engineers: 51

How many people are in the club Sigma Tau Gamma: 241

How many people are in the club Trekkies: 230

How many people are in the club Home Brewers: 15

How many people are in the club High Altitude ballooning: 19

How many people are in the club Rugby: 25

How many people are in the club IEEE: 36

How many people are in the club International Club: 102

How many people are in the club Dance Club: 64

CLUB : PRESIDENT : STUDENTS : BUDGET
Computer Systems Society : Kim Cares : 49 : 3675
Society of Women Engineers : Jeanie Queen : 51 : 3675
Sigma Tau Gamma : Storm Drain : 241 : 3675
Trekkies : C.Kirk : 230 : 3675
Home Brewers : Ross Coe : 15 : 3675
High Altitude ballooning : Justin Time : 19 : 3675
Rugby : Ryan Johns : 25 : 3675
IEEE : Marc Bansmere : 36 : 3675
International Club : Kong Mbonkum : 102 : 3675
Dance Club : Will Shaver : 64 : 3675

C:\Users\ansar\Source\Repos\cst116-lab6-rayyanansari03-V1\Debug\CST116F2021-Lab6.exe (process 16860) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

-----------------------------------------------------------------------------------------------------------

11b
10.14 Debugging Exercises
pp 289-292
10 pts #1
Submit: code & runs

NOTE: The instruction on the debugging exercise were quite vague so i followed them to the best of my abilities. For example, 
they ask to modify a value in function 2, but they do not specify whether that value should be altered in the beginning
or end of the function.

DEBUGGED CODE:

#include <iostream>
#include <iomanip>
using std::cin;
using std::cout;
using std::endl;
using std::setw;

void GetAndDisplayWelcomeInfo();
void FunctionOne(int varX[], int varY[]);
void FunctionTwo(int varX[], const int varY[], int varZ[]);
void PrintFunction(const int varX[], const int varY[],
    const int varZ[]);

const int SIZE = 10;

int main()
{
    int varX[SIZE];
    int varY[SIZE];
    int varZ[SIZE];	// Notice how we used the const here!

// Breakpoint 1
    // Put breakpoint on the following line 
    GetAndDisplayWelcomeInfo();
    FunctionOne(varX, varY);

    // Breakpoint 3
        // Put breakpoint on the following line 
    FunctionTwo(varX, varY, varZ);
    varZ[0] = -99;
    PrintFunction(varX, varY, varZ);

    return 0;
}
void GetAndDisplayWelcomeInfo()
{
    char name[2][20]; // First name in row 0, last name in row 1

    cout << "Please enter your first name: ";
    cin >> name[0];

    cout << "\nPlease enter your last name: ";
    cin >> name[1];

    // Breakpoint 2
    // Put breakpoint on the following line 
    cout << "\n\n\tWelcome " << name[0] << " " << name[1]
        << "!\n\t   Hope all is well \n\n";
}
void FunctionOne(int varX[], int varY[])
{
    for (int x = 0; x < SIZE; x++)	// NOTICE '<' NOT <= 
        // Breakpoint 4
        // Put breakpoint on the following line 
        varX[x] = x;

    for (int x = 0; x < 5; x++)
        varY[x] = x + 100;
}
void FunctionTwo(int varX[], const int varY[], int varZ[])
{
    varX[1] = 99;
    for (int x = 0; x < SIZE; x++) // Notice the const SIZE here
        varZ[x] = varX[x] + varY[x];
    
}
void PrintFunction(const int varX[20], const int varY[20],
    const int varZ[20])
{
    int x;

    cout << " \t  x \t  y  \t  z\n\n";

    for (x = 0; x < SIZE; x++)
        cout << "\t" << setw(3) << varX[x]
        << "\t " << varY[x]
        << "\t " << varZ[x] << endl;
}

OUTPUT:

Please enter your first name: Rayyan

Please enter your last name: Ansari


        Welcome Rayyan Ansari!
           Hope all is well

          x       y       z

          0      100     -99
         99      101     200
          2      102     104
          3      103     106
          4      104     108
          5      -858993460      -858993455
          6      -858993460      -858993454
          7      -858993460      -858993453
          8      -858993460      -858993452
          9      -858993460      -858993451

C:\Users\ansar\Source\Repos\cst116-lab6-rayyanansari03-V1\Debug\CST116F2021-Lab6.exe (process 2208) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .


---------------------------------------------------------------

11c
10.15 Programming Exercises
pp 292-293
10 pts #1
Submit: code & runs


CODE:

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;
bool isPalindrome(char str[100]);
bool isAlphaStr(char str[100]);
int countChar(char str[100], char character);

int main() {

	char str1[100];
	char str2[100];
	char str3[100];
	char repeatedletter;

	cout << "Enter word that you would like to count repeated character of: ";
	cin >> str3;
	cout << endl;
	cout << "Enter letter you would like to find: ";
	cin >> repeatedletter;
	cout << endl;
	cout << countChar(str3, repeatedletter);

	cout << endl;

	cout << "ENter word where you want all alphabet: ";
	cin >> str2;
	cout << endl;

	if (isAlphaStr(str2) == true) {
		
		cout << "TRUE";
	
	}

	else {
	
	
		cout << "FALSE";
	
	}

	cout << endl;
	
	
	cout << "Enter Palindrome word: ";
	cin >> str1;

	if (isPalindrome(str1)) {

		cout << "true" << endl;

	}
	else {

		cout << "false" << endl;

	}

	
}


bool isPalindrome(char str[100]) {

	char tempString[100];
	bool condition = true;

	int j = strlen(str) - 1;

	for (int i = 0; i < strlen(str); i++) {
		
		if (str[i] != str[j]) {
		
			condition = false;
		
		}

		j--;
		
	
	}

	return condition;

	
}


bool isAlphaStr(char str[100]) {

	for (int i = 0; i < strlen(str); i++) {
	
		if (!isalpha(str[i])) {
		
			return false;
		
		}
	
	}

	return true;


}


int countChar(char str[100], char character) {

	int amount = 0;
	for (int i = 0; i < strlen(str); i++) {
	
		if (str[i] == character) {
		
			amount++;
		
		}
		
	
	}

	return amount;


}


OUTPUT(1):

Enter word that you would like to count repeated character of: Hellooooo

Enter letter you would like to find: o

5
ENter word where you want all alphabet: hjkdfsn0

FALSE
Enter Palindrome word: referr
false

C:\Users\ansar\Source\Repos\cst116-lab6-rayyanansari03-V1\Debug\CST116F2021-Lab6.exe (process 19652) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .


OUTPUT(2):


Enter word that you would like to count repeated character of: hheeellloooom

Enter letter you would like to find: m

1
ENter word where you want all alphabet: Hello

TRUE
Enter Palindrome word: refer
true

C:\Users\ansar\Source\Repos\cst116-lab6-rayyanansari03-V1\Debug\CST116F2021-Lab6.exe (process 14748) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .