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
|
Tyler Taormina
cst116
Module 3 Lab 3
---------------------------------------------------------------------------------------------------------------------------------------------------
5A)
6.4 exercises page 126
#1 submit ouput
1) The output for the code provided in the text book would be...
0
2
3
2
1
7.1 exercises page 148
#1-6 submit corrected conditions
1) int_expl >= int_exp2;
2) int_expl == int_exp2;
3) int_exp1 != int_exp2;
4) char_exp == 'A';
5) int_exp1 > char_exp; illegal because we are attempting to compare an integer and a character.
6) int_exp1 < 2 && int_exp1 > -10;
7.2 exercises page 155
#1 submit code & run
1) if (a > 0)
cout << "a is greater than 0" << endl;
-----------------------------------------------------------------------------------------------------------------------------------------------------
5B)
7.4 exercises page 161
#1 submit code & run
1)
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int user_choice;
cout << "\t\tStudent Grade Program" << endl;
cout << "\t\t - Main Menu -" << endl;
cout << "1. Enter Name" << endl;
cout << "2. Enter test scores" << endl;
cout << "3. Display test scores" << endl;
cout << "9. Exit" << endl;
cout << "Please enter your choice from the list above: ";
cin >> user_choice;
switch (user_choice)
{
case 1:
cout << "You chose to Enter your name." << endl;
break;
case 2:
cout << "You chose to Enter test scores." << endl;
break;
case 3:
cout << "You chose to display test scores." << endl;
break;
case 9:
cout << "You chose to exit." << endl;
break;
}
return 0;
}
RUN:
Student Grade Program
- Main Menu -
1. Enter Name
2. Enter test scores
3. Display test scores
9. Exit
Please enter your choice from the list above: 1
You chose to Enter your name.
C:\Users\Till\source\repos\hw_practice\Debug\hw_practice.exe (process 7824) exited with code 0.
Press any key to close this window . . .
5C)
7.10 exercises page 168
#2 submit code & run
2)
sudo code
-----------------
intialize loan fee for (little loan)
intialize loan fee for (big loan)
input loan amount
check to make sure if loan amount is within range
input interest rate
check to make sure interest rate is in range
calculate interest
calculate total cost including interest and fee
display interest amount on loan
display requested loan amount
display interest rate
display total cost with interest and fee
code
---------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int fee_1 = 20;
int fee_2 = 25;
int loan_amount, interest_rate;
double interest_dec, interest_amount , total_cost = 0;
std::cout << "Please enter a loan amount request: ";
cin >> loan_amount;
if (loan_amount >= 100 && loan_amount <= 1000)
{
std::cout << "Please enter an interest rate: ";
cin >> interest_rate;
if (interest_rate >= 1 && interest_rate <= 18)
{
if (loan_amount > 500)
{
total_cost += fee_2;
}
else
{
total_cost += fee_1;
}
interest_dec = interest_rate * .01;
interest_amount = interest_dec * loan_amount;
total_cost += interest_amount + loan_amount;
std::cout << "Interest paid on this loan is: $" << interest_amount << endl;
std::cout << "Requested Loan: $" << loan_amount << endl;
std::cout << "Interest rate: " << interest_rate << "%" << endl;
std::cout << "Total cost including all fees for this loan will be: $" << total_cost << endl;
return 0;
}
else
{
std::cout << "Error. Invalid interest rate. Please enter an interest rate between 1 and 18." << endl;
return 0;
}
}
else
{
std::cout << "Error. Invalid loan amount. Please enter a loan amount between $100 and $1000." << endl;
return 0;
}
return 0;
}
RUN:
Please enter a loan amount request: 500
Please enter an interest rate: 5
Interest paid on this loan is: $25
Requested Loan: $500
Interest rate: 5%
Total cost including all fees for this loan will be: $545
C:\Users\Till\source\repos\hw_practice\Debug\hw_practice.exe (process 14452) exited with code 0.
Press any key to close this window . . .
6A)
6.5 Exercises
pg 126-127
#1-5
1.) a += 25;
2.) b *= 2 * a;
3.) b++;
4.) c %= 5;
5.) b /= a
----------------------------------------------------------------------------------------------
8.2 Pg 177 #1
1.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int number;
cout << "Enter a number between 1 and 50: ";
cin >> number;
if (number % 2 == 0)
{
while (number >= 0)
{
cout << number << endl;
number -= 2;
}
}
else {
cout << number << endl;
number -= 1;
while (number >= 0)
{
cout << number << endl;
number -= 2;
}
}
return 0;
}
RUN:
Enter a number between 1 and 50: 13
13
12
10
8
6
4
2
0
---------------------------------------------------------------------------------------------------
8.3 pg 179 #1 using do-while statements
1. Submit code and run
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int number;
cout << "Enter a number between 1 and 50: ";
cin >> number;
do
{
if (number % 2 == 0)
{
cout << number << endl;
number -= 2;
}
else
{
cout << number << endl;
number -= 1;
while (number >= 0)
{
cout << number << endl;
number -= 2;
}
}
} while (number >= 0);
return 0;
}
RUN:
Enter a number between 1 and 50: 25
25
24
22
20
18
16
14
12
10
8
6
4
2
0
C:\Users\Till\source\repos\hw_practice\Debug\hw_practice.exe (process 21168) exited with code 0.
Press any key to close this window . . .
-------------------------------------------------------------------------------------------------------------
8.4 Learn by doing exercise Pg. 184 #1
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int num_assignments, ctr;
float score, avg, score_total = 0.0;
cout << "Please enter the total number of assignments: ";
cin >> num_assignments;
ctr = num_assignments;
for (ctr; ctr > 0; ctr--)
{
cout << "Please enter score: ";
cin >> score;
score_total += score;
}
avg = score_total / num_assignments;
cout << "Your Average score for assignments is: " << avg << endl;
return 0;
}
RUN:
Please enter the total number of assignments: 5
Please enter score: 10
Please enter score: 9
Please enter score: 9
Please enter score: 10
Please enter score: 10
Your Average score for assignments is: 9.6
C:\Users\Till\source\repos\hw_practice\Debug\hw_practice.exe (process 21132) exited with code 0.
Press any key to close this window . . .
------------------------------------------------------------------------------------------------------------------------------
8.10 Programming Exercises Pg 192 #3 FIBONACCI SEQUENCE
#include <iostream>
using namespace std;
int main()
{
int limit, term1 = 0, term2 = 1, nextTerm = 0;
cout << "Enter the limit for the fibonacci sequence: ";
cin >> limit;
cout << "Fibonacci Sequence: " << term1 << ", " << term2 << ", ";
nextTerm = term1 + term2;
while (nextTerm <= limit) {
cout << nextTerm << ", ";
term1 = term2;
term2 = nextTerm;
nextTerm = term1 + term2;
}
return 0;
}
RUN:
Enter the limit for the fibonacci sequence: 26
Fibonacci Sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21,
C:\Users\Till\source\repos\hw_practice\Debug\hw_practice.exe (process 19324) exited with code 0.
Press any key to close this window . . .
|