This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:jcavalu3:portfolio:cprogproject3 [2012/05/07 20:54] – [Code] jcavalu3 | user:jcavalu3:portfolio:cprogproject3 [2012/05/09 20:22] (current) – [Code] jcavalu3 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Project: | ||
+ | A project for C/C++ Programming by Josh Cavaluzzi during the Spring 2012. | ||
+ | |||
+ | This project was begun on Some Date and is anticipated to take a while to complete. Project was completed on May 7, 2012. | ||
+ | |||
+ | =====Objectives===== | ||
+ | State the purpose of this project. What is the point of this project? What do we hope to accomplish by undertaking it? | ||
+ | |||
+ | =====Prerequisites===== | ||
+ | In order to successfully accomplish/ | ||
+ | |||
+ | * successful completion of project #1 and solid understanding of pertinent topics | ||
+ | * successful implementation of addition and subtraction from project #2 in working functions | ||
+ | * familiarity with memory allocation via **malloc(3)** | ||
+ | * familiarity with memory, accessing data via pointer dereferencing, | ||
+ | * familiarity with looking up C function parameters/ | ||
+ | * familiarity with C++ classes | ||
+ | * familiarity with functions, their parameters and return types | ||
+ | * familiarity with multi-file programs, how to make and build them | ||
+ | |||
+ | =====Background===== | ||
+ | State the idea or purpose of the project. What are you attempting to pursue? | ||
+ | |||
+ | You'll want to fill this section out with more detailed background information. DO NOT JUST PROVIDE A LINK. | ||
+ | |||
+ | Providing any links to original source material, such as from a project page, is a good idea. | ||
+ | |||
+ | You'll want to give a general overview of what is going to be accomplished (for example, if your project is about installing a web server, do a little write-up on web servers. What is it, why do we need one, how does it work, etc.) | ||
+ | |||
+ | =====Scope===== | ||
+ | Project #2 was to be an awesome exploration of array manipulation and functions, built atop a comfortable yet easy foundation of simple mathematics. | ||
+ | |||
+ | As it turns out, procrastination and refusal to work out ideas on paper are killer obstacles. | ||
+ | |||
+ | This project will therefore ebrace and extend upon project #2, where you will finish implementing code to support the storage and manipulation of numbers outside of the established data types. And once you have that, we'll do some additional modifications to reflect concepts covered is class. | ||
+ | |||
+ | So, for this project I'd like for you to: | ||
+ | |||
+ | * have working addition, subtraction, | ||
+ | * definitely get multiplication and division working | ||
+ | * also implement a **modulus** and **exponent** function | ||
+ | * verify successful operation with numbers of length 8, 16, 24, and 32 | ||
+ | * split your code up into **multiple files** (have at least one header file, a main.c, and two additional C files with various functions in them) | ||
+ | * have these **multiple files** successfully compile and operate just as your monolithic code would | ||
+ | * ALSO (aka "in addition to" your C solution, I'd like you to also implement a **class-based solution** in monolithic and multiple files in **C++**). So you will have a pure C implementation AND a class-based C++ implementation. | ||
+ | |||
+ | Some helpful hints: | ||
+ | |||
+ | * WORK IT OUT ON PAPER. | ||
+ | * WORK IT OUT ON PAPER. | ||
+ | * WORK IT OUT ON PAPER. | ||
+ | * WORK IT OUT ON PAPER. | ||
+ | * get the C version working before you even start on the C++ (it'll make more sense) | ||
+ | * when you get to coding, be sure to use the debugger to see what is actually happening | ||
+ | * chars are just numbers | ||
+ | * strings can make things complicated | ||
+ | * just focus on chars being numbers | ||
+ | * if confused, WORK IT OUT ON PAPER. | ||
+ | |||
+ | If you don't understand what "WORK IT OUT ON PAPER" means, it means to go through several STEP-BY-STEP iterations BY HAND of some of the very math operations you'd expect your program to ultimately perform. | ||
+ | |||
+ | Try it out for yourself- pick two arbitrary 8-digit numbers, and ADD them together. BY HAND. Note how you calculate the individual sums and carries. Watch how the carries propagate from right to left. | ||
+ | |||
+ | Do the some for subtraction, | ||
+ | |||
+ | Can you define multiplication in terms of addition? | ||
+ | |||
+ | Can you define division in terms of subtraction? | ||
+ | |||
+ | =====Code===== | ||
+ | |||
+ | The **Functions.h** file: | ||
+ | |||
+ | <code c> | ||
+ | GNU nano 2.2.4 File: Functions.h | ||
+ | |||
+ | #ifndef _FUNCTION_H | ||
+ | #define _FUNCTION_H | ||
+ | |||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | class Functions{ | ||
+ | public: | ||
+ | void printary( int, char* ); | ||
+ | char* mkArray( int ); | ||
+ | char* mkZero( int, char* ); | ||
+ | char* Addition( int, char*, char* ); | ||
+ | char* Subtraction( int, char*, char* ); | ||
+ | char* Multiplication( int, char*, char* ); | ||
+ | char* Exponents( int, char* ); | ||
+ | int Modulous( int, char*, char* ); | ||
+ | int Division( int, char*, char* ); | ||
+ | int compare( char*, int ); | ||
+ | int compare2( char*, char* ); | ||
+ | }; | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | |||
+ | The math.cc file (Holds all of the functions, not the prototypes): | ||
+ | |||
+ | <code c> | ||
+ | #include " | ||
+ | |||
+ | void Functions:: | ||
+ | { | ||
+ | char count; | ||
+ | for( count = 0; count < size; count++ ) | ||
+ | { | ||
+ | printf(" | ||
+ | } | ||
+ | printf(" | ||
+ | } | ||
+ | |||
+ | char * Functions:: | ||
+ | { | ||
+ | char *array; | ||
+ | array = (char *) malloc (sizeof(char) * size); | ||
+ | return array; | ||
+ | } | ||
+ | |||
+ | char * Functions:: | ||
+ | { | ||
+ | char count; | ||
+ | for( count = 0; count <= size; count++ ) | ||
+ | { | ||
+ | *( array + count ) = 0; | ||
+ | } | ||
+ | return array; | ||
+ | } | ||
+ | |||
+ | char * Functions:: | ||
+ | { | ||
+ | int count; | ||
+ | |||
+ | int answer = 0; | ||
+ | char *addition, *carry; | ||
+ | |||
+ | // Allocating memory for the return array and the carry array | ||
+ | |||
+ | addition = mkArray( size ); | ||
+ | carry = mkArray( size ); | ||
+ | |||
+ | // Setting the array elements equal to zero | ||
+ | |||
+ | mkZero( size, addition ); | ||
+ | mkZero( size, carry ); | ||
+ | |||
+ | // For loop to perform the addition | ||
+ | |||
+ | for( count = size; count >= 0; count-- ) | ||
+ | { | ||
+ | answer = (*(array1 + count) + *(array2 + count) + *(carry + count)); | ||
+ | if(answer > 9) | ||
+ | { | ||
+ | answer = answer - 10; | ||
+ | *(carry + (count - 1)) = 1; | ||
+ | } | ||
+ | *(addition + count) = answer; | ||
+ | } | ||
+ | return addition; | ||
+ | } | ||
+ | |||
+ | char * Functions:: | ||
+ | { | ||
+ | int count; | ||
+ | int answer = 0; | ||
+ | char *subtraction, | ||
+ | |||
+ | // Allocating memory for the arrays | ||
+ | |||
+ | subtraction = mkArray( size ); | ||
+ | carry = mkArray( size ); | ||
+ | |||
+ | // Making the values of the elements of each array zero | ||
+ | |||
+ | mkZero( size, subtraction ); | ||
+ | mkZero( size, carry ); | ||
+ | |||
+ | // For loop to perform subtraction | ||
+ | |||
+ | for( count = (size - 1); count >= 0; count-- ) | ||
+ | { | ||
+ | answer = (*(array1 + count) - *(array2 + count) - *(carry + count)); | ||
+ | if( answer < 0 ) | ||
+ | { | ||
+ | answer = answer + 10; | ||
+ | *(carry + (count - 1)) = 1; | ||
+ | } | ||
+ | *(subtraction + count) = answer; | ||
+ | } | ||
+ | return subtraction; | ||
+ | } | ||
+ | |||
+ | char * Functions:: | ||
+ | { | ||
+ | char *multiplication, | ||
+ | |||
+ | // Creating a new size variable to account for the larger numbered results, as well as $ | ||
+ | // the program to print out the result correctly | ||
+ | |||
+ | int size2, offset; | ||
+ | offset = sizeof(char) * size ; | ||
+ | size2 = size + size; | ||
+ | |||
+ | // Allocating the memory for the new appended arrays | ||
+ | |||
+ | appended1 = mkArray( size2 ); | ||
+ | appended2 = mkArray( size2 ); | ||
+ | |||
+ | // Setting each element equal to zero | ||
+ | |||
+ | mkZero( size2, appended1 ); | ||
+ | mkZero( size2, appended2 ); | ||
+ | |||
+ | // Copying the memory of the arrays into the new appended arrays, and including the off$ | ||
+ | // to make sure that the values are at the end of the memory, instead of in the middle | ||
+ | |||
+ | memcpy( appended1 + offset, array1, offset ); | ||
+ | memcpy( appended2 + offset, array2, offset ); | ||
+ | |||
+ | // Allocating memory in the multiplication array and setting the elements equal to zero | ||
+ | |||
+ | multiplication = mkArray( size2 ); | ||
+ | multiplication = mkZero( size2, multiplication ); | ||
+ | |||
+ | // The same thing as the multiplication array, except this array only holds the number $ | ||
+ | // to decrement the second array | ||
+ | |||
+ | one = mkArray( size2 ); | ||
+ | one = mkZero( size2, one ); | ||
+ | *( one + ( size2 - 1 ) ) = 1; | ||
+ | |||
+ | // A holder array to keep the results in check | ||
+ | |||
+ | holder = mkArray( size2 ); | ||
+ | mkZero( size2, holder ); | ||
+ | |||
+ | int x; | ||
+ | |||
+ | // The while loop has the second appended array check with the number zero, and if all $ | ||
+ | // function returns a 1, which then quits | ||
+ | |||
+ | while( compare( appended2, size2 ) == 0 ) | ||
+ | { | ||
+ | x = compare( appended2, size2 ); | ||
+ | holder = Addition( size2, holder, appended1 ); | ||
+ | appended2 = Subtraction( size2, appended2, one ); | ||
+ | } | ||
+ | multiplication = holder; | ||
+ | return multiplication; | ||
+ | } | ||
+ | |||
+ | int Functions:: | ||
+ | { | ||
+ | |||
+ | int result = 1; | ||
+ | |||
+ | while( compare2( array1, array2 ) == 1 ) | ||
+ | { | ||
+ | result++; | ||
+ | array1 = Subtraction( size, array1, array2 ); | ||
+ | } | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | int Functions:: | ||
+ | { | ||
+ | |||
+ | int result = 0; | ||
+ | |||
+ | if( compare2( array1, array2 ) == 0 ) | ||
+ | { | ||
+ | result = 1; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | while( compare2( array1, array2 ) == 1 ) | ||
+ | { | ||
+ | result++; | ||
+ | array1 = Subtraction( size, array1, array2 ); | ||
+ | } | ||
+ | } | ||
+ | printary( size, array1 ); | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | char* Functions:: | ||
+ | { | ||
+ | int power = 0, powersize = 0, size2 = 0; | ||
+ | char *exponent, *one, *holder, *appended1; | ||
+ | |||
+ | fprintf( stdout, " | ||
+ | fscanf(stdin, | ||
+ | |||
+ | int offset; | ||
+ | offset = sizeof(char) * size; | ||
+ | size2 = size + size; | ||
+ | |||
+ | appended1 = mkArray( size2 ); | ||
+ | |||
+ | mkZero( size2, appended1 ); | ||
+ | |||
+ | memcpy( appended1 + offset, array1, offset ); | ||
+ | |||
+ | exponent = mkArray( size2 ); | ||
+ | exponent = mkZero( size2, exponent ); | ||
+ | |||
+ | one = mkArray( size2 ); | ||
+ | one = mkZero( size2, one ); | ||
+ | *( one + ( size2 - 1 ) ) = 1; | ||
+ | |||
+ | holder = mkArray( size2 + size2 ); | ||
+ | mkZero( size2 + size2, holder ); | ||
+ | memcpy( holder + offset, array1, offset ); | ||
+ | |||
+ | char *extra; | ||
+ | extra = mkArray( size2 ); | ||
+ | mkZero( size2, extra ); | ||
+ | |||
+ | while( power > 1 ) | ||
+ | { | ||
+ | holder = Multiplication( size2, holder, appended1 ); | ||
+ | memcpy( extra, holder + size2, size2 ); | ||
+ | holder = extra; | ||
+ | power--; | ||
+ | } | ||
+ | exponent = holder; | ||
+ | return exponent; | ||
+ | } | ||
+ | |||
+ | // For multiplication only | ||
+ | |||
+ | int Functions:: | ||
+ | { | ||
+ | int count; | ||
+ | for( count = 0; count < size; count++ ) | ||
+ | { | ||
+ | if( array2[count] != 0 && array2[count] != ' | ||
+ | { | ||
+ | return 0; | ||
+ | } | ||
+ | } | ||
+ | return 1; | ||
+ | } | ||
+ | |||
+ | // For division and modulus | ||
+ | |||
+ | int Functions:: | ||
+ | { | ||
+ | int count, returnVal = 0; | ||
+ | |||
+ | for( count = 0; count < sizeof(array1); | ||
+ | { | ||
+ | if( array1[ count ] > array2[ count ] ) | ||
+ | { | ||
+ | returnVal = 1; | ||
+ | break; | ||
+ | } | ||
+ | else if (array1[count] < array2[count]) | ||
+ | { | ||
+ | returnVal = -1; | ||
+ | break; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | return returnVal; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | **THE MAIN FUNCTION FILE:** | ||
+ | |||
+ | <code c> | ||
+ | #include " | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | Functions *useFunction = new Functions(); | ||
+ | char *array1, *array2, *result, menuchoice; | ||
+ | int size, size1, size2, i, intResult; | ||
+ | |||
+ | fprintf(stdout, | ||
+ | fscanf(stdin, | ||
+ | fprintf(stdout, | ||
+ | fscanf(stdin, | ||
+ | |||
+ | if( size1 > size2 ) | ||
+ | size = size1; | ||
+ | else | ||
+ | size = size2; | ||
+ | |||
+ | size = size + 1; | ||
+ | |||
+ | // Creating the arrays | ||
+ | |||
+ | array1 = useFunction -> mkArray( size ); | ||
+ | array2 = useFunction -> mkArray( size ); | ||
+ | result = useFunction -> mkArray( size * 5 ); | ||
+ | |||
+ | // Making the array values zero | ||
+ | |||
+ | array1 = useFunction -> mkZero( size, array1 ); | ||
+ | array2 = useFunction -> mkZero( size, array2 ); | ||
+ | result = useFunction -> mkZero( size * 5, result ); | ||
+ | |||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | |||
+ | fgetc(stdin); | ||
+ | |||
+ | for(i = 0; i <= size; i++) | ||
+ | { | ||
+ | *(array1 + i) = fgetc(stdin) - 48; | ||
+ | } | ||
+ | useFunction -> printary( size, array1 ); | ||
+ | |||
+ | fprintf(stdout, | ||
+ | |||
+ | // Next, I created a prompt to have the user input the next number. | ||
+ | |||
+ | fprintf(stdout, | ||
+ | |||
+ | for(i = 0; i < size; i++) | ||
+ | { | ||
+ | *(array2 + i) = fgetc(stdin) - 48; | ||
+ | } | ||
+ | useFunction -> printary( size, array2 ); | ||
+ | |||
+ | fprintf(stdout, | ||
+ | |||
+ | // Beginning the switch block allowing the user to choose what he/she wants to do with the numbers | ||
+ | |||
+ | fprintf(stdout, | ||
+ | printf(" | ||
+ | |||
+ | fgetc(stdin); | ||
+ | menuchoice = fgetc(stdin); | ||
+ | switch( menuchoice ) | ||
+ | { | ||
+ | case' | ||
+ | fprintf(stdout, | ||
+ | result = useFunction -> Addition( size, array1, array2 ); | ||
+ | fprintf(stdout, | ||
+ | useFunction -> printary( size, result ); | ||
+ | fprintf(stdout, | ||
+ | break; | ||
+ | case' | ||
+ | fprintf(stdout, | ||
+ | result = useFunction -> Subtraction( size, array1, array2 ); | ||
+ | fprintf(stdout, | ||
+ | useFunction -> printary( size, result ); | ||
+ | fprintf(stdout, | ||
+ | break; | ||
+ | case' | ||
+ | fprintf(stdout, | ||
+ | result = useFunction -> Multiplication( size, array1, array2 ); | ||
+ | fprintf(stdout, | ||
+ | useFunction -> printary( size + size, result ); | ||
+ | fprintf(stdout, | ||
+ | break; | ||
+ | case' | ||
+ | fprintf(stdout, | ||
+ | intResult = useFunction -> Division( size, array1, array2 ); | ||
+ | fprintf(stdout, | ||
+ | break; | ||
+ | case' | ||
+ | fprintf(stdout, | ||
+ | result = useFunction -> Exponents( size, array1 ); | ||
+ | fprintf(stdout, | ||
+ | useFunction -> printary( size + size, result ); | ||
+ | break; | ||
+ | case' | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | useFunction -> Modulous( size, array1, array2 ); | ||
+ | break; | ||
+ | case' | ||
+ | fprintf(stdout, | ||
+ | break; | ||
+ | default: | ||
+ | fprintf(stdout, | ||
+ | break; | ||
+ | } | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | =====Execution===== | ||
+ | |||
+ | |||
+ | |||
+ | Addition: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | How many digits is the first number (preferably the larger): 6 | ||
+ | |||
+ | How many digits is the second number: 4 | ||
+ | Next, the program will ask you to input the numbers that you want to be stored. | ||
+ | You MUST add one zero to the beginning of the first number, or else the program will not run correctly. | ||
+ | Also, for the second number, add in enough zeros to the beginning so that the length matches that of the first number. | ||
+ | If you would like to perform an operation with an exponent, just input the number that you are raising to a power, and then just follow the directions and choose exponents. | ||
+ | |||
+ | Please enter the number that you want to be stored: 0567389 | ||
+ | 0567389 | ||
+ | |||
+ | |||
+ | Please enter the number that you want to be stored: 0005873 | ||
+ | 0005873 | ||
+ | |||
+ | |||
+ | What would you like to do with these numbers? Choose: | ||
+ | 1. Addition | ||
+ | 2. Subtraction | ||
+ | 3. Multiplication | ||
+ | 4. Divison | ||
+ | 5. Exponents | ||
+ | 6. Modulus | ||
+ | 7. Quit | ||
+ | Enter now: 1 | ||
+ | You have chosen Addition. | ||
+ | The result is: 0573262 | ||
+ | |||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Subtraction: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | How many digits is the first number (preferably the larger): 24 | ||
+ | |||
+ | How many digits is the second number: 23 | ||
+ | Next, the program will ask you to input the numbers that you want to be stored. | ||
+ | You MUST add one zero to the beginning of the first number, or else the program will not run correctly. | ||
+ | Also, for the second number, add in enough zeros to the beginning so that the length matches that of the first number. | ||
+ | If you would like to perform an operation with an exponent, just input the number that you are raising to a power, and then just follow the directions and choose exponents. | ||
+ | |||
+ | Please enter the number that you want to be stored: 0983762783761238473281987 | ||
+ | 0983762783761238473281987 | ||
+ | |||
+ | |||
+ | Please enter the number that you want to be stored: 0091111112233445566778899 | ||
+ | 0091111112233445566778899 | ||
+ | |||
+ | |||
+ | What would you like to do with these numbers? Choose: | ||
+ | 1. Addition | ||
+ | 2. Subtraction | ||
+ | 3. Multiplication | ||
+ | 4. Divison | ||
+ | 5. Exponents | ||
+ | 6. Modulus | ||
+ | 7. Quit | ||
+ | Enter now: 2 | ||
+ | You have chosen Subtraction. | ||
+ | The result is: 0892651671527792906503088 | ||
+ | |||
+ | lab46: | ||
+ | |||
+ | </ | ||
+ | |||
+ | Multiplication: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | How many digits is the first number (preferably the larger): 6 | ||
+ | |||
+ | How many digits is the second number: 5 | ||
+ | Next, the program will ask you to input the numbers that you want to be stored. | ||
+ | You MUST add one zero to the beginning of the first number, or else the program will not run correctly. | ||
+ | Also, for the second number, add in enough zeros to the beginning so that the length matches that of the first number. | ||
+ | If you would like to perform an operation with an exponent, just input the number that you are raising to a power, and then just follow the directions and choose exponents. | ||
+ | |||
+ | Please enter the number that you want to be stored: 0123454 | ||
+ | 0123454 | ||
+ | |||
+ | |||
+ | Please enter the number that you want to be stored: 0012345 | ||
+ | 0012345 | ||
+ | |||
+ | |||
+ | What would you like to do with these numbers? Choose: | ||
+ | 1. Addition | ||
+ | 2. Subtraction | ||
+ | 3. Multiplication | ||
+ | 4. Divison | ||
+ | 5. Exponents | ||
+ | 6. Modulus | ||
+ | 7. Quit | ||
+ | Enter now: 3 | ||
+ | You have chosen Multiplication. | ||
+ | The result is: 00001524039630 | ||
+ | |||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Division: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | How many digits is the first number (preferably the larger): 8 | ||
+ | |||
+ | How many digits is the second number: 2 | ||
+ | Next, the program will ask you to input the numbers that you want to be stored. | ||
+ | You MUST add one zero to the beginning of the first number, or else the program will not run correctly. | ||
+ | Also, for the second number, add in enough zeros to the beginning so that the length matches that of the first number. | ||
+ | If you would like to perform an operation with an exponent, just input the number that you are raising to a power, and then just follow the directions and choose exponents. | ||
+ | |||
+ | Please enter the number that you want to be stored: 048828125 | ||
+ | 048828125 | ||
+ | |||
+ | |||
+ | Please enter the number that you want to be stored: 000000025 | ||
+ | 000000025 | ||
+ | |||
+ | |||
+ | What would you like to do with these numbers? Choose: | ||
+ | 1. Addition | ||
+ | 2. Subtraction | ||
+ | 3. Multiplication | ||
+ | 4. Divison | ||
+ | 5. Exponents | ||
+ | 6. Modulus | ||
+ | 7. Quit | ||
+ | Enter now: 4 | ||
+ | You have chosen Division. | ||
+ | The result is: 1953125 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Exponents: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | How many digits is the first number (preferably the larger): 1 | ||
+ | |||
+ | How many digits is the second number: 1 | ||
+ | Next, the program will ask you to input the numbers that you want to be stored. | ||
+ | You MUST add one zero to the beginning of the first number, or else the program will not run correctly. | ||
+ | Also, for the second number, add in enough zeros to the beginning so that the length matches that of the first number. | ||
+ | If you would like to perform an operation with an exponent, just input the number that you are raising to a power, and then just follow the directions and choose exponents. | ||
+ | |||
+ | Please enter the number that you want to be stored: 06 | ||
+ | 06 | ||
+ | |||
+ | |||
+ | Please enter the number that you want to be stored: 01 | ||
+ | 01 | ||
+ | |||
+ | |||
+ | What would you like to do with these numbers? Choose: | ||
+ | 1. Addition | ||
+ | 2. Subtraction | ||
+ | 3. Multiplication | ||
+ | 4. Divison | ||
+ | 5. Exponents | ||
+ | 6. Modulus | ||
+ | 7. Quit | ||
+ | Enter now: 5 | ||
+ | You have chosen Exponents. | ||
+ | Please enter the value of the power that you are using: 5 | ||
+ | The result is: 7776 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Modulus: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | How many digits is the first number (preferably the larger): 4 | ||
+ | |||
+ | How many digits is the second number: 3 | ||
+ | Next, the program will ask you to input the numbers that you want to be stored. | ||
+ | You MUST add one zero to the beginning of the first number, or else the program will not run correctly. | ||
+ | Also, for the second number, add in enough zeros to the beginning so that the length matches that of the first number. | ||
+ | If you would like to perform an operation with an exponent, just input the number that you are raising to a power, and then just follow the directions and choose exponents. | ||
+ | |||
+ | Please enter the number that you want to be stored: 01234 | ||
+ | 01234 | ||
+ | |||
+ | |||
+ | Please enter the number that you want to be stored: 00123 | ||
+ | 00123 | ||
+ | |||
+ | |||
+ | What would you like to do with these numbers? Choose: | ||
+ | 1. Addition | ||
+ | 2. Subtraction | ||
+ | 3. Multiplication | ||
+ | 4. Divison | ||
+ | 5. Exponents | ||
+ | 6. Modulus | ||
+ | 7. Quit | ||
+ | Enter now: 6 | ||
+ | You have chosen Modulus. | ||
+ | The result is: 00004 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Quit: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | How many digits is the first number (preferably the larger): 1 | ||
+ | |||
+ | How many digits is the second number: 1 | ||
+ | Next, the program will ask you to input the numbers that you want to be stored. | ||
+ | You MUST add one zero to the beginning of the first number, or else the program will not run correctly. | ||
+ | Also, for the second number, add in enough zeros to the beginning so that the length matches that of the first number. | ||
+ | If you would like to perform an operation with an exponent, just input the number that you are raising to a power, and then just follow the directions and choose exponents. | ||
+ | |||
+ | Please enter the number that you want to be stored: 01 | ||
+ | 01 | ||
+ | |||
+ | |||
+ | Please enter the number that you want to be stored: 01 | ||
+ | 01 | ||
+ | |||
+ | |||
+ | What would you like to do with these numbers? Choose: | ||
+ | 1. Addition | ||
+ | 2. Subtraction | ||
+ | 3. Multiplication | ||
+ | 4. Divison | ||
+ | 5. Exponents | ||
+ | 6. Modulus | ||
+ | 7. Quit | ||
+ | Enter now: 7 | ||
+ | Have a great day! | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Default: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | How many digits is the first number (preferably the larger): 1 | ||
+ | |||
+ | How many digits is the second number: 1 | ||
+ | Next, the program will ask you to input the numbers that you want to be stored. | ||
+ | You MUST add one zero to the beginning of the first number, or else the program will not run correctly. | ||
+ | Also, for the second number, add in enough zeros to the beginning so that the length matches that of the first number. | ||
+ | If you would like to perform an operation with an exponent, just input the number that you are raising to a power, and then just follow the directions and choose exponents. | ||
+ | |||
+ | Please enter the number that you want to be stored: 01 | ||
+ | 01 | ||
+ | |||
+ | |||
+ | Please enter the number that you want to be stored: 01 | ||
+ | 01 | ||
+ | |||
+ | |||
+ | What would you like to do with these numbers? Choose: | ||
+ | 1. Addition | ||
+ | 2. Subtraction | ||
+ | 3. Multiplication | ||
+ | 4. Divison | ||
+ | 5. Exponents | ||
+ | 6. Modulus | ||
+ | 7. Quit | ||
+ | Enter now: 8 | ||
+ | You haven' | ||
+ | lab46: | ||
+ | </ | ||
+ | =====Reflection===== | ||
+ | This project was very interesting. The Exponents function gave me a hard time, but I finally finished it, thank GREAT ODIN'S SPEAR!!! It helped me become reacquainted with C++, classes, and multiple file use. All-in-all, success! | ||
+ | |||
+ | =====References===== | ||
+ | In performing this project, the following resources were referenced: | ||
+ | |||
+ | * Karl Krauss | ||
+ | * Matt Hass | ||
+ | * http:// |