# Calculator Class?

Page 1 of 1

## 8 Replies - 2273 Views - Last Post: 16 November 2012 - 11:37 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=300280&amp;s=4e8aff95e955e98526f0fcc4c6d85044&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 HPLG

Reputation: 0
• 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:

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

• D.I.C Lover

Reputation: 1020
• Posts: 2,463
• 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".

### #3 HPLG

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

## Re: Calculator Class?

Posted 15 November 2012 - 01:49 AM

how do I do that??

### #4 Skydiver

• Code herder

Reputation: 4249
• Posts: 13,592
• Joined: 05-May 12

## Re: Calculator Class?

Posted 15 November 2012 - 06:18 AM

Just set a variable to store the pending operation.

### #5 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 4827
• Posts: 8,594
• 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.

• MrCupOfT

Reputation: 2292
• Posts: 9,531
• 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

### #7 Skydiver

• Code herder

Reputation: 4249
• Posts: 13,592
• 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.

### #8 tlhIn`toq

• Freelance developer

Reputation: 6094
• Posts: 13,442
• 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

### #9 heinbau

Reputation: 4
• 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!