blob: c19e2bdbf8b17237fda0fa0c46c0edebb9405d24 (
plain) (
blame)
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
|
CST116 today
Module 2: Lab 2
3a
4.1 Exercises
pp 63-64
3.5 pts #1-7
Submit: labelled and corrected literals
1. -12.34 Numeric
2. �Hello� Illegal
3. �F� String
4. �1234� String
5. �1� Character
6. A Illegal
7. �Marcus� Illegal
4.3 Exercises
p 72
3.5 pts #3
Submit: corrected statements
a. int a, b;
b. int b = 0;
int a = b;
c. int a = 0
float b = 3.5;
d. char grade = 'A';
e. char c = '1';
f. int a, b, c, d, e, f;
g. string x = �This is a test.�;
6.1 Exercises
p 122
4 pts #5-4
Submit: corrected statements
11 pts total
1. Y = 5x + 1; Invalid because "5x" needs *
2. x^2 + 2x + 1 = 0; Invalid because "2x" and because the left side of the equal sign should just be a variable location and you cannot use exponents
3. X = 5 * a + 4; Valid
4. 0 = -15 * b; Invalid because "0" (left side of equal sign must be a variable)
3b
4.12 Exercises
pp 82-83
20 pts 1-2
Submit: corrected pseudocode
20 pts total
1.
Display "Enter old wage: "
Read Old_wage
Raise = Old_wage * .06
New_wage = Old_wage + Raise
Display Old_wage
Display "+ 6% ="
Display New_Wage
2.
Display "Enter Assignment average: "
Read Assignment_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_avg = Test1 * .15 + Test2 * .15 + Test3 *.15 / 3
Class_Score = Assign_avg * .30 + Test_avg * .45 + Final * .25
Display "Final score: "
Display Class_score
3c
4.13 Programming Exercises
pp 83-�84
20 pts 2-�3
Submit: code & run
20 pts total
2.
#include <iostream>
using std::cout;
int main()
{
char ascii = 67;
cout << ascii << '\n';
ascii = 43;
cout << ascii << '\n';
cout << ascii << '\n';
return 0;
}
RUN:
C
+
+
3.
PSEUDOCODE:
Display "Enter age: "
Read age
new_age = age * days
Display new_age
CODE:
#include <iostream>
using namespace std;
int main()
{
int age = 0;
int new_age = 0;
const int days = 365;
cout << "Enter age: ";
cin >> age;
new_age = age * days;
cout << "Your age in days is: " << new_age << endl;
return 0;
}
RUN:
Enter age: 19
Your age in days is: 6935
4a
p 100
5.4 Learn by Doing Exercises
10 pts #1
Submit: code & run
1.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float temp = 0;
cout << "Enter temperature: ";
cin >> temp;
cout.width(6);
cout.setf(ios::fixed);
cout << setprecision(1) << temp << endl;
return 0;
}
RUN:
Enter temperature: 98.5
98.5
pp 123�-124
6.3 Exercises
4 pts #1-�7
Submit: corrected equations and values of the variable �a�
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; Modulus cannot be used for floats
7. 2 - 5 + 7 = a; The left side of the equal sign should be the variable
4b
pp 112-114
5.9 Debugging Exercise
10 pts
Submit: corrected code & run
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
int main()
{
float money = 123.45F;
float raise_amount = 0;
float raise;
float new_money = 0;
cout << "You have $";
cout << money << endl;
//Breakpoint 1
//Put a breakpoint on the following line
cout << "Enter percent raise: ";
cin >> raise_amount;
raise = money * raise_amount;
new_money = money + raise;
cout << "After your raise you have $";
cout << new_money << endl;
return 0;
}
RUN:
You have $123.45
Enter percent raise: .1
After your raise you have $135.795
pp 114-115
5.10 Programming Exercise
10 pts #1
Submit: corrected code & run
20 pts total
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main( )
{
double ProductionHours, ProducersHours, ProducersCost, TotalCost;
double ProductionRate = 0;
double ProductionCost = 0;
cout << "Enter Production Hours: ";
cin >> ProductionHours;
cout << "\nEnter Production Rate: ";
cin >> ProductionRate;
cout << "\nEnter Producers Hours: \n";
cin >> ProducersHours;
ProductionCost = ProductionHours * ProductionRate;
ProducersCost = ProducersHours * ProductionRate;
TotalCost = ProductionCost + ProducersCost;
cout << "\n\t\tCar Dealership Bill " ;
cout << "\n\nProduction Cost: ";
cout << ProductionCost ;
cout << "\n\nPre-Production Cost: ";
cout << ProductionCost;
cout << "\n\nProducers Cost: ";
cout << ProducersCost;
cout << "\n\nWeekly Total Cost: ";
cout << TotalCost << endl;
return 0;
}
RUN:
Enter Production Hours: 5
Enter Production Rate: 89
Enter Producers Hours:
9
Car Dealership Bill
Production Cost: 445
Pre-Production Cost: 445
Producers Cost: 801
Weekly Total Cost: 1246
|