亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? calculatordlg.cpp

?? 有二叉樹計算表達式的值
?? CPP
字號:
// calculatorDlg.cpp : implementation file
//

#include "StdAfx.h"
#include "calculator.h"
#include "calculatorDlg.h"
#include "Usinghelp.h"
#include "math.h"
#include "ctype.h"
#include "string.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCalculatorDlg dialog

CCalculatorDlg::CCalculatorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCalculatorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCalculatorDlg)
	m_input = _T("");
	m_output = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCalculatorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCalculatorDlg)
	DDX_Text(pDX, IDC_EDIT1, m_input);
	DDX_Text(pDX, IDC_EDIT2, m_output);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCalculatorDlg, CDialog)
	//{{AFX_MSG_MAP(CCalculatorDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_PROCESS, OnButtonProcess)
	ON_BN_CLICKED(IDC_BUTTON_HELP, OnButtonHelp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCalculatorDlg message handlers

BOOL CCalculatorDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCalculatorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCalculatorDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCalculatorDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCalculatorDlg::OnButtonProcess() 
{
	UpdateData(TRUE);
	char str[100];
	for(int i=0;i<m_input.GetLength();i++)
		str[i]=m_input.GetAt(i);
	str[i]='\0';
	double value;
	value=compute(create(str));
	m_output.Format("%f",value);
	UpdateData(FALSE);
	
}


double CCalculatorDlg::compute(btree *bt)
{
	if(bt->left==NULL&&bt->right==NULL)
		switch(bt->oper.op)
		{
		case '+':return bt->left_num+bt->right_num;
		case '-':return bt->left_num-bt->right_num;
		case '*':return bt->left_num*bt->right_num;
		case '/':return bt->left_num/bt->right_num;
		case '^':return pow(bt->left_num,bt->right_num);
		}


	if(bt->left!=NULL&&bt->right==NULL)
		switch(bt->oper.op)
		{
		case '+':return compute(bt->left)+bt->right_num;
		case '-':return compute(bt->left)-bt->right_num;
		case '*':return compute(bt->left)*bt->right_num;
		case '/':return compute(bt->left)/bt->right_num;
		case '^':return pow(compute(bt->left),bt->right_num);
		}

	if(bt->left==NULL&&bt->right!=NULL)
		switch(bt->oper.op)
		{
		case '+':return bt->left_num+compute(bt->right);
		case '-':return bt->left_num-compute(bt->right);
		case '*':return bt->left_num*compute(bt->right);
		case '/':return bt->left_num/compute(bt->right);
		case '^':return pow(bt->left_num,compute(bt->right));

		}

	if(bt->left!=NULL&&bt->right!=NULL)
	     switch(bt->oper.op)
		{
		case '+':return compute(bt->left)+compute(bt->right);
		case '-':return compute(bt->left)-compute(bt->right);
		case '*':return compute(bt->left)*compute(bt->right);
		case '/':return compute(bt->left)/compute(bt->right);
		case '^':return pow(compute(bt->left),compute(bt->right));
		}
	return -1;

}

btree * CCalculatorDlg::create(char *str)
{
	btree *root,*current;//二叉樹的根節點和當前節點
	current=root=new btree;
	operation tmpoper;
	tmpoper.op=0;tmpoper.priority=0;
	double tmp=0.0,prev=0.0;
	int cnt=0,root_priority;//mid_prirotiy臨時存儲根節點運算符的優先級
	unsigned int i=0;
	int left_right=0;//用于判斷是給left_num,還是給right_num賦值
	int cntleftbracket=0,cntrightbracket=0;//左括號和右括號的個數
	current->left=NULL;
	current->right=NULL;
	current->parent=NULL;
	while(1)
	{
	  char ch;
		int dot=0;
//處理括號
		if(str[i]=='(')
		{
			cntleftbracket++;
			i++;
			for(unsigned int j=i;str[i];i++)
			{
				if(str[i]==')')cntrightbracket++;
				else if(str[i]=='(')cntleftbracket++;
				if(cntleftbracket==cntrightbracket)
				{
					char strbracket[100];
					for(int k=0;j<i;k++,j++)
						strbracket[k]=str[j];
					strbracket[k]='\0';
					tmp=compute(create(strbracket));
					prev=tmp;
					i++;
					break;
				}
			}
		}
		cntleftbracket=0;
		cntrightbracket=0;
//處理括號結束
	  int singed=1;
	  for(;i<strlen(str)&&(isdigit(str[i])||str[i]=='.'||str[i]=='-'&&!isdigit(str[i-1])&&i>0);i++)
	  {   ch=str[i];
			if(ch=='-')
			{
				singed=-1;
				continue;
			}
		   if(ch=='.')
			{
			 dot=1;
	 		  continue;
			}
		  if(dot==0)
			  tmp=(ch-0x30)+tmp*10.0;
		  else if(dot>0)
		  {
			  tmp+=(ch-0x30)*pow(10,-dot);
			  dot++;
		  }
	  }
	  tmp*=singed;
	  if(left_right==0)
		  current->left_num=tmp;
	  else if(left_right==1)
		current->right_num=tmp;
	  left_right=1-left_right;
	  prev=tmp;
	  tmp=0;
	  ch=str[i];
	  i++;
	  if(i>strlen(str))break;
	  if(cnt==0)
	  {
		switch(ch)
		{
			case '+':current->oper.op='+';current->oper.priority=1;break;
			case '-':current->oper.op='-';current->oper.priority=1;break;
			case '*':current->oper.op='*';current->oper.priority=2;break;
			case '/':current->oper.op='/';current->oper.priority=2;break;
			case '^':current->oper.op='^';current->oper.priority=3;break;
		}
		cnt++;
	  }
	  else
		   switch(ch)
			{
			case '+':tmpoper.op='+';tmpoper.priority=1;break;
			case '-':tmpoper.op='-';tmpoper.priority=1;break;
			case '*':tmpoper.op='*';tmpoper.priority=2;break;
			case '/':tmpoper.op='/';tmpoper.priority=2;break;
			case '^':tmpoper.op='^';tmpoper.priority=3;break;
			}
		root_priority=root->oper.priority;
	  if(tmpoper.priority>current->oper.priority)
	  {
		btree * tmpbt=new btree;
		tmpbt->left_num=prev;
		left_right=1;
		tmpbt->oper.op=tmpoper.op;
		tmpbt->oper.priority=tmpoper.priority;
		tmpbt->left=NULL;
		tmpbt->right=NULL;
		tmpbt->parent=current;
		current->right=tmpbt;
		current=tmpbt;
		cnt++;
	  }
	  else if(tmpoper.priority==current->oper.priority)
	  {
		  if(tmpoper.priority>root_priority)
		  {
			  btree *tmpbt=new btree;
			  left_right=1;
			  tmpbt->oper.op=tmpoper.op;
		      tmpbt->oper.priority=tmpoper.priority;
		      tmpbt->left=current;
		      tmpbt->right=NULL;
			  tmpbt->parent=current->parent;
			  current->parent->right=tmpbt;
			  current->parent=tmpbt;
		      current=tmpbt;
			  cnt++;
		  }
		  else if(tmpoper.priority==root_priority)
		  {
			  btree *tmpbt=new btree;
			  left_right=1;
			  tmpbt->oper.op=tmpoper.op;
			  tmpbt->oper.priority=tmpoper.priority;
			  tmpbt->left=root;
			  tmpbt->right=NULL;
			  tmpbt->parent=NULL;
			  root->parent=tmpbt;
			  root=tmpbt;
			  current=tmpbt;
			  cnt++;
		  }

	  } 
	   else if(tmpoper.priority<current->oper.priority&&tmpoper.priority!=0)
	  {
			while(1)
			{
				if(current==root)
				{
					btree *tmpbt=new btree;
					left_right=1;
					tmpbt->oper.op=tmpoper.op;
					tmpbt->oper.priority=tmpoper.priority;
					tmpbt->left=root;//tmpbt->left=current
					tmpbt->right=NULL;
					tmpbt->parent=NULL;
					root->parent=tmpbt;
					root=tmpbt;
					current=tmpbt;
					cnt++;
					break;
				}
				else if(tmpoper.priority>current->parent->oper.priority&&current->parent==root)
				{
					btree *tmpbt=new btree;
					left_right=1;
					tmpbt->oper.op=tmpoper.op;
					tmpbt->oper.priority=tmpoper.priority;
					tmpbt->left=current;
					tmpbt->right=NULL;
					tmpbt->parent=root;//tmpbt->parent=current->parent;
					root->right=tmpbt;
					current->parent=tmpbt;
					current=tmpbt;
					cnt++;
					break;
				}

				current=current->parent;
				if(tmpoper.priority==current->oper.priority&&tmpoper.priority!=root_priority)
				{
					btree *tmpbt=new btree;
					left_right=1;
					tmpbt->oper.op=tmpoper.op;
					tmpbt->oper.priority=tmpoper.priority;
					tmpbt->left=current;
					tmpbt->right=NULL;
					tmpbt->parent=current->parent;
					current->parent->right=tmpbt;
					current->parent=tmpbt;
					current=tmpbt;
					cnt++;
					break;
				}
				if(tmpoper.priority==current->oper.priority&&tmpoper.priority==root_priority)
				{
					btree *tmpbt=new btree;
					left_right=1;
					tmpbt->oper.op=tmpoper.op;
					tmpbt->oper.priority=tmpoper.priority;
					tmpbt->left=root;
					tmpbt->right=NULL;
					tmpbt->parent=NULL;
					root->parent=tmpbt;
					root=tmpbt;
					current=tmpbt;
					cnt++;
					break;
				}

			}	 
	  }
	 
	}
	return root;
}

void CCalculatorDlg::OnButtonHelp() 
{
	CUsinghelp dlg;
	dlg.DoModal();
}

void CCalculatorDlg::OnOK() 
{
	OnButtonProcess();

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产一区二区三区| 日韩伦理电影网| 国产日韩v精品一区二区| 亚洲欧美经典视频| 久久97超碰国产精品超碰| 成人小视频免费观看| 欧美日本一道本在线视频| 国产精品你懂的| 天天色天天操综合| 91一区一区三区| 久久久激情视频| 免费看欧美女人艹b| 日本精品一级二级| 中文字幕一区二区三区不卡| 久久99日本精品| 在线播放国产精品二区一二区四区 | 亚洲二区视频在线| 成人午夜激情视频| 久久久久久99久久久精品网站| 亚洲网友自拍偷拍| 91香蕉视频污在线| 国产精品三级久久久久三级| 国产在线一区观看| 欧美xxxxxxxx| 精品一区二区在线观看| 91精品国产免费| 视频一区国产视频| 欧美色倩网站大全免费| 一区二区三区在线观看动漫| 波多野结衣亚洲| 国产精品丝袜91| 成人免费av在线| 中文字幕av一区 二区| 国产99久久久久| 国产日韩精品一区| 成人性生交大片免费| 亚洲一区二区三区四区五区中文| 成人av免费网站| 国产精品色哟哟网站| 成人蜜臀av电影| 亚洲精品国产一区二区精华液| 97久久精品人人做人人爽50路 | 中文字幕精品在线不卡| 韩国一区二区三区| 国产亚洲成av人在线观看导航 | 久久久精品人体av艺术| 精品在线播放免费| 国产精品久久网站| 色婷婷香蕉在线一区二区| 一区二区在线免费观看| 欧美巨大另类极品videosbest| 日韩精品一区第一页| 精品美女一区二区| 国产成人在线网站| 亚洲精品水蜜桃| 69久久夜色精品国产69蝌蚪网| 精品一区二区三区免费毛片爱| 精品久久久久一区| 波多野结衣中文字幕一区二区三区| 亚洲视频免费在线| 7777精品伊人久久久大香线蕉 | 国产日产欧美一区二区视频| 国产91在线观看丝袜| 亚洲精品日日夜夜| 欧美一区二区三区性视频| 国产一区二区0| 亚洲精品免费电影| 精品处破学生在线二十三| va亚洲va日韩不卡在线观看| 五月天亚洲精品| 久久这里只有精品6| 色94色欧美sute亚洲13| 欧美aaa在线| 国产精品素人视频| 欧美日韩不卡一区| 国产成人av自拍| 首页综合国产亚洲丝袜| 国产日产欧美一区二区三区| 色天使色偷偷av一区二区| 久久精品免费看| 亚洲美女视频在线| 亚洲精品一区二区三区香蕉| 97se亚洲国产综合自在线观| 免费高清在线视频一区·| 亚洲婷婷综合色高清在线| 精品日韩99亚洲| 欧美午夜宅男影院| 99久久精品国产观看| 狠狠色丁香婷婷综合| 香蕉成人啪国产精品视频综合网| 国产女主播一区| 精品久久久久久综合日本欧美| 日本精品裸体写真集在线观看 | 国产日韩一级二级三级| 欧美精品自拍偷拍动漫精品| av电影在线观看完整版一区二区| 蜜臀精品久久久久久蜜臀| 亚洲狠狠爱一区二区三区| 国产精品蜜臀av| 久久综合久久鬼色| 日韩精品一区二区三区视频播放| 在线视频你懂得一区二区三区| 福利一区二区在线观看| 美女视频网站久久| 日韩精彩视频在线观看| 亚洲成人动漫在线免费观看| 日韩理论片网站| 亚洲视频香蕉人妖| 国产精品久久久久毛片软件| 国产亚洲欧美一级| 久久婷婷成人综合色| 精品美女一区二区三区| 日韩欧美国产麻豆| 精品日韩欧美一区二区| 精品剧情在线观看| 久久综合久久99| 国产欧美一区二区三区在线老狼| 精品久久久久久久一区二区蜜臀| 日韩免费看网站| 日韩欧美国产高清| 久久久亚洲国产美女国产盗摄| 日韩精品一区二区三区在线 | 国产精品香蕉一区二区三区| 国产一区二区三区国产| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 亚洲色图清纯唯美| 亚洲欧美日韩电影| 亚洲综合成人在线| 毛片av中文字幕一区二区| 五月天丁香久久| 麻豆中文一区二区| 国产麻豆成人精品| 成人动漫av在线| 在线欧美日韩国产| 欧美精品电影在线播放| 日韩免费视频一区| 国产精品美女一区二区| 一区二区三区欧美亚洲| 五月综合激情婷婷六月色窝| 另类小说综合欧美亚洲| 国产精品一线二线三线精华| 99精品久久免费看蜜臀剧情介绍| 在线观看日韩av先锋影音电影院| 欧美高清性hdvideosex| 2020国产精品自拍| 亚洲欧美一区二区三区国产精品| 午夜精品一区二区三区三上悠亚| 美女高潮久久久| voyeur盗摄精品| 欧美一区二区三区在线观看| 久久久久久久久久久黄色| 亚洲裸体在线观看| 奇米色一区二区三区四区| 成人综合婷婷国产精品久久免费| 色综合天天综合网国产成人综合天 | 色琪琪一区二区三区亚洲区| 欧美日韩亚洲综合一区| 久久亚区不卡日本| 一区二区三区四区高清精品免费观看| 亚洲高清视频的网址| 国产成人免费视频精品含羞草妖精| 91精品1区2区| 亚洲精品一区二区三区蜜桃下载| 最好看的中文字幕久久| 久久99精品一区二区三区三区| 99精品视频一区| 精品国产伦一区二区三区观看体验| 亚洲欧洲在线观看av| 久久国产成人午夜av影院| 日本乱码高清不卡字幕| 日本一区二区在线不卡| 日本久久电影网| 久久久久久综合| 日本午夜精品视频在线观看| 91免费观看视频在线| 精品黑人一区二区三区久久| 亚洲综合色网站| k8久久久一区二区三区| 欧美精品一区二区三区蜜桃| 香蕉成人啪国产精品视频综合网 | 久久99精品网久久| 欧美色男人天堂| 亚洲另类春色国产| 成人app在线观看| 久久久不卡网国产精品二区| 麻豆精品国产91久久久久久 | gogogo免费视频观看亚洲一| 日韩免费性生活视频播放| 日韩国产一区二| 欧美日本一道本在线视频| 亚洲尤物在线视频观看| 一本色道久久综合狠狠躁的推荐| 久久精品人人做人人爽97| 极品少妇xxxx偷拍精品少妇| 日韩一区二区免费高清| 性欧美疯狂xxxxbbbb| 欧美日韩高清在线播放| 午夜欧美在线一二页| 欧美性淫爽ww久久久久无| 一区二区三区.www|