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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
|
// Project2_FHernandez_BSchroeder.cpp : This file contains the 'main' function. Program execution begins and ends there.
// Written by Ben Schroeder and Freddy Hernandez
// email:[email protected]
// email:[email protected]
// date: 10/30/2021 and periodically updated up to 11/07/2021
//
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Meetings:
// 10/26/2021 In-class meeting: Went over psuedocode for the various operation functions of the program. Took this home to review.
// 10/29/2021 Via Email: Discussing the "3rd set of data". Discussed the psuedocode. Questions about getting the project onto Github
// 10/30/2021 Via Email: BAS emailed updated code for a majority of the program created on 10/30 to FHJ for review and revising by FHJ.
// We also discussed possibly going of the code together over the weekend. If not over the weekend, early next week.
// 11/01/2021 Via Email: Scheduled an in-person meeting between FHJ and BAS to go over the updated code and plan for revisions.
// 11/02/2021 IN-PERSON Meeting:
// A) Revision list:
// 1) Fix the order of the flow of the program ( DisplayMenu(), ProcessMenuChoice, then GetData() in the specific
// operation functions that require the input number )
// -This will require changing function inputs as well as which function will be called from which functions
// a) Call DisplayMenu() in main() Change DisplayMenu() so that it requires NO INPUT, Call ProcessMenuChoice()
// from DisplayMenu()
// b) ProcessMenuChoice() option outputs will have to be altered because ProcessMenuChoice() will no longer
// have 'number' to work with
// c) Call GetData() from specific ProcessMenuChoice() options that require the input number (ie 1 thru 7)
// then call the option function with the number intact as they are already set up.
// d) GetData() should just return number and should not call any function
// 2) There is a glitch when choosing option 10 in ProcessMenuChoice(). It displays the menu one more time
// before exiting
// B) Create ReverseDigits(), (activate it in Prototypes as well in ProcessMenuChoice())
// C) See about getting the Project in the proper GitHub page. (ask Martha about where that is) This way we can each be
// updating the code with all the updates decribed for the other partner, in real time.
// D) Write up a TESTING PROCEDURE PLAN
// E) Prepare a suitable format for the Psuedocode to be presented (other than the penciled notes jotted down on paper)
// 11/04/2021 VIA EMAIL: Code updates emailed back and forth... Continuing edits and troubleshooting.
// 11/05/2021 Via Email: Documentaion details, submission questions etc...
// 11/07/2021 Via Phone and email: Updating the documentation...Finalization and Completion of Project
//
//
//
//
// Code Updates:
// 10/26/2021 Psuedocode drawn up on paper and reviewed by FHJ
// 10/30/2021 BAS created: int main(),int GetData(), void DisplayMenu(int&), int ProcessMenuChoice(int&), void IsPosNeg(int&),
// void IsOddEven(int&), void Sqrt(int&), void ChangeSign(int&), void NumDigits(int&), void DigitAtPosition(int&),
// void DisplayAdditionTable(), void DisplayMultiplicationTable() (Much testing NEEDS to be done)
// 11/01/2021 BAS added and tested the ChangeSign() function
// 11/01/2021 BAS fixed Sqrt() function to add clauses for 0 and negative numbers
// 11/01/2021 BAS fixed format of the Addition and Multiplication tables to make them look better
// 11/01/2021 BAS fixed IsOddEven() so that negative numbers could be evaluated... added abs(number)%2
// 11/01/2021 BAS updated documentation comments and meeting info.
// 11/02/2021 FHJ edited the functions to change the program flow. Now menu is displayed first, then the number
// is requested for functions 1 thru 7. This seems to be a more logical flow for the program to use.
// 11/03/2021 FHJ built and tested the ReverseDigits() function.
// 11/04/2021 Updated the program to better meet the requirements of the assignment (ie pass by value, pass by reference )
//
//
//
//
//
// AGILE QUESTIONS for Benjamin Schroeder
// (ie 1)What specific task? 2)What do I know about the specific task? 3)What do I not know about the specific task? )
// 10/26/2021 1) I will begin to draw up psuedocode for the functions in the project,
// 2) I know how to do most of the operations involved in the project, however,
// 3) I do not know how exactly to build the addition and multiplication tables.
// 10/30/2021 1) I will begin coding the program functions starting with GetData() and go down the list as they are introduced in
// ch7, 8, and 9.
// 2) I know I will be testing as I go, so I will see results pretty readily.
// 3) I do not know how to do 4 of the functions right off hand, the addition and multiplication tables, ReverseDigits(), and
// DigitAtPosition()
// 11/01/2021 1) I will begin running the program and see if I can find any things that need changing
// 2) I know I will find mistakes and unaesthetic problems in the program as the code is still very much a scratch draft.
// 3) Not sure if I will fix everything I see or wait to talk to Freddy about what his thoughts are on the Project.
// 11/04/2021 1) I will begin toubleshooting the program.
// 2) I will probably find some errors upon testing every function with: Positive, Negative, and Zero.
// 3) Not sure exactly where the errors are going to show up.
// - Found some major things that needed addressed. Fixed function inputs
// 11/05/2021 1) I will do some more rins of the program looking for errors or undesireable effects.
// 2) There is still a bit of a flow problem in the program, but all in all the program works as it should.
// 3) I don't know that anymore fixes need to take place.
//
//
//
// AGILE QUESTIONS for Freddy Hernandez
// (ie 1)What specific task? 2)What do I know about the specific task? 3)What do I not know about the specific task? )
//
//
//
//
//
//
//
//
//
//
//
//Testing Plan:
// Testing consists of running each function 1 thru 7 with 3 possibilities.Positive and negative numbers, and zero.
// The outputs should handle all three cases. Options 8 and 9 should display the respective Table without asking for
// a number input from the user. Option 10 should display a goodbye message.
// Test runs are included in the accompanying .txt file
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PSUEDOCODE:
//
// From main(), get the program started by displaying the menu (ie Call DisplayMenu() )
//
//
///////////////////////////////////
// void DisplayMenu()
// Show menu options
// int choice = somenumber
// int number = somenumber
// do
// ask for an option between 1 and 10
// record "choice" entered
// while ...the option number entered is out of that range
// if option is one of the first 7:
// Set "number" = GetData() (ie call GetData() )
// Call ProcessMenuChoice(choice, number)
//
//
////////////////////////////////////////
// int GetData()
// int number = outside of range
// while( number outside of range)
// ask for a number between -1000000 and 1000000
// record number
// return number
//
///////////////////////////////////////////
// void ProcessMenuCoice(choice, number)... ("number" is to be called by reference)
// use a switch case of (choice) to pick which function to call
// within each case, call the appropriate function to operate.
// (for functions 1 thru 7, there is an input variable "number" to use in the function.)
// (for functions 8 and 9, no input variable is required...they are only displaying couts.)
// (case 10 exits the program)
//
//
/////////////////////////////////////////////
// void IsPosNeg(number)
// There will be 3 possibilties, Positive, negative, and zero
// (If, If Else, and Else statements will be used for each possibility)
// If number > 0 ....cout number is positive
// If number < 0 ....cout number is negative
// If number == 0 .... cout zero is neither pos or neg
// Then Call DisplayMenu() to start the program back through
//
//
///////////////////////////////////////////
// void IsOddEven(number)
// Either the number leaves a remainder when divided by 2, or it does not.
// If there is a remainder from number%2, the number is odd.... cout odd
// If there is no remainder from number%2, the number is even... cout even
// Then call DisplayMenu() to start the program back through
//
//
////////////////////////////////////////////
// void Sqrt(number) (find the square root of the number)
// There will be 3 possibilties for this function: Positive numbers, negative, and or zero
// IF number > 0 ... use sqrt(number) ..cout the squareroot.
// IF number < 0 ... cout "negative numbers do not have squareroots"
// IF number ==0 ... cout " zero doesn't have a squareroot"
// Then call DisplayMenu() to start the program back through
//
//
////////////////////////////////////////////
// void ChangeSign(number)
// There are 2 possibilities for this function: Postive or negative numbers
// If number > 0 ...subtract the number from 0 and cout the result
// If number < 0 cout the absolute value of the number
// Then call DisplayMenu() to start the program back through
//
//
////////////////////////////////////////////
// void NumDigits(number)
// Every digit adds a factor OF 10 to the number...
// Dividing "number" by 10 and counting how many times we do this while the number is still >=1
// will give us how many digits the original number had.
// count = 0
// while (number >= 1)
// number = number/10
// count = count+1
// cout the count
// Then call DisplayMenu() to start the program back through
//
//
//////////////////////////////////////////////
// void DigitAtPos(number)
// Ask which digit the user wants to see ... record that int "digitPos"
// Then divide number by 10 to the power of 1 less than the digitPos desired
// then find the remainder when that result is divided by 10 once more.
// This will be the digit at the position that the user wanted to see.
// Then call DisplayMenu() to start the program back through
//
//
/////////////////////////////////////////////
// void ReverseDigits(number)
// find the remainder at each digit position by using number%10 and record this "remainder"
// Construct a "reversed number" by adding this remainder to an accumulative "reversed number *10"
// Iterate through the entire number by redefining the number to "itself divided by 10" (to more to the next digit position)
// cout the reversed number
// Then call DisplayMenu() to start the program back through
//
//
/////////////////////////////////////////////////
// void DisplatAdditionTable()
// This will be a 12 by 12 table
// we will need an array of numbers 1 thru 12 to represent the horizontal row at the top of the table
// We will need an additional array of numbers 1 thru 12 representing the vertical column on the left side of the table
// A for loop can be utilized to cout each row of the table by iterating through each entry of the vertical array
// A for loop within the above for loop will handle the calculations (adding results) of whichever horizontal item with
// the particular row (vertical item from the outside for loop) cout of each calculation will contruct the table row by row.
// Then call DisplayMenu() to start the program back through
//
//////////////////////////////////////////////////
// void DisplayMultiplicationTable()
// Similar to the addition table except with the contents being multiplication results
// Then call DisplayMenu() to start the program back through
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <math.h>
#include <iostream>
using namespace std;
//Function Prototypes
int GetData(); //ask for and returns the number input by the user
void DisplayMenu(); //Displays the menu of all of the program's options
void ProcessMenuChoice(int, int&); //Takes input from the user and directs the program to the various operation functions
void IsPosNeg(int); // Below are the various operation functions of the program
void IsOddEven(int);
void Sqrt(int);
void ChangeSign(int);
void NumDigits(int);
void DigitAtPosition(int);
void ReverseDigits(int);
void DisplayAdditionTable();
void DisplayMultiplicationTable();
int main()
{
DisplayMenu();
}
int GetData()
{
int number = 1000001;
do {
cout << "\nEnter a number between -1,000,000 and 1,000,000: ";
cin >> number;
} while (number < -1000000 || number >1000000);
return number;
}
void DisplayMenu()
{
cout << "***************************************************************************\n";
cout << "\tThis program can perform several mathematical operations\n";
cout << "***************************************************************************\n";
cout << "1) See if the number is Positive or Negative\n";
cout << "2) See if the number is Odd or Even.\n";
cout << "3) Find the square root of the number\n";
cout << "4) Change the sign of the number\n";
cout << "5) Determine how many digits the number has.\n";
cout << "6) Find the digit at a specific position in the number\n";
cout << "7) Reverse the digits in the number\n";
cout << "8) Display The Addition Table\n";
cout << "9) Display the Multiplication Table\n";
cout << "10) Exit\n";
cout << "***************************************************************************\n";
int choice = 10;
int number = 0;
do {
cout << "\t(Pick an option from 1 to 10): ";
cin >> choice;
} while (choice < 1 || choice >10);
if (choice < 8)
number = GetData();
ProcessMenuChoice(choice, number);
}
void ProcessMenuChoice(int choice, int& number)
{
switch (choice)
{
case 1:
cout << "\n 1) Positive or Negative\n";
IsPosNeg(number);
break;
case 2:
cout << "\n 2) Odd or Even.\n";
IsOddEven(number);
break;
case 3:
cout << "\n 3) Find the square root \n";
Sqrt(number);
break;
case 4:
cout << "\n 4) Change the sign\n";
ChangeSign(number);
break;
case 5:
cout << "\n 5) How many digits \n";
NumDigits(number);
break;
case 6:
cout << "\n 6) Find the digit at a specific position \n";
DigitAtPosition(number);
break;
case 7:
cout << "\n 7) Reverse the digits\n";
ReverseDigits(number);
break;
case 8:
cout << "\n\t The Addition Table\n";
DisplayAdditionTable();
break;
case 9:
cout << "\n\t The Multiplication Table\n";
DisplayMultiplicationTable();
break;
case 10:
cout << "\n\n\tThank you for using this program. Have a nice day!\n\n\n";
break;
}
}
//************************** FUNCTIONS FOR THE VARIOUS MENU OPTIONS ********************************************************************
void IsPosNeg(int number)
{
if (number > 0)
{
cout << "\t" << number << " is a positive number." << "\n\n";
}
else if (number < 0)
{
cout << "\t" << number << " is a negative number." << "\n\n";
}
else if (number == 0)
{
cout << "\t" << number << " is neither negative nor positive, it's zero." << "\n\n";
}
DisplayMenu();
}
void IsOddEven(int number)
{
int oddeven = abs(number) % 2;
if (oddeven > 0)
cout << "\t" << number << " is an odd number" << "\n\n";
else if (oddeven == 0)
cout << "\t" << number << " is an even number" << "\n\n";
DisplayMenu();
}
void Sqrt(int number)
{
if (number > 0)
{
float root = sqrt(number);
cout << "\t" << "The square root of " << number << " is: " << root << "\n\n";
}
else if (number < 0)
cout << "\t Negative numbers do not have square roots." << "\n\n";
else if (number == 0)
cout << "\t Zero doesn't have a square root." << "\n\n";
DisplayMenu();
}
void ChangeSign(int number)
{
int chngSign = number;
if (number >= 0)
chngSign = 0 - number;
else if (number < 0)
chngSign = abs(number);
cout << "\t" << "Changing the sign of " << number << " gives us " << chngSign << "\n\n";
DisplayMenu();
}
void NumDigits(int number)
{
int temp = number;
int i = 0;
while (abs(temp) >= 1)
{
temp = temp / 10;
i = i + 1;
}
cout << "\t" << number << " has " << i << " digits" << "\n\n";
DisplayMenu();
}
void DigitAtPosition(int number)
{
int digitPos = 1;
cout << "\t" << "Which digit position are you interested in?: ";
cin >> digitPos;
int temp = number;
temp = temp / pow(10, digitPos - 1);
temp = abs(temp % 10);
cout << "\t" << "Digit position #" << digitPos << " of " << number << " is: " << temp << "\n\n";
DisplayMenu();
}
void ReverseDigits(int number)
{
int n = number;
int remainder, reversedNumber = 0;
while (n != 0)
{
remainder = n % 10;
reversedNumber = reversedNumber * 10 + remainder;
n /= 10;
}
cout << "\t" << number << " reversed is: " << reversedNumber << "\n\n";
DisplayMenu();
}
void DisplayAdditionTable()
{
cout << "\n\n";
int numsH[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
int numsV[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
cout << " + | "; // top corner identifying Addition Table
for (int i = 0; i < 12; i++) //top line (numbers 1 thru 12)
{
if (numsH[i] >= 10)
{
cout << numsH[i] << " "; //proper spacing for one or two digit numbers
}
else
{
cout << numsH[i] << " ";
}
}
cout << "\n---|---------------------------------------\n";
for (int i = 0; i < 12; i++)
{
if (numsV[i] >= 10)
{
cout << numsV[i] << " | "; //left most column and vertical separator for the line
}
else
{
cout << numsV[i] << " | ";
}
for (int j = 0; j < 12; j++) // filling the rest of the addition table
{
if (numsV[i] + numsH[j] >= 10)
{
cout << numsV[i] + numsH[j] << " "; // again proper spacing
}
else
{
cout << numsV[i] + numsH[j] << " ";
}
}
cout << "\n";
}
cout << "\n\n";
DisplayMenu();
}
void DisplayMultiplicationTable()
{
cout << "\n\n";
int numsH[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
int numsV[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
cout << " x | "; //upper left corner identifying multiplication table
for (int i = 0; i < 12; i++) // top line 1 thru 12
{
if (numsH[i] >= 10)
{
cout << numsH[i] << " "; //spacing for 1 of 2 digit numbers per column
}
else
{
cout << numsH[i] << " ";
}
}
cout << "\n---|------------------------------------------------\n";
for (int i = 0; i < 12; i++)
{
if (numsV[i] >= 10) //left most comlumn and vertical separato
{
cout << numsV[i] << " | ";
}
else
{
cout << numsV[i] << " | ";
}
for (int j = 0; j < 12; j++) //filling in the rest of the multiplication tabl
{
if (numsV[i] * numsH[j] >= 100)
{
cout << numsV[i] * numsH[j] << " "; //again proper spacing for digits
}
else if (numsV[i] * numsH[j] >= 10)
{
cout << numsV[i] * numsH[j] << " ";
}
else
cout << numsV[i] * numsH[j] << " ";
}
cout << "\n";
}
cout << "\n\n";
DisplayMenu();
}
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
|