Language Visual C++ 6.0 */
class CP2Doc:public CDocument
{
protected:
CP2Doc ();
DECLARE_DYNCREATE (CP2Doc);
double aa, ab, ac; // input
char ad [50]; // input string
int ag, ah, ai; // ag - pointer to input char in string <ad>, ah - flag of <Enter>
double aj;
int am [10]; // results
void bb (); // converting from <char> to <double>
void bc ();
}
CP2Doc::CP2Doc ()
{
ad [0] = 0; // input string to be displayed
aa = ab = ac = 0; // input double numbers
ag = ah = 0;
am [0] = 0; // output integer numbers
}
void CP2Doc::bb ()
{
ah = 1; // flag - user pressed <Enter>
ai = 0; // pointer in string <ad>; indicates the char to be analyzed
while ((ad [ai] < '0' || ad [ai] > '9') && ad [ai] != '-' && ad [ai] != '.' && ad [ai]) ai++;
bc ();
aa = aj;
while ((ad [ai] < '0' || ad [ai] > '9') && ad [ai] != '-' && ad [ai] != '.' && ad [ai]) ai++;
bc ();
ab = aj;
while ((ad [ai] < '0' || ad [ai] > '9') && ad [ai] != '-' && ad [ai] != '.' && ad [ai]) ai++;
bc ();
ac = aj;
}
void CP2Doc::bc ()
{
int a; // sign of collected number: +1 or -1
double b; // multiplier for decimal part of number
aj = 0; // collected double number
a = 1;
b = .1;
if (ad [ai] == '-') {a = -1; ai++;} // sign of number
while (ad [ai] >= '0' && ad [ai] <= '9') // integer part of number
{
aj = aj * 10 + ad [ai] - '0';
ai++;
}
if (ad [ai] == '.') // decimal part of number
{
ai++;
while (ad [ai] >= '0' && ad [ai] <= '9')
{
aj += (ad [ai] - '0') * b;
ai++;
b /= 10;
}
}
aj *= a;
}
void CP2View::OnDraw (CDC *pDC)
{
CP2Doc *pdoc = GetDocument ();
ASSERT_VALID (pdoc);
CString a; // output string
pDC -> TextOut (10, 10, "Input 3 float numbers:");
pDC -> TextOut (10, 35, pdoc -> ad);
a.Format ("code = %i", pdoc -> am [0]); // output of code of pressed key
pDC -> TextOut (10, 60, a);
if (pdoc -> ah) // flag - user pressed <Enter> to print results
{
a.Format ("%g %g %g", pdoc -> aa, pdoc -> ab, pdoc -> ac); // print 3 double
pDC -> TextOut (10, 85, a);
}
}
void CP2View::OnChar (UINT nChar, UINT nRepCnt, UINT nFlags)
{
CP2Doc *pdoc = GetDocument ();
ASSERT_VALID (pdoc);
pdoc -> am [0] = nChar; // analyzing pressed key
if (nChar == 8) // pressed <Backspace>
{
if (pdoc -> ag) {pdoc -> ag--; pdoc -> ad [pdoc -> ag] = 0;}
goto aaa;
}
if (nChar == 13) // pressed <Enter>
{
pdoc -> bb ();
goto aaa;
}
if (pdoc -> ag < 49) // adding symbol to string <ad>
{
pdoc -> ad [pdoc -> ag] = nChar;
pdoc -> ad [pdoc -> ag + 1] = 0;
pdoc -> ag++;
}
aaa:
Invalidate ();
CView::OnChar (nChar, nRepCnt, nFlags);
}
Присоединяйтесь — мы покажем вам много интересного
Присоединяйтесь к ОК, чтобы подписаться на группу и комментировать публикации.
Нет комментариев