8 Replies - 1481 Views - Last Post: 16 November 2012 - 11:37 AM Rate Topic: -----

#1 HPLG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-November 12

Calculator Class?

Posted 14 November 2012 - 09:55 PM

I need to create a calculator class for my basic calculator application that will implement the functions of the Calculator?
The design of the calculator class should be in this:

Posted Image

this is what I have so far am really confused?:
    public class Calculator
    {
        private decimal currentValue;



        public Calculator()
        {
        }

        public Calculator(decimal currentValue)
        {
            this.CurrentValue = currentValue;
        }
        public decimal CurrnetValue
        {
            get
            {
                return currentValue;
            }
            set
            {
                currentValue = value;
            }

        }

        public decimal Add(decimal operand1, decimal operand2)
        {
            return operand1 + operand2;
            }
        public decimal Subtract(decimal operand1, decimal operand2)
        {
            return operand1 - operand2;
        }
        public decimal Multiply(decimal operand1, decimal operand2)
        {
            return operand1 * operand2;
            }
        
        public decimal Divide(decimal operand1, decimal operand2)
        {
            return operand1 / operand2;
            }

        
           
    }


Is This A Good Question/Topic? 0
  • +

Replies To: Calculator Class?

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Calculator Class?

Posted 15 November 2012 - 01:23 AM

Yes, you are confused. It says "Set the pending operation to" not "perform this operation".
Was This Post Helpful? 0
  • +
  • -

#3 HPLG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-November 12

Re: Calculator Class?

Posted 15 November 2012 - 01:49 AM

how do I do that??
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3531
  • View blog
  • Posts: 10,934
  • Joined: 05-May 12

Re: Calculator Class?

Posted 15 November 2012 - 06:18 AM

Just set a variable to store the pending operation.
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4451
  • View blog
  • Posts: 7,751
  • Joined: 08-June 10

Re: Calculator Class?

Posted 15 November 2012 - 07:21 AM

Look, I'm going to explain what's going on here. We can't do your homework for you, and the amount of help you need at this point would qualify as us doing it for you. You need to go talk to your teacher/professor/lab assistant and get some advice.

All we can really tell you is that the assignment wants you to have a pending operator, and only perform the operation in the equals method. That suggests to me you'll need some logic in the Equals method to determine what the current operator is, and then use it.
Was This Post Helpful? 1
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2250
  • View blog
  • Posts: 9,433
  • Joined: 29-May 08

Re: Calculator Class?

Posted 15 November 2012 - 07:32 PM

It'll help you, if work out the process of operation on paper first.
Let's start simply.

1
2

+ does do addition operation because there only one number been inputted.
Instead remembers what operator needs to perform.
Also need to do something else.
Can you think what that is?
Spoiler


2
3

= performs the stored operation on the two numbers.

Is there structure that can remember numbers and also help with calculating the result?
Spoiler

This post has been edited by AdamSpeight2008: 15 November 2012 - 07:35 PM

Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3531
  • View blog
  • Posts: 10,934
  • Joined: 05-May 12

Re: Calculator Class?

Posted 16 November 2012 - 06:26 AM

He doesn't even need a full blown stack of numbers and operations. Look at the requirements for his class, the EnterValue() method only needs to return the last two values, and the various methods named after math operations only needs to know the pending operation.

Of course, AdamSpeight2008's solution is much more general for later if/when the assignment gets expanded to do more.
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5464
  • View blog
  • Posts: 11,739
  • Joined: 02-June 10

Re: Calculator Class?

Posted 16 November 2012 - 09:15 AM

Q: I am making a calculator as my school homework project and ...
A: Calculator tutorial
Was This Post Helpful? 0
  • +
  • -

#9 heinbau  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 22
  • Joined: 08-November 12

Re: Calculator Class?

Posted 16 November 2012 - 11:37 AM

I think with where you are in the project (homework?) I'm not even sure if you understand whatyou're trying to do. I know you understand the concept of addition subtraction etc, but have you worked through the flow logic?

This is a fairly simple class that you're trying to come up with, and I was able to work the whole thing out on paper in just a few minutes. I only mention that because I am very new with programming, and I troll the forums to help teach myself.

My suggestion to you is to grab a sheet of paper, and turn your computer off. If you play around with pen and paper you will be able to work through it easily! You're just missing a few key things, and once you think it through it'll be very obvious :)

I promise!

Good luck!
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1