6/24/10

Sum and reveres of a number(MFC)

Buzz It
#include
class myframe:public CFrameWnd
{CString str1;
char str2[22],str3[33];
CEdit e1,e2,e3;
CStatic t1,t2,t3;
CButton b1;
public:
myframe()
{
Create(0,"reverse");
}
void OnCreate()
{
t1.Create("Enter your number",WS_CHILDWS_VISIBLESS_CENTERIMAGE,CRect(20,333,44,555),this,0);
e1.CreateEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILDWS_VISIBLESS_CENTERIMAGE,CRect(200,33,404,55),this,1);
t2.Create("Reverse is",WS_CHILDWS_VISIBLESS_CENTERIMAGE,CRect(120,33,144,225),this,2);
e2.CreateEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILDWS_VISIBLESS_CENTERIMAGE,CRect(120,323,104,55),this,3);
t3.Create("Sum is",WS_CHILDWS_VISIBLESS_CENTERIMAGE,CRect(120,33,144,225),this,4);
e3.CreateEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILDWS_VISIBLESS_CENTERIMAGE,CRect(200,33,404,55),this,5);
b1.Create("result",BS_PUSHBUTTONWS_CHILDWS_VISIBLE,CRect(250,300,410,350),this,6);
}
void fun()
{
if(e1.GetWindowTextLength()==0)
{
t1.SetWindowText("please enter number");
return;
}
int n=0,a=0,b=0,sum1=0;
e1.GetWindowText(str1);
sscanf(str1,"%d",&n);
int mod;
while(n!=0)
{
mod=n%10;
n=n/10;
b=b+mod;
sum1=(sum1*10)+mod;
}
sprintf(str2,"%d",b);
sprintf(str3,"%d",sum1);
e2.SetWindowText(str2);
e3.SetWindowText(str3);
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe, CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int initInstance()
{
myframe *p;
p=new myframe;
p->ShowWindow(1);
m_pMainWnd=p;
return 1;
}
};
myapp a;

OUTPUT

0 comments:

Post a Comment