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
|
#include <iostream>
using namespace std;
//7a
//9.3 Learn by Doing Exercises
//float avgFunction(float first, float second, float third);
//int main()
//{
// float one = 0; float two = 0; float three = 0; float average = 0;
// cout << "This program will find the average of 3 user values\n";
//
// average = avgFunction(one, two, three);
// cout << "\nThe average is: " << average;
//
// return 0;
//}
//float avgFunction(float first, float second, float third)
//{
// cout << "Enter the first number: ";
// cin >> first;
// cout << "Enter the second number: ";
// cin >> second;
// cout << "Enter the third number: ";
// cin >> third;
//
// return ((first + second + third) / 3);
//}
//7b
//9.4 Learn by Doing Exercises
//void GetInput(float& salary, int& years_service);
//void CalcRaise(float& salary, int years_service);
//int CalcBonus(int years_service);
//void PrintCalculations(int years_service, float salary, int bonus);
//int main()
//{
//defining variables
// float sal = 0; int years = 0;
//running functions
// GetInput(sal, years);
// CalcRaise(sal, years);
// int bonus = CalcBonus(years);
// PrintCalculations(years, sal, bonus);
// return 0;
//}
//void GetInput(float& salary, int& years_service)
//{
// cout << "Enter the employee's salary\n";
// cin >> salary;
// cout << "Enter the employee's years of service\n";
// cin >> years_service;
//}
//void CalcRaise(float& salary, int years_service)
//{
// if (years_service > 10)
// {
// salary *= 1.10;
// }
// else if (years_service < 10 && years_service > 5)
// {
// salary *= 1.05;
// }
// else
// {
// salary *= 1.02;
// }
//}
//int CalcBonus(int years_service)
//{
// int bonusCounter = (years_service / 2);
// return (bonusCounter * 500);
//}
//void PrintCalculations(int years_service, float salary, int bonus)
//{
// cout << endl << "The employee's new salary will be " << salary << ", and they will receive a bonus of " << bonus;
//}
//7c
//9.5 Learn by Doing Exercises
void getTime(int &hours, int &minutes, int &seconds);
void displayTime(int hours, int minutes, int seconds, int style);
int main()
{
//defining local variables
int hrs = 0; int mins = 0; int secs = 0; char styleChoice = 0; int style = 0;
//get time
getTime(hrs, mins, secs);
//style
cout << endl << "Press 'd' for default, press 'm' for style menu." << endl;
cin >> styleChoice;
do
{
if (styleChoice == 'm')
{
cout << "Press 1 for 24 hour notation, 2 for military time, or 3 for standard format." << endl;
cin >> style;
cout << endl;
if (style > 3 || style < 1)
{
cout << "Error: number other than 1, 2, or 3 entered." << endl;
}
}
else if (styleChoice == 'd')
{
cout << endl;
style = 3;
}
} while (style > 3 || style < 1);
//time display function
displayTime(hrs, mins, secs, style);
//exit
return 0;
}
void getTime(int& hours, int& minutes, int& seconds)
{
do
{
cout << "Input the current hours (0-23)\n";
cin >> hours;
cout << endl;
if (hours < 0 || hours > 23)
{
cout << "Error: value outside of the range 0-23 entered." << endl;
}
} while (hours < 0 || hours > 23);
do
{
cout << "Input the current minutes (0-59)\n";
cin >> minutes;
cout << endl;
if (minutes < 0 || minutes > 59)
{
cout << "Error: value outside of the range 0-59 entered." << endl;
}
} while (minutes < 0 || minutes > 59);
do
{
cout << "Input the current seconds (0-59)\n";
cin >> seconds;
cout << endl;
if (seconds < 0 || seconds > 59)
{
cout << "Error: value outside of the range 0-59 entered." << endl;
}
} while (seconds < 0 || seconds > 59);
}
void displayTime(int hours, int minutes, int seconds, int displayStyle)
{
cout << "The current time: ";
if (displayStyle == 1)
{
if (hours < 10)
{
cout << "0" << hours << ":";
}
else
{
cout << hours << ":";
}
if (minutes < 10)
{
cout << "0" << minutes << ":";
}
else
{
cout << minutes << ":";
}
if (seconds < 10)
{
cout << "0" << seconds;
}
else
{
cout << seconds;
}
cout << " in 24 hour notation" << endl;
}
else if (displayStyle == 2)
{
if (hours < 10)
{
cout << "0" << hours;
}
else
{
cout << hours;
}
if (minutes < 10)
{
cout << "0" << minutes;
}
else
{
cout << minutes;
}
if (seconds < 10)
{
cout << "0" << seconds;
}
else
{
cout << seconds;
}
cout << " in military time" << endl;
}
else if (displayStyle == 3)
{
char AmPm = 'N';
if (hours > 12)
{
hours -= 12;
cout << hours << ":";
AmPm = 'P';
}
else if (hours == 12)
{
cout << hours << ":";
AmPm = 'P';
}
else
{
cout << hours << ":";
AmPm = 'A';
}
if (minutes < 10)
{
cout << "0" << minutes << ":";
}
else
{
cout << minutes << ":";
}
if (seconds < 10)
{
cout << "0" << seconds;
}
else
{
cout << seconds;
}
if (AmPm == 'A')
{
cout << "AM in standard format" << endl;
}
else if (AmPm == 'P')
{
cout << "PM in standard format" << endl;
}
}
}
|