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

📄 rcjustifydlg.cpp

📁 离散数学二元关系性质判断器(源码及报告)
💻 CPP
字号:
// RCJustifyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RCJustify.h"
#include "RCJustifyDlg.h"
afx_msg UINT OnNcHitTest(CPoint point); //ON_WM_NCHITTEST()
#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()

/////////////////////////////////////////////////////////////////////////////
// CRCJustifyDlg dialog

CRCJustifyDlg::CRCJustifyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRCJustifyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRCJustifyDlg)
	m_edit1 = _T("");
	m_edit2 = _T("");
	m_edit3 = _T("");
	m_edit4 = _T("");
	
	//}}AFX_DATA_INIT
	m_array=new char[50];
	strcpy(m_array,"性质为:");
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CRCJustifyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRCJustifyDlg)
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	DDV_MaxChars(pDX, m_edit1, 3);
	DDX_Text(pDX, IDC_EDIT2, m_edit2);
	DDV_MaxChars(pDX, m_edit2, 3);
	DDX_Text(pDX, IDC_EDIT3, m_edit3);
	DDX_Text(pDX, IDC_EDIT4, m_edit4);
	
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRCJustifyDlg, CDialog)
	//{{AFX_MSG_MAP(CRCJustifyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_generatexuoujihe, Ongeneratexuoujihe)
	ON_WM_LBUTTONDOWN()
	ON_BN_CLICKED(ID_ZK, OnZk)
	ON_WM_NCHITTEST()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRCJustifyDlg message handlers

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

void CRCJustifyDlg::Ongeneratexuoujihe() //在m_edit3中显示序偶
{
	// TODO: Add your control notification handler code here
	this->UpdateData(TRUE);
	if(m_edit1.GetLength()==0&&m_edit2.GetLength()==0)//对m_edit1和m_edit2判空
		AfxMessageBox("集合不能为空!");
	  m_edit3=dkej();
	 //m_edit5=dkej2();
	this->UpdateData(FALSE);
}

void CRCJustifyDlg::OnOK() //判断关系
{
   	 // this->SetDlgItemText(IDC_EDIT4," ");
	  
	  strcpy(m_array,"性质为:");
	  this->UpdateData(TRUE);
	  if(m_edit1.GetLength()==0)
		  AfxMessageBox("输入集合不能为空!");
	  else
	  {
      this->filter();
	  this->zifan();
	  this->fanzifan();
	  this->notzifannotfanzifan();
	  this->duichen();
	  this->fanduichen();
	  this->chuandi();
	  	 // AfxMessageBox(a);
	  this->SetDlgItemText(IDC_EDIT4,m_array);
	  }
    //this->UpdateData(FALSE);
	//CDialog::OnOK();
}
CString CRCJustifyDlg::dkej()
{
	//生成序偶
    char s[100];
	CString m[100],a;
	int k=0;
    m_edit2=m_edit1;
	for(int i=0;i<m_edit1.GetLength();i++)
	{
		for(int j=0;j<m_edit2.GetLength();j++)
		{
			sprintf(s,"%c,%c",m_edit1[i],m_edit2[j]);         
		    m[k]=s;
			k++;
		 }
	}
	for(i=0;i<k;i++)
	a=a+m[i]+"  ";
	return a;
}



void CRCJustifyDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnLButtonDown(nFlags, point);
	//用来实现左键拖放无标题栏
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnLButtonDown(nFlags, point);//CDialog为基函数
	PostMessage( WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( point.x, point.y)); 

}
UINT CRCJustifyDlg::OnNcHitTest(CPoint point)
{
    UINT nHitTest = CDialog::OnNcHitTest( point );//把CTranDialog改成你的基类 
	return (nHitTest==HTCLIENT) ? HTCAPTION:nHitTest;
}

void CRCJustifyDlg::duichen()
{
  bool flag_dc=true;
  bool flag=false;
  for(int i=0;i<a.GetLength();i+=2)
  {
      flag=false; 
	  int k=i+1;
	  CString temp;
	  temp=a[k];
	  if(temp==a[i])
		  continue;
	  else
	  {
		  for(int j=0;j<a.GetLength();j+=2)
		  {
			  if(j==i)
				  continue;
			  int r=j+1;
			  if(a[j]==temp && a[r]==a[i])
				{
                    
					flag=true;
					break;
				}
		  }
          if(flag==false)
		  {
				flag_dc=false;
				break;
		  }
	  }

  }
  if(flag_dc==true)
	  	strcat(m_array,"对称");

}

void CRCJustifyDlg::zifan()
{

    bool flag=true;
    int k=0;
	for(int i=0;i<a.GetLength();i+=2)
	{
		if(a[i]==a[i+1])
		  k++;		
    }
    if(k==m_edit1.GetLength())
		flag=true;
	else
		flag=false;
	if(flag==true)
	  	strcat(m_array,"自反 ");

}

void CRCJustifyDlg::notzifannotfanzifan()
{
	
    bool flag1=true;
    int k=0;
	for(int i=0;i<a.GetLength();i+=2)
	{
		if(a[i]==a[i+1])
		  k++;		
    }
    if(k==m_edit1.GetLength())
		flag1=true;
	else
		flag1=false;

    bool flag2=true;
	int k1=0;
	for(int j=0;j<a.GetLength();j+=2)
	{
		if(a[j]==a[j+1])
		  k1++;		
    }
	if(k1==0)
		flag2=true;
	else
		flag2=false;

  if(!flag1 && !flag2)
       	strcat(m_array," 既不是自反也不是反自反 ");

}
void CRCJustifyDlg::fanzifan()
{
	
  	bool flag=true;
	int k=0;
	for(int i=0;i<a.GetLength();i+=2)
	{
		if(a[i]==a[i+1])
		  k++;		
    }
	if(k==0)
		flag=true;
	else
		flag=false;
	if(flag==true)
		strcat(m_array," 反自反 ");


}

void CRCJustifyDlg::chuandi()
{ 
  bool flag=true;
//Exist(char x, char y, CString temp)//存在为true
  for(int i=0;i<a.GetLength();i+=2)
	  for(int j=0;j<a.GetLength();j+=2)
		  if(a[i+1]==a[j])
		  {
			  if(!(Exist(a[i],a[j+1],a)))
				   flag=false;
		  }
   if(flag==true)
		strcat(m_array," 传递 ");
}

void CRCJustifyDlg::filter()
{
   a.Empty();
   CString temp,b[50];
   int j=0;
   this->GetDlgItemText(IDC_EDIT3,temp);
   for(int i=0;i<m_edit3.GetLength();i++)
   {
	   if(temp[i]!=',' && temp[i]!=' ')
	   {
		   b[j]=temp[i];
	       j++;
	   }
   }
   for(int k=0;k<j;k++)
   {
	   a=a+b[k];
   }

}


void CRCJustifyDlg::fanduichen()
{
  	bool flag_fdc=true;
	for(int i=0;i<a.GetLength();i+=2)
	{
		int k;
		int j=i+1;
		char temp=a[j];

		if(temp==a[i])
			continue;
		else
		{
			bool flag=false;
			for(k=0;k<a.GetLength();k+=2)
			{
				if(k==i)
					continue;
				int r=k+1;
				if(a[k]==temp && a[r]==a[i])
				{
					flag=true;
					break;
				}
			}
			if(flag==true)
			{
				flag_fdc=false;
				break;
			}

		}

	}
	if(flag_fdc==true)
		strcat(m_array," 反对称 ");
}

bool CRCJustifyDlg::Exist(char x, char y, CString temp)
{
   for(int i=0;i<temp.GetLength();i+=2)
	   if(x==temp[i]&&y==temp[i+1])
		   return true;
	return false;
}

void CRCJustifyDlg::OnZk() 
{
	// TODO: Add your control notification handler code here
	this->UpdateData(TRUE);
	m_edit1.Empty();
	m_edit2.Empty();
	m_edit3.Empty();
	m_edit4.Empty();
	this->UpdateData(FALSE);
	
}

⌨️ 快捷键说明

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