⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bignumdlg.cpp

📁 大的整数运算
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	// TODO: Add your control notification handler code here
	exit(1);
}

void CBigNumDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	char ch1[300],ch2[300];
	memset(ch1,0,300);
	memset(ch2,0,300);
	GetDlgItem(IDC_NumA)->GetWindowText(ch1,300);
	GetDlgItem(IDC_NumB)->GetWindowText(ch2,300);
	if(TRUE==judge(ch1,strlen(ch1)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
    if(TRUE==judge(ch2,strlen(ch2)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
	BNum *pbnto;
	BNum *p;
	BNum *q;
	pbnto = new BNum;
    p = new BNum;
	q = new BNum;
	BN_Reset(p);
    BN_Reset(q);
	BN_Reset(pbnto);
    CString str1;                    //  void BN_AddTo(BNum *pbn, BNum *pbn2, BNum *pbnto)
    GetDlgItemText(IDC_NumA,str1);
	CString str2;                    //  void BN_AddTo(BNum *pbn, BNum *pbn2, BNum *pbnto)
    GetDlgItemText(IDC_NumB,str2);
	if(!G){
	CBigNumDlg::chtoi(str1,p);
    CBigNumDlg::chtoi(str2,q);}
    else{
	CBigNumDlg::chto_i(str1,p);
    CBigNumDlg::chto_i(str2,q);}
    BN_AddTo(p, q, pbnto);
//	CString str3 = "hello world";
	CString str3;
	CBigNumDlg::itoch(str3,pbnto);
	if(!G) transfer(str3,str3);
	GetDlgItem(IDC_NumC)->SetWindowText(str3);
	UpdateData();
}

void CBigNumDlg::OnPlus() 
{
	// TODO: Add your control notification handler code here
	char ch1[300],ch2[300];
	memset(ch1,0,300);
	memset(ch2,0,300);
	GetDlgItem(IDC_NumA)->GetWindowText(ch1,300);
	GetDlgItem(IDC_NumB)->GetWindowText(ch2,300);
	if(TRUE==judge(ch1,strlen(ch1)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
    if(TRUE==judge(ch2,strlen(ch2)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
	BNum *pbnto;
	BNum *p;
	BNum *q;
	pbnto = new BNum;
    p = new BNum;
	q = new BNum;
	BN_Reset(p);
    BN_Reset(q);
	BN_Reset(pbnto);
    CString str1;                    
    GetDlgItemText(IDC_NumA,str1);
	CString str2;                    
    GetDlgItemText(IDC_NumB,str2);
	if(!G){
	CBigNumDlg::chtoi(str1,p);
    CBigNumDlg::chtoi(str2,q);}
    else{
	CBigNumDlg::chto_i(str1,p);
    CBigNumDlg::chto_i(str2,q);}
	int j = 1;
	j = BN_ComPare(p,q);
	if(0==j)
	{
		MessageBox("注意,这个是B-A时候的结果");
	}
	BN_Sub(p,q,pbnto);
	CString str3;
	CBigNumDlg::itoch(str3,pbnto);
	if(!G) transfer(str3,str3);
	GetDlgItem(IDC_NumC)->SetWindowText(str3);
	UpdateData();
}

void CBigNumDlg::OnMulti() 
{
	// TODO: Add your control notification handler code here
	char ch1[300],ch2[300];
	memset(ch1,0,300);
	memset(ch2,0,300);
	GetDlgItem(IDC_NumA)->GetWindowText(ch1,300);
	GetDlgItem(IDC_NumB)->GetWindowText(ch2,300);
	if(TRUE==judge(ch1,strlen(ch1)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
    if(TRUE==judge(ch2,strlen(ch2)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
	BNum *pbnto;
	BNum *p;
	BNum *q;
	pbnto = new BNum;
    p = new BNum;
	q = new BNum;
	BN_Reset(p);
    BN_Reset(q);
	BN_Reset(pbnto);
    CString str1;                   
    GetDlgItemText(IDC_NumA,str1);
	CString str2;                    
    GetDlgItemText(IDC_NumB,str2);
	if(!G){
	CBigNumDlg::chtoi(str1,p);
    CBigNumDlg::chtoi(str2,q);}
    else{
	CBigNumDlg::chto_i(str1,p);
    CBigNumDlg::chto_i(str2,q);}
	BN_Multiply(p,q,pbnto);
	CString str3;
	CBigNumDlg::itoch(str3,pbnto);
	if(!G) transfer(str3,str3);
	GetDlgItem(IDC_NumC)->SetWindowText(str3);
	UpdateData();
}

void CBigNumDlg::OnDiv() 
{
	// TODO: Add your control notification handler code here
	char ch1[300],ch2[300];
	memset(ch1,0,300);
	memset(ch2,0,300);
	GetDlgItem(IDC_NumA)->GetWindowText(ch1,300);
	GetDlgItem(IDC_NumB)->GetWindowText(ch2,300);
	if(TRUE==judge(ch1,strlen(ch1)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
    if(TRUE==judge(ch2,strlen(ch2)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
	if(StrCmp(ch2,"0")==0)
	{
		MessageBox("除法时,B不能位零");
		return;
	}
	BNum *pbnto;
	BNum *p;
	BNum *q;
	BNum *re;
	pbnto = new BNum;
    p = new BNum;
	q = new BNum;
	re = new BNum;
	BN_Reset(p);
    BN_Reset(q);
	BN_Reset(pbnto);
	BN_Reset(re);
    CString str1;                   
    GetDlgItemText(IDC_NumA,str1);
	CString str2;                    
    GetDlgItemText(IDC_NumB,str2);
	if(!G){
	CBigNumDlg::chtoi(str1,p);
    CBigNumDlg::chtoi(str2,q);}
    else{
	CBigNumDlg::chto_i(str1,p);
    CBigNumDlg::chto_i(str2,q);}
//	BN_Multiply(p,q,pbnto);
	BN_Devide(p,q,re,pbnto);
	CString str3;
	CBigNumDlg::itoch(str3,pbnto);
	if(!G) transfer(str3,str3);
	GetDlgItem(IDC_NumC)->SetWindowText(str3);
	UpdateData();
}

void CBigNumDlg::OnMod() 
{
	// TODO: Add your control notification handler code here
	char ch1[300],ch2[300];
	memset(ch1,0,300);
	memset(ch2,0,300);
	GetDlgItem(IDC_NumA)->GetWindowText(ch1,300);
	GetDlgItem(IDC_NumB)->GetWindowText(ch2,300);
	if(TRUE==judge(ch1,strlen(ch1)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
    if(TRUE==judge(ch2,strlen(ch2)))
	{
		if(G) MessageBox("A中请输入0-9或者A-F之间的数字");
	    else MessageBox("A中请输入0-9之间的数字");
		return;
	}
	BNum *pbnto;
	BNum *p;
	BNum *q;
	BNum *re;
	pbnto = new BNum;
    p = new BNum;
	q = new BNum;
	re = new BNum;
	BN_Reset(p);
    BN_Reset(q);
	BN_Reset(pbnto);
	BN_Reset(re);
    CString str1;                   
    GetDlgItemText(IDC_NumA,str1);
	CString str2;                    
    GetDlgItemText(IDC_NumB,str2);
	if(!G){
	CBigNumDlg::chtoi(str1,p);
    CBigNumDlg::chtoi(str2,q);}
    else{
	CBigNumDlg::chto_i(str1,p);
    CBigNumDlg::chto_i(str2,q);}
//	BN_Multiply(p,q,pbnto);
	BN_Devide(p,q,re,pbnto);
	CString str3;
	CBigNumDlg::itoch(str3,re);
	if(!G) transfer(str3,str3);
	GetDlgItem(IDC_NumC)->SetWindowText(str3);
	UpdateData();
}

void CBigNumDlg::Ontransfer() 
{
	// TODO: Add your control notification handler code here
	if(!G) {return;}
	char ch1[300],ch2[300];
	memset(ch1,0,300);
	memset(ch2,0,300);
	GetDlgItem(IDC_NumC)->GetWindowText(ch1,300);
	BNum *pbnto;
	BNum *p;
	BNum *q;
	BNum *re;
	BNum *rs;
	pbnto = new BNum;
    p = new BNum;
	q = new BNum;
	re = new BNum;
	rs = new BNum;
	BN_Reset(pbnto);
	BN_Reset(re);
	BN_Reset(rs);
    CString str1;                   
    GetDlgItemText(IDC_NumC,str1);
	CString str2;                    
    str2="a";
	CBigNumDlg::chto_i(str1,p);
    CBigNumDlg::chto_i(str2,q);
    int i=0;
	while(BN_ComPare(p,q)!=0){
	BN_Devide(p,q,re,rs);
    pbnto->Data[i++]=re->Data[0];
	BN_Pass(rs,p);
	}
	BN_Devide(p,q,re,rs);
    pbnto->Data[i++]=re->Data[0];
	CString str3;
	CBigNumDlg::itoch(str3,pbnto);
	GetDlgItem(IDC_NumC)->SetWindowText(str3);
	UpdateData();
}

void CBigNumDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
    G=!G;	
	if(G) m_btn2.SetWindowText("16进制");
	else m_btn2.SetWindowText("10进制");
}
void CBigNumDlg::transfer(CString &str1,CString &str3) 
{
	// TODO: Add your control notification handler code here
	BNum *pbnto;
	BNum *p;
	BNum *q;
	BNum *re;
	BNum *rs;
	pbnto = new BNum;
    p = new BNum;
	q = new BNum;
	re = new BNum;
	rs = new BNum;
	BN_Reset(pbnto);
	BN_Reset(re);
	BN_Reset(rs);
	CString str2;                    
    str2="a";
	CBigNumDlg::chto_i(str1,p);
    CBigNumDlg::chto_i(str2,q);
    int i=0;
	while(BN_ComPare(p,q)!=0){
	BN_Devide(p,q,re,rs);
    pbnto->Data[i++]=re->Data[0];
	BN_Pass(rs,p);
	}
	BN_Devide(p,q,re,rs);
    pbnto->Data[i++]=re->Data[0];
	CBigNumDlg::itoch(str3,pbnto);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -