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

📄 正式dlg.cpp

📁 离散数学真值表求值
💻 CPP
字号:
// 正式Dlg.cpp : implementation file
//

#include "stdafx.h"
#include <string.h>
#include <fstream.h>
#include "正式.h"
#include "正式Dlg.h"
#include "SequChar.h"
//#include "file.h"
int ClenOrNot=0;
char CharWho[10];
int canshu[40];
int Arry[11];
char ShowList[6600]="";
int as=0;
int fs=0;			
int GivenCharFuction();
int f(int s);
int mi(int);


#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 void OnInformation();
	//}}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)
	ON_BN_CLICKED(IDINFORMATION, OnInformation)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTONFILE, OnButtonfile)
	ON_BN_CLICKED(IDC_BUTTONLOAD, OnButtonload)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::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 CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void CMyDlg::OnOK() 
{
//	if(Lock!=1)
//	{
		strcpy(ShowList,"");
//	}
//	this->SetDlgItemText(IDC_EDIT1,ShowList);
	this->SetDlgItemText(IDC_RSULT,ShowList);
	
	// TODO: Add extra validation here
	CString m_str;	
	CString Savem_str;
	char *show;
    show=new char[100];
	
	
	if(ClenOrNot==1)
	{
		OnButton1();
//		AfxMessageBox("出错!您未按要求操作,建议阅读帮助信息!");
	}
    else
	{
	this->GetDlgItemText(IDC_EDIT1,m_str);

    Savem_str=m_str;
    strcpy(show,m_str);
  
	SequChar vc(show);

    for(int ss=0;ss<40;ss++)
	{
		if(vc.BaseArry[ss+1]==1)
			break;
		canshu[as]=vc.BaseArry[ss+1];
		as++;		
	}
	int M=GivenCharFuction();
	////////////////////////////////////////////////////////////////////////////
	int NmberLine=mi(M);	
	int y=0;
	for(int NmberLine_X=0;NmberLine_X<mi(M);NmberLine_X++)/////                                                   		/////
	{                                                     /////
		NmberLine=NmberLine_X;                            /////
		for(int i=10;i>10-M;i--)                              /////
		{                                                  ////
			Arry[i]=NmberLine%2;                          /////
			NmberLine=NmberLine/2;			              //////
		}			                                        ////
		y=f(vc.BaseArry[0]);
		if(y>1)
		{
			AfxMessageBox("错误!您未按要求操作,请先阅读帮助信息!");
			
            OnButton1();
			break;
		}
	}
	if(y<=1)
	{
		for(int ShowCharWho=M-1;ShowCharWho>=0;ShowCharWho--)
		{
			m_str=CharWho[ShowCharWho];
    		strcat(ShowList,m_str);
			strcat(ShowList,"     ");	
		}
    	strcat(ShowList,Savem_str);
		strcat(ShowList,"\n");

		for( NmberLine_X=0;NmberLine_X<mi(M);NmberLine_X++)
		{

			NmberLine=NmberLine_X;
			for(int i=10;i>10-M;i--)
			{
				Arry[i]=NmberLine%2;
				NmberLine=NmberLine/2;			
			}
	
			y=f(vc.BaseArry[0]);

			for(int yx=11-M;yx<=10;yx++)
			{
			if(Arry[yx]==0)
				strcat(ShowList,"0");
			else
			    strcat(ShowList,"1");  

				strcat(ShowList,"     ");

			}
			if(y==0)
				strcat(ShowList,"0");
			else
			    strcat(ShowList,"1");
			
			strcat(ShowList,"\n");
		}
		this->SetDlgItemText(IDC_RSULT,ShowList);
        // strcpy(ShowList,"");
	}

	}
		///////////////////////////////////////////////////////////////////////////
		
//		CDialog::OnOK();
	
}
int GivenCharFuction()//Referance The Arry will be used
{
	int ReArry[40]={45,113,45,112,109};
	for(int newx=0;newx<40;newx++)
	{
		ReArry[newx]=canshu[newx];
	}
	int N=20;
	int CharNum=0;
	int CharMax=65;
	int SaveCharMax=122;
	int SaveCharNum=0;
	int CharIs=10;            //最多不同字符数	
	for( int i=0;i<N;i++)
	{
		if((ReArry[i]>=65)&&(ReArry[i]<=90))
		{
			CharNum++;
		}
		if((ReArry[i]>=97)&&(ReArry[i]<=122))
		{
			CharNum++;
		}
	}
	SaveCharNum=CharNum;
	int CharWhoUsed=0;
	while(1)
	{	
		CharMax=65;
		for( i=0;i<N;i++)
		{
			if((ReArry[i]>CharMax)&&((ReArry[i]>=65)&&(ReArry[i]<=90)||((ReArry[i]>=97)&&(ReArry[i]<=122))))
			{
				CharMax=ReArry[i];
//				cout<<"charmax here"<<CharMax<<endl;
			}
			SaveCharMax=CharMax;
		}
		int Close_Open_CharIs=0;

		CharWho[CharWhoUsed]=CharMax;
		CharWhoUsed++;

		for( i=0;i<N;i++)
			{
				if(ReArry[i]==CharMax)
				{
					ReArry[i]=CharIs;
			//		if( Close_Open_CharIs==0)
			//		{
			//			CharIs--;
			//			Close_Open_CharIs=1;
			//		}	
					SaveCharNum--;	
//					cout<<endl;
				}
			}
		CharIs--;
		if(SaveCharNum==0)
			break;
	}

	for( newx=0;newx<20;newx++)
	{
		canshu[newx]=ReArry[newx];
	}
	return 10-CharIs;	
}

int f(int s)
{
	int qian1=0;
	int qian2=0,hou2=0,x2=0,y2=0;
	int qian3=0,hou3=0,x3=0,y3=0;
	int qian4=0,hou4=0,x4=0,y4=0;
	int qian5=0,hou5=0,x5=0,y5=0;
	if(s==33)
	{
			
			qian1=canshu[fs];		
			fs++;
			if(fs==as)
				fs=0;

		return (!f(qian1));
	}
	if(s==38)
	{
		
			qian2=canshu[fs];		
			fs++;
			if(fs==as)
				fs=0;
			x2=f(qian2);
			hou2=canshu[fs];
			fs++;
			if(fs==as)
				fs=0;	
		y2=f(hou2);
	
		return(x2&&y2);
	}
	if(s==124)
	{	
			qian3=canshu[fs];		
			fs++;
			if(fs==as)
				fs=0;
			x3=f(qian3);
			hou3=canshu[fs];
			fs++;
			if(fs==as)
				fs=0;		
		y3=f(hou3);			
		return(x3||y3);
	}
	if(s==45)
	{
			qian4=canshu[fs];		
			fs++;
			if(fs==as)
				fs=0;
			x4=f(qian4);
			hou4=canshu[fs];
			fs++;
			if(fs==as)
				fs=0;		
		y4=f(hou4);
		if((y4==0)&&(x4==1))		
			return 0;
		else
			return 1;
	}
	if(s==60)
	{		
			qian5=canshu[fs];		
			fs++;
			x5=f(qian5);
			hou5=canshu[fs];
			fs++;
			if(fs==as)
				fs=0;		
		y5=f(hou5);
		if(x5==y5)
			return 1;
		else
			return 0;
	}
	if(s==10)
		return Arry[10];
	if(s==9)
		return Arry[9];
	if(s==8)
	return Arry[8];
	if(s==7)
	return Arry[7];
	if(s==6)
		return Arry[6];
	if(s==5)
		return Arry[5];
	if(s==4)
		return Arry[4];
	if(s==3)
		return Arry[3];
	if(s==2)
		return Arry[2];
	if(s==1)
		return Arry[1];
	else
	{
	    ClenOrNot=1;
		return 100;
	}
}
int mi(int x)
{
	if(x>0)
		return 2*mi(x-1);
		return 1;
}

void CMyDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
		this->SetDlgItemText(IDC_EDIT1,"");
		ClenOrNot=0;
		this->SetDlgItemText(IDC_RSULT,"");

}

void CMyDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	AfxMessageBox("离散数学2004 final\n\n欢迎使用离散数学系列应用软件!\n\n 本套软件将帮助您完成离散数学中的一系列计算问题\n\n本软件用于真值表生成\n\n生成真值表后按“生成文件”可生成名为“离散数学.TXT”文件\n\n步骤与要求如下:\n\n1 在公式输入区键入所要求式子\n2 单击“输入确认”键(或回车)\n3 结果将在显示区显示\n4 此时按“生成文件”可在当前目录下生成“使用记录.TXT”\n5 清空键清空所有输入区与显示区内容\n\n  **注意** 输入公式要由( )确定优先级\n\n   同时为了方便键盘输入做如下规定:\n(1)用  ! 代替 非 操作\n(2)用 && 代替 ∧ 操作\n(3)用 || 代替 ∨ 操作\n(4)用 <> 代替 <=> 操作\n(5)保持操作 -> 不变\n\n例如:欲求  p∧q∨R<=>!S 真值\n应输入:((p&&Q)||R)<>(!S)\n\n有您的帮助,我们将做的更好!请支持国产共享软件!\n\n**************水世界实验室****************\n\n");
	
}

void CMyDlg::OnButtonfile() 
{
	// TODO: Add your control notification handler code here
	ofstream file("使用记录-离散数学.txt");
//	strcat(ShowList,"
	file<<ShowList;

    AfxMessageBox("“使用记录.txt”已经生成!\n请更改文件名,否则下次生成文件会将其覆盖");
	
}

void CAboutDlg::OnInformation() 
{
	// TODO: Add your control notification handler code here
	AfxMessageBox("制作群:水世界实验室");
}

void CMyDlg::OnButtonload() 
{
	// TODO: Add your control notification handler code here
	ifstream filein("in.txt",ios::nocreate);
	filein>>ShowList;
	Lock=1;
	this->SetDlgItemText(IDC_EDIT1,ShowList);
	OnOK();
	Lock=0;
}

void CMyDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	AfxMessageBox("软件注册说明 *. >> 如何注册本软件?\n\n1. 商品〖离散数学应用软件〗是共享软件。您应该首先下载后试用,如果您喜欢本软件并且决定一直使用下去,请付费使用。这个付费过程称为“注册”,付费后的用户称为“注册用户”。\n\n2. 共享软件的品质由用户自行鉴定,本站不对共享软件的质量进行任何担保,无论是明示的还是暗示的。与本软件有关的技术服务,由本软件的作者向您提供。本站仅处理您在支付注册费用及注册信息发送过程中出现的问题。\n\n3. 注册用户可以得到作者的技术支持和服务。相应的,如果软件作者有其他服务承诺,注册用户将得到更多的好处。特别的,您的注册还将在最大程度上鼓励作者作出更多、更好的软件供大家使用,进而促进中国的民族软件事业的发展和壮大。\n\n4. 请登陆网站,软件作者通过 E-Mail 向您发送注册码,所以请您务必留下真实准确的 E-Mail 地址;为保证顺利发送注册码或提供服务,如果您有第二个E-Mail地址,也请留给作者。\n\n5. 如果您有意注册使用本软件,请填写“注册表单”。其中,带有 * 的项目为必填项,请仔细填写。\n\n注册途径:作者E-mail:chenchen_online@yahoo.com.cn \n\nhttp://www.chenchen.7u7.net  请在上面留言!\n\n**************水世界实验室***************");
}

void CMyDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	AfxMessageBox("************水世界实验室**************\n\n版本2004 final\n\n请支持国产共享软件!");
}

⌨️ 快捷键说明

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