M
Mountain Bikn' Guy
This code is used in a simple example calculator. It has a text box that
displays the result. It performs addition, subtraction, multiplication, etc.
on two operands. For the operands it accepts digits 0..9 and a decimal
point. The insert() method isn't very clear to me. Can anyone help me
convert the code shown below to C#?
Thanks!
enum { PRECISION = 14 };
//-------------------------------------------------------------------
void Calc::clear() {
myDisplay[0] = ' ';
myDisplay[1] = '0';
myDisplay[2] = '\0';
myIns = &myDisplay[1];
SetDlgItemText(myHwnd, IDC_DISPLAY, myDisplay);
}
//...................................................................
void Calc::insert(int keyId) {
if (myIns < &myDisplay[PRECISION - 1]) {
*myIns++ = (keyId == IDC_POINT) ? '.' : keyId - IDC_0 + '0';
*myIns = '\0';
SetDlgItemText(myHwnd, IDC_DISPLAY, myDisplay);
}
}
class Calc {
public:
Calc() {}
// helper methods...
void clear();
void insert(int keyId);
private:
char myDisplay[40];
char *myIns;
};
displays the result. It performs addition, subtraction, multiplication, etc.
on two operands. For the operands it accepts digits 0..9 and a decimal
point. The insert() method isn't very clear to me. Can anyone help me
convert the code shown below to C#?
Thanks!
enum { PRECISION = 14 };
//-------------------------------------------------------------------
void Calc::clear() {
myDisplay[0] = ' ';
myDisplay[1] = '0';
myDisplay[2] = '\0';
myIns = &myDisplay[1];
SetDlgItemText(myHwnd, IDC_DISPLAY, myDisplay);
}
//...................................................................
void Calc::insert(int keyId) {
if (myIns < &myDisplay[PRECISION - 1]) {
*myIns++ = (keyId == IDC_POINT) ? '.' : keyId - IDC_0 + '0';
*myIns = '\0';
SetDlgItemText(myHwnd, IDC_DISPLAY, myDisplay);
}
}
class Calc {
public:
Calc() {}
// helper methods...
void clear();
void insert(int keyId);
private:
char myDisplay[40];
char *myIns;
};