diff options
Diffstat (limited to 'Project2_Fhernandez_BSchroeder/Project2_Fhernandez_BSchroeder.cpp')
| -rw-r--r-- | Project2_Fhernandez_BSchroeder/Project2_Fhernandez_BSchroeder.cpp | 530 |
1 files changed, 530 insertions, 0 deletions
diff --git a/Project2_Fhernandez_BSchroeder/Project2_Fhernandez_BSchroeder.cpp b/Project2_Fhernandez_BSchroeder/Project2_Fhernandez_BSchroeder.cpp new file mode 100644 index 0000000..da4457c --- /dev/null +++ b/Project2_Fhernandez_BSchroeder/Project2_Fhernandez_BSchroeder.cpp @@ -0,0 +1,530 @@ +// Project2_Scratch.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... +// +// +// +// +// 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. 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 |