Click here to Skip to main content
15,888,337 members
Home / Discussions / C#
   

C#

 
AnswerRe: calculator Pin
Eddy Vluggen26-Mar-09 8:08
professionalEddy Vluggen26-Mar-09 8:08 
GeneralRe: calculator Pin
the exile26-Mar-09 8:20
the exile26-Mar-09 8:20 
GeneralRe: calculator Pin
EliottA26-Mar-09 8:48
EliottA26-Mar-09 8:48 
QuestionRe: calculator Pin
CPallini26-Mar-09 8:09
mveCPallini26-Mar-09 8:09 
JokeRe: calculator Pin
Yusuf26-Mar-09 8:50
Yusuf26-Mar-09 8:50 
JokeRe: calculator Pin
CPallini26-Mar-09 9:04
mveCPallini26-Mar-09 9:04 
JokeRe: calculator Pin
0x3c026-Mar-09 9:35
0x3c026-Mar-09 9:35 
AnswerRe: calculator Pin
Roger Wright26-Mar-09 20:04
professionalRoger Wright26-Mar-09 20:04 
I'm not much of a programmer, but I'd start by modelling the data items as structs - one element for the real, the other for the imaginary part - then overload the operators to define complex functions.

For instance,

struct Complex
{
   public double Re, Im;
   public Complex(double Re, double Im)
   {
      this.Re = Re;
      this.Im = Im;
   }
   public Complex(Complex X)
   {
      Re = B.Re;
      Im = B.Im;
   }
   public static Complex operator + (Complex A, Complex B)
   {
      Complex result = new Complex(A);
      result.Re += B.Re;
      result.Im += B.Im;
   }
}


This defines a struct with two parts called Complex, with real and imaginary parts called Re and Im, respectively. Re and Im are declared as type double. Two constructors are declared, one being initialized with separate values, the other by a type Complex value. The last bit overloads the '+' operator to return a Complex sum of two Complex variables. You can add other operators to the mix by writing the code to implement them. Although structs do not have methods, operator overloads (which look just like methods) work on structs as well as classes. In your calculator application I'd define buttons to click for each overloaded operator, something like what Microsoft has done with the built in Windows Calculator utility.

By the way, I didn't write or test the above - I modified an example in a book I'm studying to fit your situation. You might want to pick up a copy and read it; "Professional C# 2005 with .Net 3.0" by Wrox Press. It's quite thorough and very readable.

"A Journey of a Thousand Rest Stops Begins with a Single Movement"

AnswerRe: calculator [modified] Pin
Alan Balkany27-Mar-09 3:59
Alan Balkany27-Mar-09 3:59 
Questionhow to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 7:31
robertkjr3d26-Mar-09 7:31 
AnswerRe: how to use a list array to populate a listbox with columns Pin
dan!sh 26-Mar-09 7:44
professional dan!sh 26-Mar-09 7:44 
GeneralRe: how to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 7:57
robertkjr3d26-Mar-09 7:57 
GeneralRe: how to use a list array to populate a listbox with columns Pin
dan!sh 26-Mar-09 8:15
professional dan!sh 26-Mar-09 8:15 
GeneralRe: how to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 8:25
robertkjr3d26-Mar-09 8:25 
GeneralRe: how to use a list array to populate a listbox with columns Pin
Fayu26-Mar-09 8:39
Fayu26-Mar-09 8:39 
GeneralRe: how to use a list array to populate a listbox with columns Pin
dan!sh 26-Mar-09 8:48
professional dan!sh 26-Mar-09 8:48 
AnswerRe: how to use a list array to populate a listbox with columns Pin
Fayu26-Mar-09 8:00
Fayu26-Mar-09 8:00 
GeneralRe: how to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 8:08
robertkjr3d26-Mar-09 8:08 
GeneralRe: how to use a list array to populate a listbox with columns Pin
Fayu26-Mar-09 8:37
Fayu26-Mar-09 8:37 
GeneralRe: how to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 8:43
robertkjr3d26-Mar-09 8:43 
GeneralRe: how to use a list array to populate a listbox with columns Pin
Henry Minute26-Mar-09 10:39
Henry Minute26-Mar-09 10:39 
QuestionEmbed a progress bar inside a treeview node Pin
JamieNS26-Mar-09 7:30
JamieNS26-Mar-09 7:30 
AnswerRe: Embed a progress bar inside a treeview node Pin
dan!sh 26-Mar-09 7:55
professional dan!sh 26-Mar-09 7:55 
QuestionArgument Exception appears in some computers but not in others Pin
VitroBlue26-Mar-09 7:15
VitroBlue26-Mar-09 7:15 
AnswerRe: Argument Exception appears in some computers but not in others Pin
Luc Pattyn26-Mar-09 8:44
sitebuilderLuc Pattyn26-Mar-09 8:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.