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
|
EXERCISES 3a
Page 63-64;Exercises 4.1
1)-12.34 - float
2)"Hello" - string
3)"F" or 'F' - string or char
4)"1234" - string
5)'1' - char
6)"A" or 'A' - string or char
7)"Marcus" - string
3 (page 72))
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; or char = '1'; Im not sure is the book is okay with keeping the value 1 or they want what 1 is referring to.
f.int a, b, c, d, e , f;
g.string x = "This is a test.";
4(page 122)) - I am solving these problems assuming the variables already have been pre defined somewhere in the program.
a)y = 5*x+1;
b)C++ does not solve equation by default. Its a polynomial. i dont think there is a way to rewrite it and have the computer
read it without the help of a library
c)x = 5*a+4;
d.b = 0/-15;
--------------------------------------------------------------------------
EXERCISES 3b
Page 82,83 # 1-2
1)
Display "Enter old wage: "
Read Old_wage
New_wage = Old_wage*1.06
Display Old_wage
Display"+6%="
Display New_wage
2)
Display "Enter assignment average:"
Read Assignment_avg
Display "Enter test 1:"
Read Test 1
Display "Enter test 2:"
Read Test2
Display "Enter test 3:"
Read Test3
Display "Enter Final:"
Read Final
Test_avg = (Test1 + Test2 + Test3)/3
Class_score + Assignmnet_avg*.30 + Final*.25 + Test_avg*.45
Display "Final Score:"
Display Class_score
---------------------------------------------------------------------------------
EXERCISES 3c
pages 83-84 #2-3
2)
PROGRAM:
#include <iostream>
#include <iomanip>
using namespace std;
using std::ios;
int main()
{
char ascii = 67;
cout << ascii << '\n';
ascii = 43;
cout << ascii << '\n';
cout << ascii << '\n';
//return 0;
}
OUTPUT:
C
+
+
C:\Users\ansar\source\repos\OIT Brushup\Debug\OIT Brushup.exe (process 21044) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
3)
PROGRAM:
#include <iostream>
#include <iomanip>
using namespace std;
using std::ios;
int main()
{
int age = 18;
int daysInYears = 365;
cout << age * daysInYears;
}
OUTPUT:
6570
C:\Users\ansar\source\repos\OIT Brushup\Debug\OIT Brushup.exe (process 12788) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
===============================================================================
EXERCISE 4a
Page 100 - #1
PROGRAM:
#include <iostream>
#include <iomanip>
using namespace std;
using std::ios;
int main()
{
float personTemp;
cout << "Enter your temperature: " << endl;
cin >> personTemp;
cout.setf(ios::fixed);
cout << setw(6) << setprecision(1) << personTemp << endl;
}
OUTPUT:
Enter your temperature:
54.721
54.7
C:\Users\ansar\source\repos\OIT Brushup\Debug\OIT Brushup.exe (process 6536) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
Page 123-124 #1-5
#include <iostream>
#include <iomanip>
using namespace std;
using std::ios;
int main()
{
float a;
a = 5 + 10 * 2;
cout << a << endl;
a = (5 + 10) * 2;
cout << a << endl;
a = 5;
a = a + (5 + 10) * 2;
cout << a << endl;
a = 10 % 5;
cout << a << endl;
a = 10 % 3;
cout << a << endl;
}
OUTPUT:
25
30
35
0
1
C:\Users\ansar\source\repos\OIT Brushup\Debug\OIT Brushup.exe (process 17632) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
#5-7
#include <iostream>
#include <iomanip>
using namespace std;
using std::ios;
int main()
{
float a;
a = 7 + 5 - 2;
cout << a << endl;
a = 5.2 / 2.3;
cout << a;
}
OUTPUT:
10
2.26087
C:\Users\ansar\source\repos\OIT Brushup\Debug\OIT Brushup.exe (process 21412) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
--------------------------------------------------------------------------------------
EXERCISE 4b
Page 112-114
PROGRAM:
#include <iostream>
#include <iomanip>
using namespace std;
using std::ios;
int main()
{
float money = 123.45;
float raise;
cout << "You have $";
cout << money << endl;
cout << "enter percent raise: ";
cin >> raise;
raise = (raise / 100) + 1;
money = money * raise;
cout << "After your raise you have $";
cout << money << endl;
}
OUTPUT:
You have $123.45
enter percent raise: 10
After your raise you have $135.795
C:\Users\ansar\source\repos\OIT Brushup\Debug\OIT Brushup.exe (process 18136) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
Page 114 - 115
PROGRAM:
#include <iostream>
using namespace std;
int main()
{
double ProductionHours,
PreProductionHours,
ProducersHours,
ProductionCost,
PreProductionCost,
ProducersCost,
TotalCost,
PRODUCTION_RATE,
PRE_PRODUCTION_RATE,
PRODUCERS_RATE;
cout << "Enter Production Hours: ";
cin >> ProductionHours;
cout << "\nEnter Pre-Production Hours:";
cin >> PreProductionHours;
cout << "\nEnter Producers Hours: ";
cin >> ProducersHours;
cout << "\nEnter Production Rate: ";
cin >> PRODUCTION_RATE;
cout << "\nEnter Pre Production Rate: ";
cin >> PRE_PRODUCTION_RATE;
cout << "\nEnter Producers Rate: ";
cin >> PRODUCERS_RATE;
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;
}
OUTPUT:
Enter Production Hours: 5
Enter Pre-Production Hours:3
Enter Producers Hours: 7
Enter Production Rate: 8
Enter Pre Production Rate: 1
Enter Producers Rate: 6
Car Dealership Bill
"
Production Cost: 40
Pre-Production Cost: 3
Producers Cost: 42
Weekly Total Cost: 85
C:\Users\ansar\Source\Repos\cst116-lab2-rayyanansari03_1\Lab2Ansari\Debug\Lab2Ansari.exe (process 9804) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
|