blob: 4acfc140dc75827f4e469717a67558e21d461c6c (
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
|
#include <iostream>
using namespace std;
//5a
//6.4 Exercises
//int main()
//{
// int a = 0;
// cout << a++ << endl;
// cout << ++a << endl;
// cout << a + 1 << endl;
// cout << a << endl;
// cout << --a << endl;
//}
//5a
//7.2 Exercises
//int main()
//{
// int money = 0;
// int accounts = 0;
//
// cout << "What is your balance?" << endl;
// cin >> money;
// cout << "How many accounts do you have open with us?" << endl;
// cin >> accounts;
//
// if (money >= 25000)
// cout << "Your membership is Platinum";
// else if (money < 25000 && money > 10000 && accounts == 2)
// cout << "Your membership is Gold";
// else if (money > 10000 && accounts == 1)
// cout << "Your membership is Silver";
// else if (money <= 10000)
// cout << "Your membership is Copper";
//
// return 0;
//}
//5b
//7.4 Exercises
//int main()
//{
// char menu_selection;
// cout << "Student Grade Program" << endl;
// cout << "- Main Menu -" << endl << endl;
// cout << "1. Enter name\n2. Enter test scores\n3. Display test scores\n9. Exit"
// << endl << endl;
// cout << "Please enter your choice from the list above ";
//
// cin >> menu_selection;
//
// switch (menu_selection)
// {
// case '1':
// cout << "Enter name";
// break;
// case '2':
// cout << "Enter test scores";
// break;
// case '3':
// cout << "Display test scores";
// break;
// case '9':
// cout << "Exit";
// break;
// }
//}
//5c
//7.10 Exercises #2
//int main()
//{
//variables
// int amountOfLoan = 0;
// float interestRate = 0;
// int fee = 0;
//defining variables w/ input sequence
// cout << "Enter the amount of your loan" << endl;
// cin >> amountOfLoan;
// cout << endl;
// cout << "Enter the interest rate" << endl;
// cin >> interestRate;
// cout << endl;
//checking if inputs are valid
// if (interestRate > 18 || interestRate < 1)
// {
// cout << "Error: invalid interest rate" << endl;
// return 0;
// }
// if (amountOfLoan > 1000 || amountOfLoan < 100)
// {
// cout << "Error: invalid loan amount" << endl;
// return 0;
// }
//calculating fees
// if (amountOfLoan <= 500 || amountOfLoan >= 100)
//fee = 20;
// if (amountOfLoan > 500)
//fee = 25;
//outputting data
// cout << "The total amount of interest due is ";
// cout << amountOfLoan * interestRate << endl;
// cout << "The interest rate is ";
// cout << interestRate << endl;
// cout << "The total amount of interest and fees due is ";
// cout << (amountOfLoan * interestRate) + fee << endl;
// return 0;
// }
//6b
//Section 8.4
//#1
int main()
{
//defining variables
int numOfAssignments = 0; int gradedAssignments = 0; float score; float scoreAccumulate = 0; float averageScore; int numCount = 1;
//user prompt and input
cout << "Enter the number of assignments" << endl;
cin >> numOfAssignments;
gradedAssignments = numOfAssignments;
cout << endl;
//get each assignment score
for (numOfAssignments; numOfAssignments > 0; numOfAssignments--)
{
cout << "Enter the score for Assignment #" << numCount << endl;
cin >> score;
scoreAccumulate = scoreAccumulate + score;
numCount++;
}
//calculate average score
averageScore = (scoreAccumulate / gradedAssignments);
//print average score
cout << "The average score of these " << gradedAssignments << " assignments is " << averageScore;
}
// Section 8.4
// #2
//int main()
//{
//defining variables
//int baseLength = 0;
//asking for input
//cout << "Base length?" << endl;
//cin >> baseLength;
//cout << endl;
//executing loops to create triangle
//for (int b = baseLength; b <= baseLength, b != 0; b--)
//{
//for (int a = b; a != 0; a--)
//{
//cout << '*';
//}
//cout << endl;
//}
//return 0;
//}
//Section 8.10 #3
//int main()
//{
// int endValue = 0; int currentValue = 1; int behind_currentValue = 0; int currentBehindSum = 1;
// cout << "Where would you like your Fibonacci sequence to terminate?\n";
// cin >> endValue;
// cout << endl;
// while (currentValue <= endValue)
// {
// cout << currentBehindSum << ' ';
// currentBehindSum = currentValue + behind_currentValue;
// behind_currentValue = currentValue;
// currentValue = currentBehindSum;
// }
// cout << endl;
// return 0;
//}
//6a
//Section 8.2 # 1
//int main()
//{
// //defining variables
// int startValue = 0;
//user prompt
// cout << "Welcome to the descending even number program.\nPlease enter an integer between 1 and 50\n";
// cin >> startValue;
// cout << endl;
// //end program if startValue not 1-50
// if ((startValue < 50) && (startValue > 1))
// {
// }
// else
// {
// cout << "The number you have entered is not between 1 and 50. Try again." << endl;
// return 0;
// }
// //check if startValue is odd, print once if odd skip if even
// if ((startValue % 2) != 0)
// {
// cout << startValue;
// cout << endl;
// }
// //calculations and display loop
// for (startValue; (startValue >= 0); startValue--)
// {
// if ((startValue % 2) == 0)
// {
// cout << startValue << ' ';
// }
// else
// {
// }
// }
// cout << endl;
// return 0;
//}
//Section 8.3 #1
//int main()
//{
//defining variables
//int startValue = 0;
//user prompt and check if number is 1-50
//cout << "Welcome to the descending even number program.\nPlease enter an integer between 1 and 50\n";
//cin >> startValue;
//cout << endl;
//if ((startValue > 50) || (startValue < 1))
//{
// do
// {
// cout << "You have not entered an integer between 1 and 50. Please try again.\n";
// cin >> startValue;
// cout << endl;
// } while ((startValue > 50) || (startValue < 1));
//}
//check if startValue is odd, print once if odd skip if even
//if ((startValue % 2) != 0)
//{
// cout << startValue;
// cout << endl;
//}
//calculations and display loop
//for (startValue; (startValue >= 0); startValue--)
//{
// if ((startValue % 2) == 0)
// {
// cout << startValue << ' ';
// }
// else
// {
// }
//}
//cout << endl;
//return 0;
//}
|