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
|
CST116 C++
6.4 5a pg 126 #1
1.
0
2
3
2
1
7.1 pg 148 #1-6
1. The sign is reversed. it should be <=
int_exp1 <= int_exp2
2. There should be 2 equal signs
int_exp1 == int_exp2
3. ! should be on the other side
int_exp1 != int_exp2
4. Cant compare a string literal using relational quotes
char_exp == 'A'
5. This is correct
6. Has to have int_exp1 (on each side of operator)
int_exp1 < 2 && int_exp1 > -10
7.2 pg 155 #1
#include <iostream>
#include<math.h>
#include<iomanip>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
int money;
int accounts;
//take the number of accounts
cout << "How many accounts do you have with us today?\n";
std::cin >> accounts;
//take the money amount
cout << "How much money do you have in your account(s)?\n $";
std::cin >> money;
//if x>=25,000 is platinum
//if 10,000<x<25,000 and 2 accounts is gold
// if x>10,000 but only 1 account is silver
//if x<=10,000 is copper
if ((money >= 25000) & (accounts == 2)) {
cout << "You are a Platinum member!";
}
else if ((money >= 25000) & (accounts == 1)) {
cout << "You are a Platinum member!";
}
else if (((10000 < money) && (money < 25000)) & (accounts > 1)) {
cout << "You are a Gold member!";
}
else if (((10000 < money) && (money < 25000)) & (accounts == 1)) {
cout << "You are a Silver member";
}
else if ((money <= 10000) & (accounts == 2)) {
cout << "You are a Copper member";
}
else if ((money <= 10000) & (accounts == 1)) {
cout << "You are a Copper member";
}
return 0;
}
5b 7.4 pg 161 #1
#include <iostream>
#include <iomanip>
using std::endl;
using std::cout;
int main()
{
int selection;
cout << "Student Grade program\n -Main Menu- \n\n1. Enter Name\n2. Enter test scores\n3. Display test scores\n9. Exit\n\nPlease enter your choice from the list above\n\n";
std::cin >> selection;
switch (selection)
{
case 1 :
cout << "\n\nYour choice is: Enter Name?\n\n";
break;
case 2:
cout << "\n\nYour choice is: Enter Test Scores?\n\n";
break;
case 3:
cout << "\n\nYour choice is: Display Test Scores?\n\n";
break;
case 9:
cout << "\n\nYour choice is: to Exit?\n\n";
break;
default:
cout << "\n\nYour selection is invalid... Try again\n\n";
}
}
5c 7.10 pg 168 #2
#include <iostream>
#include<iomanip>
#include <stdlib.h>
#include <thread>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
int loan;
float interest{};
float percent_interest;
float sum_of_interest_and_fees;
int fee;
string response;
string agreement;
//agreement for margin of acceptance
cout << "Just to let you know before we start, \nthe parameters for a loan is between $100 and $1000, \nand the parameters for interest rate is between 1% and 18%, \n\nis that okay?\ntype 'y' for yes and 'n' for no\n\n";
std::cin >> agreement;
if (agreement == "y")
{
cout << "\n\nWe will proceed with the questions, then...\n\n";
}
else if (agreement == "n")
{
cout << "\n\nThat is unfortunate, I cannot continue this transaction, sorry\n\n";
return (0);
}
else
{
cout << "Invalid character, try this transaction again\n\n";
return (0);
}
//enter the loan amount
cout << "Enter the loan amount:\n\n";
std::cin >> loan;
if (loan >= 100 && loan <= 1000)
{
cout << "\nAccepted";
}
else if (loan <= 100 || loan >= 1000)
{
cout << "\n\nYou are not elegible for this loan, sorry.\n" << endl;
return (0);
}
//enter the interest amount
cout << "\n\nEnter the interest amount:\n\n";
std::cin >> interest;
if (interest >= 1 && interest <= 18)
{
cout << "\nAccepted";
}
else if (interest <= 1 || interest >= 18)
{
cout << "\n\nYou are not elegible for this loan, sorry.\n" << endl;
return (0);
}
cout << "\n\nWe will now calculate your interest and fees";
cout << "\n\n...";
percent_interest = interest / 100;
if (loan >= 100 && loan <= 500)
{
fee = 20;
}
else if (loan > 500)
{
fee = 25;
}
//calculate interest and fees
sum_of_interest_and_fees = loan + (loan * percent_interest) + fee;
cout << "\n\nHere is a summary of the calculations and data you have given us:";
cout << "\n\nYou are asking for a loan of $" <<loan<< ",";
cout << "\n\nYou have an interest rate of %" << interest << ",";
cout << "\n\nSince you are borrowing $" << loan << ", there is a fee of $" << fee<< " added on";
cout << "\n\nSo the sum of the interest and fees will bill you $" << sum_of_interest_and_fees;
cout << "\n\nDoes this seem right?? Type 'y' for yes, and 'n' for no\n\n";
std::cin >> response;
if (response == "y")
{
cout << "\n\nThank you for your business.\n\n";
return (0);
}
else if (response == "n")
{
cout << "\n\nWell that kind of sucks, I don't know what to tell you.\n\n";
return (0);
}
else
{
cout << "\n\nInvalid character, try this transaction again\n\n";
return (0);
}
}
6a 6.5 pg 126-127 #1-5
1. a += 25;
2. b *= a * 2;
3. b += 1;
4. c %= 5
5. b /= a
8.2 pg 177 #1
1.
#include <iostream>
#include<iomanip>
#include <stdlib.h>
#include <thread>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
int count;
int converted_to_even;
bool even;
bool odd;
cout << "Input any number between 1 and 50:\n\n";
std::cin >> count;
if (count >= 1 && count <= 50)
{
cout << "\n\nCounting down the even numbers to 0:\n\n";
}
else
{
cout << "\n\nThis number is not a number between 1 and 50, try again.\n\n";
return (0);
}
if (count % 2 == 1)
{
converted_to_even = count - 1;
}
else
{
converted_to_even = count;
}
while (converted_to_even >= 0)
{
cout << converted_to_even << endl;
converted_to_even -= 2;
}
}
8.3 pg 179 #1
1.
#include <iostream>
#include<iomanip>
#include <stdlib.h>
#include <thread>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
int count;
int converted_to_even;
cout << "Input any number between 1 and 50:\n\n";
std::cin >> count;
if (count >= 1 && count <= 50)
{
cout << "\n\nCounting down the even numbers to 0:\n\n";
}
else
do {
cout << "\n\nERROR, this number is not between 1 and 50, please enter a number between 1 and 50\n\n";
std::cin >> count;
}
while (count > 50 || count < 1);
if (count % 2 == 1)
{
converted_to_even = count - 1;
}
else
{
converted_to_even = count;
}
while (converted_to_even >= 0)
{
cout << converted_to_even << endl;
converted_to_even -= 2;
}
}
6b 8.4 pg 184 #1
1.
#include <iostream>
#include<iomanip>
#include <stdlib.h>
#include <thread>
#include <string>
using std::cout;
using std::endl;
using std::string;
using namespace std;
int main()
{
int n, i;
float num[100], sum = 0.0, average;
cout << "How many assignments do you have in one class?\n\n";
cin >> n;
for (i = 0; i < n; ++i)
{
cout << i + 1 << ". Enter Grade: ";
cin >> num[i];
sum += num[i];
}
average = sum / n;
cout << "Your average for each assignment is: " << average << endl;
return 0;
}
6c 8.10 pg 192 #3
3.
#include <iostream>
#include<iomanip>
#include <stdlib.h>
#include <thread>
#include <string>
using std::cout;
using std::endl;
using std::string;
using namespace std;
int main()
{
int n, t1 = 0, t2 = 1, next_term = 0;
cout << "What is the number you want to count up to in Fibonacci's sequence?\n\n";
cin >> n;
cout << "Here is the sequence: " << t1 << ", " << t2 << ", ";
next_term = t1 + t2;
while (next_term <= n)
{
cout << next_term << ", ";
t1 = t2;
t2 = next_term;
next_term = t1 + t2;
}
return 0;
}
|