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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
Module 6: Lab 6
Tyler Taormina
CST 116
_______________________________________________________________________________
11a
10.10 Learn By Doing
pg 282-283
#1 for 10pts
CODE:
/*Tyler Taormina
*Module 11a
*Matrix Practice
*/
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
#define ARRAY_SIZE 10
int readData(int[ARRAY_SIZE][2], string[ARRAY_SIZE][2]);
void printData(int[ARRAY_SIZE][2], string[ARRAY_SIZE][2], int[ARRAY_SIZE], int);
void calcData(int[ARRAY_SIZE][2], int[ARRAY_SIZE]);
int main()
{
int COUNTER;
int award[ARRAY_SIZE];
int id_numStu[ARRAY_SIZE][2];
string pres_club[ARRAY_SIZE][2];
COUNTER = readData(id_numStu, pres_club);
calcData(id_numStu, award);
printData(id_numStu, pres_club, award, COUNTER);
}
void printData(int intData[ARRAY_SIZE][2], string stringData[ARRAY_SIZE][2], int awardData[ARRAY_SIZE], int ctr)
{
cout << setw(20) << left << "Student Club" << left << setw(20) << "President" << setw(20) << left << "Number of Students" << setw(20) << left << "Award" << endl;
// Headings for the columns ^^
cout << "=============================================================================" << endl;
for (int i = 0; i < ctr; i++)
{
for (int j = 0; j < 1; j++)
{
cout << setw(20) << left << stringData[i][j] << setw(20) << left << stringData[i][j+1] << setw(20) << left << intData[i][j+1] << setw(20) << left << awardData[i] << endl;
}
}
}
int readData(int intData[ARRAY_SIZE][2], string stringData[ARRAY_SIZE][2])
{
int again = 1, i = 0, num_stu = 0, counter = 0;
while (again && i < ARRAY_SIZE)
{
cout << "Enter the ID (0 to exit): ";
cin >> again;
if (again)
{
intData[i][0] = again;
cout << "Enter the name of the club: ";
getline( cin >> ws, stringData[i][0]);
cout << "Enter the President of the club: ";
getline( cin >> ws, stringData[i][1]);
cout << "Enter the number of students in the club: ";
cin >> num_stu;
intData[i][1] = num_stu;
cout << endl;
i++;
counter++;
}
}
cout << endl;
return counter;
}
void calcData(int intData[ARRAY_SIZE][2], int awardData[ARRAY_SIZE])
{
int award = 75;
int i;
for (i = 0; i < ARRAY_SIZE; i++)
{
awardData[i] = intData[i][1] * award;
}
}
RUN:
Enter the ID (0 to exit): 1
Enter the name of the club: Weenies
Enter the President of the club: Oliver
Enter the number of students in the club: 2
Enter the ID (0 to exit): 2
Enter the name of the club: Huskies
Enter the President of the club: Koda
Enter the number of students in the club: 3
Enter the ID (0 to exit): 3
Enter the name of the club: Ping Pong
Enter the President of the club: Tyler
Enter the number of students in the club: 1
Enter the ID (0 to exit): 4
Enter the name of the club: Video
Enter the President of the club: Mike
Enter the number of students in the club: 20
Enter the ID (0 to exit): 5
Enter the name of the club: Photo
Enter the President of the club: Sun
Enter the number of students in the club: 2
Enter the ID (0 to exit): 0
Student Club President Number of Students Award
=============================================================================
Weenies Oliver 2 150
Huskies Koda 3 225
Ping Pong Tyler 1 75
Video Mike 20 1500
Photo Sun 2 150
_______________________________________________________________________________
11b 10.14 Debugging Exercises
pg 289-292
#1 for 10pts
CODE:
// Tyler Taormina
// CST 116
// Module 11B Debugging Exercise
// pg 289-292
// #1 for 10pts
#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 < SIZE; x++ )
varY[x] = x + 100;
}
void FunctionTwo (int varX[], const int varY[], int varZ[] )
{
for ( int x = 0; x < SIZE; x++ ) // Notice the const SIZE here
varZ[x] = varX[x] + varY[x];
varX[1] = 99;
}
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;
}
RUN:
Please enter your first name: tyler
Please enter your last name: taormina
Welcome tyler taormina!
Hope all is well
x y z
0 100 -99
99 101 102
2 102 104
3 103 106
4 104 108
5 105 110
6 106 112
7 107 114
8 108 116
9 109 118
_______________________________________________________________________________
11c
10.15 Programming Exercises
pg 292-293
#1 for 10pts
CODE:
// Tyler Taormina
// CST 116
// Module 11c
//
#include <iostream>
#include <cstring>
#include <string>
#define MAX 50
using namespace std;
void isPalindrome();
void isAlpha();
void countChar();
void DisplayMenu(int&);
void ProcessMenuChoice(int);
int main() {
//main call to project.
int user_choice;
cout << "=================================================================" << endl;
cout << "PROGRAM RUNNING.." << endl;
cout << "=================================================================" << endl;
cout << endl;
DisplayMenu(user_choice);
ProcessMenuChoice(user_choice);
return 0;
}
void DisplayMenu(int& user_choice)
{
// displays a selection of choices for the user to pick from.
// updates user_choice by reference.
cout << "Choose what you would like to check for in a word" << endl;
cout << "that you will enter..." << endl;
cout << "=================================================================" << endl;
//displays the menu of functions for the user to choose from
cout << "1) Check for palindrome.\n";
cout << "2) Check for all alpha.\n";
cout << "3) Count the number of times a letter is in a word.\n";
cout << "4) Exit Program.\n\n";
cout << "Enter: ";
cin >> user_choice;
if (user_choice > 4 || user_choice< 1) {
cout << "Invalid Entry. Please enter a number from the options list provided.\n\n\n\n" << endl;
DisplayMenu(user_choice);
}
}
void ProcessMenuChoice (int menu_choice) {
// Uses the user menu choice input to determine which function to call.
// Also controls the ending or restarting of program.
int program_rerun = 0;
switch(menu_choice){
case 1:
isPalindrome();
break;
case 2:
isAlpha();
break;
case 3:
countChar();
break;
case 4:
cout << "Are you sure you want to exit? Enter any number other than 1 to end program." << endl;
break;
default:
break;
}
cout << "Press 1 and enter to rerun program. Enter any other number to close program: ";
cin >> program_rerun;
if (program_rerun == 1)
main();
else {
cout << "================================================================" << endl;
cout << "Program Closing..." << endl;
cout << "================================================================\n\n\n" << endl;
}
}
void isPalindrome ()
{
// checks a word to see if the reverse spelling is the same as the
// normal spelling. For example 'lol' reversed would be 'lol'. 'pop'
// reversed would be 'pop'.
char string1[MAX];
int i, length;
int flag = 0;
cout << "Enter a string: "; cin >> string1;
length = strlen(string1);
for(i=0;i < length ;i++){
if(string1[i] != string1[length-i-1]){
flag = 1;
break;
}
}
if (flag) {
cout << string1 << " is not a palindrome" << endl;
}
else {
cout << string1 << " is a palindrome" << endl;
}
}
void isAlpha ()
{
//checks to make sure that the only characters in the string are
// either numbers or letters.
char str[MAX];
int i;
cout << "Enter a string to test: ";
cin >> str;
for (int i = 0; str[i] != '\0'; i++)
{
if (!isalnum(str[i]))
{
cout << str[i] << " is not alphanumeric" << endl;
}
}
}
void countChar ()
{
//counts the number of times that a certain character shows
// up in a string.
std::string string1;
char ch;
cout << "Please enter a word: "; cin >> string1;
cout << "Please enter a character to count: "; cin >> ch;
int count = 0;
for (int i = 0; (i = string1.find(ch, i)) != std::string::npos; i++) {
count++;
}
std::cout << "Character " << ch << " occurs " << count << " times" << endl << endl;
}
RUN:
=================================================================
PROGRAM RUNNING..
=================================================================
Choose what you would like to check for in a word
that you will enter...
=================================================================
1) Check for palindrome.
2) Check for all alpha.
3) Count the number of times a letter is in a word.
4) Exit Program.
Enter: 1
Enter a string: lol
lol is a palindrome
Press 1 and enter to rerun program. Enter any other number to close program: 1
=================================================================
PROGRAM RUNNING..
=================================================================
Choose what you would like to check for in a word
that you will enter...
=================================================================
1) Check for palindrome.
2) Check for all alpha.
3) Count the number of times a letter is in a word.
4) Exit Program.
Enter: 1
Enter a string: tyler
tyler is not a palindrome
Press 1 and enter to rerun program. Enter any other number to close program: 1
=================================================================
PROGRAM RUNNING..
=================================================================
Choose what you would like to check for in a word
that you will enter...
=================================================================
1) Check for palindrome.
2) Check for all alpha.
3) Count the number of times a letter is in a word.
4) Exit Program.
Enter: 2
Enter a string to test: tyler!@#
! is not alphanumeric
@ is not alphanumeric
# is not alphanumeric
Press 1 and enter to rerun program. Enter any other number to close program: 1
=================================================================
PROGRAM RUNNING..
=================================================================
Choose what you would like to check for in a word
that you will enter...
=================================================================
1) Check for palindrome.
2) Check for all alpha.
3) Count the number of times a letter is in a word.
4) Exit Program.
Enter: 3
Please enter a word: mississippi
Please enter a character to count: i
Character i occurs 4 times
Press 1 and enter to rerun program. Enter any other number to close program: 2
================================================================
Program Closing...
================================================================
_______________________________________________________________________________
|