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
|
//Code by Jordan Harris-Toovy for OIT's CST116 course lab 3. October 2021
#include <iostream>
#include <iomanip>
using namespace std;
//7.2 - Learn by doing exercises #1
/*
int main()
{
float money = 0.0F;
bool has_checkings = 0;
bool has_savings = 0;
cout << "Please enter the amout of money you have (in USD): \n";
cin >> money;
cout << "Do you have a checkings account (enter 0 for no, 1 for yes): \n";
cin >> has_checkings;
cout << "Do you have a savings account (enter 0 for no, 1 for yes): \n";
cin >> has_savings;
cout << "\n\n";
cout << "Your account type is: ";
if (money >= 25000)
cout << "Platnum" << endl;
else if (money >= 10000)
{
if (has_checkings == 1 && has_savings == 1)
cout << "Gold" << endl;
else if ((has_checkings == 1 && has_savings == 0) || (has_checkings == 0 && has_savings == 1))
cout << "Silver" << endl;
else
{
cout << "Error" << endl;
return 1;
}
}
else
cout << "Copper" << endl;
return 0;
}
*/
//7.4 - Learn by doing exercises #1
/*
int main()
{
cout << "Student Grade Program\n" << " -Main Menu-" << "\n\n";
cout << "1. Enter name\n";
cout << "2. Enter test scores\n";
cout << "3. Display test scores\n";
cout << "9. Exit\n\n";
cout << "Please enter your choice from the list above: ";
int user_input = 0;
cin >> user_input;
cout << "\n";
switch (user_input)
{
case 1:
cout << "This is where you would enter a name if this was more then a menu!\n";
break;
case 2:
cout << "This is where you would enter a test score if this was more then a menu!\n";
break;
case 3:
cout << "This is where you would see test scores if this was more then a menu!\n";
break;
case 9:
cout << "Goodbye\n";
break;
default:
cout << "Invalid input. Exiting\n";
return 1;
}
return 0;
}
*/
//7.10 - Programing exercises #2
//Pesudocode:
/*
DISPLAY promt for interest rate
GET interest rate from user
DISPLAY promt for loan amount
GET loan amount from user
IF interest rate is out of range
DISPLAY error message
IF loan amount is out of range
DISPLAY error message
IF loan amount is greater than the threshold
MOVE high fee into varible charge
OTHERWISE
MOVE low fee into varible charge
Calculate the interest of the loan amount and add it to varible charge
DISPLAY charge
*/
/*
int main()
{
float interest_rate = -1.00F;
float principal = -1.00F;
float fee = 0.00F;
float payment = -1.00F;
cout << "Enter the interest rate (in percent) of the loan: ";
cin >> interest_rate;
cout << "\nEnter the principal (in USD) of the loan: ";
cin >> principal;
cout << endl;
if (interest_rate > 18)
{
cout << "Interest rate is too high\n";
return (1);
}
else if (interest_rate < 1)
{
cout << "Interest rate is too low\n";
return (2);
}
if (principal > 1000.00F)
{
cout << "Principal is too large\n";
return (3);
}
else if (principal < 100.00F)
{
cout << "Principal is too small\n";
return (4);
}
if (principal > 500.00F)
fee = 25.00F;
else
fee = 20.00F;
payment = principal * (interest_rate / 100);
payment += fee;
cout << "\n\nThe payment due for this billing cycle is ";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << payment << " USD\n";
return (0);
}
*/
//8.2 - Learn by doing exercises #1
/*
int main()
{
int max_value = -1;
cout << "Enter an interger between 1 and 50: ";
cin >> max_value;
//Filter invalid input
if ((max_value < 1) || (max_value > 50))
{
cout << "\n Invalid input";
return (1);
}
cout << "The even numbers between " << max_value << " and 0 (inclusive) are: " << endl;
//Check if even, remove 1 if not
if ((max_value % 2) != 0)
{
max_value--;
}
while (max_value >= 0)
{
cout << max_value << endl;
max_value -= 2;
}
return (0);
}
*/
//8.3 - Learn by doing exercises #1
/*
int main()
{
int max_value = -1;
while ((max_value < 1) || (max_value > 50))
{
cout << "Enter an interger between 1 and 50: ";
cin >> max_value;
//Alert user of invalid input
if ((max_value < 1) || (max_value > 50))
{
cout << "\n Invalid input\n";
}
}
cout << "The even numbers between " << max_value << " and 0 (inclusive) are: " << endl;
//Check if even, remove 1 if not
if ((max_value % 2) != 0)
{
max_value--;
}
do
{
cout << max_value << endl;
max_value -= 2;
}
while (max_value >= 0);
return (0);
}
*/
//8.4 - Learn by doing exercises #1
//Pseudocode:
/*
* DISPLAY loop-length prompt
* GET num_asign
*
* FOR num_asign:
* DISPLAY score prompt
* GET num_asign, ADD to scores
*
* DIVIDE scores by num_asign
* DISPLAY scores
*/
/*
int main()
{
unsigned int num_asign = 0;
float score = 0.0F, temp_score = 0.0F;
cout << "Enter the number of asignments: ";
cin >> num_asign;
cout << "\nEnter each score as a percent.\n\n";
for (int idx = 0; idx < num_asign; idx++)
{
cout << "Enter score " << idx + 1 << " : ";
cin >> temp_score;
score += temp_score;
cout << endl;
}
score = score / num_asign;
cout << "The average score is: " << score << endl;
return (0);
}
*/
//8.4 - Learn by doing exercises #2 (NOT IN PROBLEM SET)
/*
int main()
{
int tri_height = 0;
cout << "Enter size of triangle: ";
cin >> tri_height;
cout << endl;
if (tri_height > 0)
{
tri_height--;
}
else
{
cout << "Invalid size";
return (1);
}
for (tri_height; tri_height >= 0; tri_height--)
{
for (int tri_width = tri_height; tri_width >= 0; tri_width--)
cout << "* ";
cout << endl;
}
return (0);
}
*/
//8.10 - Programing exercises #3
//Pseudocode:
/*
* DISPLAY user prompt for maximum sequence value
* GET max_value
*
* IF max_value < 1, end
* ELSE IF max_value = 1, DISPLAY 1, 1
* ELSE:
*
* DISPLAY 1, 1, 2
* working_v1 = 1
* working_v2 = 2
* working_v3 = 2
*
* WHILE working_v3 < max_value:
*
* working_v3 = working_v1 + working_v2
* working_v1 = working_v2
* working_v2 = working_v3
*
* DISPLAY working_v3
*/
int main()
{
unsigned long long max_val = 0, working_v1 = 1, working_v2 = 1, working_v3 = 2;
cout << "Enter maximum positive integer for the Fibonacci sequence: ";
cin >> max_val;
cout << endl;
if (max_val == 0)
cout << "Not in sequence" << endl;
else
{
cout << "1\n1" << endl;
while (working_v3 < max_val)
{
cout << working_v3 << endl;
working_v3 = working_v1 + working_v2;
working_v1 = working_v2;
working_v2 = working_v3;
}
cout << endl;
}
return (0);
}
|