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
|
Tyler Taormina
October 6, 2021
Module 2 Lab 2
3a) Literals
pg 62
4.1 Exercises
------------------------
Correct and Label Literals
-----------------------------------------------------------------------
1. -12.34 Numeric
.
2. �Hello� �Hello� type string
3. �F� type string
4. �1234� type string
5. �1� type character
6. A �A� type character
7. �Marcus� �Marcus� type string
pg 65
4.3 Exercises
---------------------
State what is wrong with each of the below
-------------------------------------------------------------------------
a. int a, int b;
In the above code we could remove the second 'int' before the b. We would have...
int a, b;
b. Int a = b;
Int b = 0;
In the above code we would need to change the order so that we are giving b a value before we initialize a. Corrected would look like...
int b = 0;
int a = b;
c. Int a = 0, b = 3.5;
Should be....
int a = 0;
float b = 3.5;
d. Char grade = �A�;
Should be single quotes...
char grade = 'A';
e. Char c = 1;
Should be in single quotes...
char c = '1';
f. Int a, b, c, d, e, f;
should be lowercase 'i' in "int" and the names are nondescriptive
g. Char x = �This is a test.�;
Should be a string...
String x = "This is a test.";
pg 122
6. 1 Exercises
----------------------------------------------------------------------------
1. y = 5x + 1;
invalid because in c++ we cannot use a coefficient with a variable. We would need an asterisc to imply multiplication
2. X^2 + 2x + 1 = 0;
invalid because of the coefficient
3. x = 5 * a + 4;
valid c++ statement
4. 0 = -15 * b;
cannot have a constant on the left side of an equal sign, must be a variable.
pg 82
3B)
4.12 Exercises
--------------------------------------------------------------------------------
1. 6% raise problem (this is the corrected pseudo code)
Display "enter old wage: "
read old_wage
raise_amnt = old_wage * .06
new_wage = old_wage + raise_amnt
display old_wage
display " + 6% = "
display new_wage
2. Final Grade problem (this is the corrected pseudo code)
Display "Enter Assignment Avergae: "
read assign_avg
Display "Enter test 1: "
read test1
Display "Enter test 2:"
read test2
Display "Enter test 3:"
read test3
Display "Enter Final: "
read final_test
test_avg = (test1 * .15 + test2 * .15 + test3 * .15) / 3
class_score = assign_avg * .30 + test_avg * .45 + final_test * .25
Display "Final Score:"
display class_score
3C)
4.13 Programming exercise
pg 83-84
#2-3
2) Just compile and run program. Will include image.
3)
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int year = 365;
int age = 27;
int age_in_days;
age_in_days = year * age;
cout << "You are " << age_in_days << " days old!";
return 0;
}
4A)
5.4 Exercise
pg 100
#1
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float temp;
cin >> temp;
cout << "Your temperature is: ";
cout.width(6);
cout.setf(ios::fixed); // decimal notation
cout << setprecision(1) << temp << endl;
return 0;
6.3 Exercises
pg 123-124
#1-7
1) a = 5 + 10 * 2
a = 25
2) a = (5 + 10) * 2;
a = 30
3) a = 5;
a = a + (5 + 10) * 2;
a = 35
4) a = 10 % 5;
a = 0
5) a = 10 % 3;
a = 1
6) a = 5.2 % 2.3;
Error for incorrect opperands. Cannot use '%' with type double or float
7) 2 - 5 + 7 = a;
Error saying expression must be a modifiable value
4B)
5.9 Debugging Exercise
int main() {
float money = 123.45;
float raise;
cout << "You have $ ";
cout << money << endl;
// breakpoint 1
//put a breakpoint on the folowing line
cout << "Enter percent raise: ";
cin >> raise;
money = money * raise + money;
cout << "After your raise you have $";
cout.setf(ios::fixed);
cout << setprecision(2) << money << endl;
return 0;
}
5.10 Programming Exercise
pg 114-115
#1
#include <iostream>
using namespace std;
int main() {
float PRODUCTION_RATE = 10.00;
float PRE_PRODUCTION_RATE = 10.00;
float PRODUCERS_RATE = 10.00;
double ProductionHours, PreProductionHours, ProducersHours, ProductionCost,
PreProductionCost, ProducersCost, TotalCost;
cout << "Enter Production Hours: ";
cin >> ProductionHours;
cout << "\nEnter Pre-Production Hours: ";
cin >> PreProductionHours;
cout << "\nEnter Producers Hours: ";
cin >> ProducersHours;
ProductionCost = ProductionHours * PRODUCTION_RATE;
PreProductionCost = PreProductionHours * PRE_PRODUCTION_RATE;
ProducersCost = ProducersHours * PRODUCERS_RATE;
TotalCost = ProductionCost + PreProductionCost + ProducersCost;
cout << "\n\t\tCar Dealership Bill\n";
cout << "\n\nProduction Cost: ";
cout << ProductionCost;
cout << "\n\nPre-Production Cost: ";
cout << PreProductionCost;
cout << "\n\nProducers Cost: ";
cout << ProducersCost;
cout << "\n\nWeekly Total Cost: ";
cout << TotalCost << endl;
return 0;
}
|