Table of Contents

Project: BIG NUM REDUX

A project for C/C++ by Stephanie Williams during the Spring Semester 2012.

This project was begun on April 1 and is anticipated to take one week to complete. Project was completed on April 6, 2012.

Objectives

This project is to fix some problems with project 2 as well as play with classes.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

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:

Some helpful hints:

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, multiplication, division, modulus, and exponent.

Can you define multiplication in terms of addition?

Can you define division in terms of subtraction?

Code

The C code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main()
{
        long long int numb1;
        long long int numb2;
        long long int total;
        int menu;
 
        printf("Enter a number: ");
        scanf("%lld", &numb1);
        printf("Enter another number: ");
        scanf("%lld", &numb2);
        printf("Enter selection\n");
        printf("1=addition\n");
        printf("2=subtraction\n");
        printf("3=multiplication\n");
        printf("4=division\n");
        printf("0=exit\n");
        scanf("%d", &menu);
 
        switch(menu){
                case 1: total=numb1+numb2; break;
                case 2: total=numb1-numb2; break;
                case 3: total=numb1*numb2; break;
                case 4: total=numb1/numb2; break;
        };
 
 
        if(menu==1)
        {
                printf("%lld plus %lld is %lld\n", numb1, numb2, total);
        }
        if(menu==2)
        {
                printf("%lld minus %lld is %lld\n", numb1, numb2, total);
        }
        if(menu==3)
        {
                printf("%lld times %lld is %lld\n", numb1, numb2, total);
        }
        if(menu==4)
        {
                printf("%lld divided by %lld is %lld\n", numb1, numb2, total);
        }
        if(menu=0)
        {
                printf("Hope you enjoyed your experience\n");
        }
        return(0);
}
 
 
 

C++ code

include <cstdio>
#include <stdlib>

int main()
{
        long long int numb1;
        long long int numb2;
        long long int total;
        int menu;

        printf("Enter a number: ");
        scanf("%lld", &numb1);
        printf("Enter another number: ");
        scanf("%lld", &numb2);
        printf("Enter selection\n");
        printf("1=addition\n");
        printf("2=subtraction\n");
        printf("3=multiplication\n");
        printf("4=division\n");
        printf("0=exit\n");
        scanf("%d", &menu);

        switch(menu){
         case 1: total=numb1+numb2; break;
                case 2: total=numb1-numb2; break;
                case 3: total=numb1*numb2; break;
                case 4: total=numb1/numb2; break;
        };


        if(menu==1)
        {
                printf("%lld plus %lld is %lld\n", numb1, numb2, total);
        }
        if(menu==2)
        {
                printf("%lld minus %lld is %lld\n", numb1, numb2, total);
        }
        if(menu==3)
        {
                printf("%lld times %lld is %lld\n", numb1, numb2, total);
        }
        if(menu==4)
        {
                printf("%lld divided by %lld is %lld\n", numb1, numb2, total);
        }
        if(menu=0)
        {
                printf("Hope you enjoyed your experience\n");
        }
        return(0);
}

Although the codes are the same they function differently

Execution

An example run of your code (be sure to show off all operations):

lab46:~/src/cprog$ ./big_num
Enter a number: 89764512378645
Enter another number: 5126674513
Enter selection
1=addition
2=subtraction
3=multiplication
4=division
0=exit
4
89764512378645 divided by 5126674513 is 17509
lab46:~/src/cprog$

Reflection

This project wasn't bad. much of the groundwork had already been done.

References

In performing this project, the following resources were referenced: