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

📄 turbo_finaldlg.cpp

📁 采用随机输入作为码源
💻 CPP
字号:
// turbo_finalDlg.cpp : implementation file
//

#include "stdafx.h"
#include "turbo_final.h"
#include "turbo_finalDlg.h"
#include "turbo.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()

/////////////////////////////////////////////////////////////////////////////
// CTurbo_finalDlg dialog

CTurbo_finalDlg::CTurbo_finalDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTurbo_finalDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTurbo_finalDlg)
	m_input1 = _T("");
	m_input2 = _T("");
	m_number = 0;
	m_output1 = _T("");
	m_output2 = _T("");
	m_error = _T("");
	m_incorrect = 0;
	//}}AFX_DATA_INIT
	ifcode = 0;
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTurbo_finalDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTurbo_finalDlg)
	DDX_Control(pDX, IDC_EDIT_incorrect, m_incorrect1);
	DDX_Text(pDX, IDC_EDIT_input1, m_input1);
	DDV_MaxChars(pDX, m_input1, 62);
	DDX_Text(pDX, IDC_EDIT_input2, m_input2);
	DDV_MaxChars(pDX, m_input2, 128);
	DDX_Text(pDX, IDC_EDIT_number, m_number);
	DDX_Text(pDX, IDC_EDIT_output1, m_output1);
	DDV_MaxChars(pDX, m_output1, 128);
	DDX_Text(pDX, IDC_EDIT_output2, m_output2);
	DDV_MaxChars(pDX, m_output2, 62);
	DDX_Text(pDX, IDC_EDIT_error, m_error);
	DDV_MaxChars(pDX, m_error, 500);
	DDX_Text(pDX, IDC_EDIT_incorrect, m_incorrect);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTurbo_finalDlg, CDialog)
	//{{AFX_MSG_MAP(CTurbo_finalDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDOK, OnEncodeBtn)
	ON_BN_CLICKED(IDC_BUTTON1, OnDecodeBtn)
	ON_BN_CLICKED(IDC_errorBtn, OnerrorBtn)
	ON_BN_CLICKED(IDC_BUTTON_about, OnBUTTONabout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTurbo_finalDlg message handlers

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

void CTurbo_finalDlg::OnEncodeBtn() 
{
	// TODO: Add your control notification handler code here
	int i,n=64,m,j=0,k; 
	char *temp1,*temp2;
	temp1 = new char[n-2];
	temp2 = new char[2*n+1];
	temp1[n-2] = '\0';
	temp2[2*n] = '\0';
	randomize(); 
	for(i=0; i<62; i++) 
	{
		encodeinput[i] = rand()%2;
		temp1[i] = encodeinput[i] + '0';
	}
	m_input1.Format("%s",temp1);
	systemencode(encodeinput,encodeoutput,n);
	for(i=0;i<2*n;i++)
	{
		temp2[i] = encodeoutput[i] + '0';
	}
	m_output1.Format("%s",temp2);
	UpdateData(FALSE);
}

void CTurbo_finalDlg::OnDecodeBtn() 
{
	// TODO: Add your control notification handler code here
	if(ifcode)
	{
		int i,n=64,m,j=0,k,mm = 0;
		double decodeinput[200],decodeoutput[100];
		char *temp1,*temp2;
		temp1 = new char[n-1];
		temp2 = new char[2*n+1];
		temp1[n-2] = '\0';
		temp2[2*n] = '\0';
//		m_incorrect = 0;
		for(i=0;i<128;i++)
			decodeinput[i]=encodeoutput[i]*2-1;
		systemdecode(decodeinput,decodeoutput,n);
		for(i=0;i<62;i++)
		{
			temp1[i] = decodeoutput[i] + '0';
			if(decodeoutput[i]!=encodeinput[i])
			{
		//		m_incorrect++;
				mm++;
			}
		}
		m_incorrect = mm;
		m_output2.Format("%s",temp1);
		UpdateData(FALSE);
		ifcode = 0;
	}
}

void CTurbo_finalDlg::OnerrorBtn() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	int record[500]={0};
	int error[500],rr[128];
	char *temp;
	temp = new char[129];
	temp[128] = '\0';
	int k = 0,j = 0,flag=0;
	char wrong[3]={0,0,0};
	for(int i = 0;i<4*m_number&&flag==0;i++)
	{
		if(m_error[0]==' ')
		{
			MessageBox("不能以空格开头");
			exit(0);
		}
		record[i+1] = m_error.Find(' ',record[i]+1);
		if(record[i+1] == -1)//到达末尾
		{
			if(i == 0)//只有一个数字的情况
			{
				for(j = 0 ;j<m_error.GetLength() - record[i];j++)
				{	
					wrong[j] = m_error.GetAt(j);	
				}
				j = m_error.GetLength()-1;
				switch(m_error.GetLength())
				{	
					case 1:
						rr[k] = (int)wrong[j] - '0';
						break;
					case 2:
						rr[k] = 10*(int)wrong[j-1] + (int)wrong[j] - 11*'0';
						break;
					case 3:	
						rr[k] = 100*(int)wrong[j-2] + 10*(int)wrong[j-1] + (int)wrong[j] -111*'0';
						break;
				}
			}
			else
			{
				for(j = 0 ;j<m_error.GetLength() - record[i]-1;j++)
				{	
					wrong[j] = m_error.GetAt(record[i]+j+1);	
				}
				j = m_error.GetLength()-record[i]-2;
				switch(m_error.GetLength()-record[i]-1)
				{	
					case 1:
						rr[k] = (int)wrong[j] - '0';
						break;
					case 2:
						rr[k] = 10*(int)wrong[j-1] + (int)wrong[j] - 11*'0';
						break;
					case 3:	
						rr[k] = 100*(int)wrong[j-2] + 10*(int)wrong[j-1] + (int)wrong[j] -111*'0';
						break;
				}
			}

			flag = 1;
		}
		else //没有到达末尾
		{
			if(i!=0) //不是第一个
			{
				for(j=0;j<record[i+1]-record[i]-1;j++)
				{
					wrong[j] = m_error.GetAt(record[i]+j+1);
				}
				j = record[i+1] - record[i] -2;
				switch(record[i+1]-record[i]-1)
				{	
					case 1:
						rr[k] = (int)wrong[j] - '0';
						break;
					case 2:
						rr[k] = 10*(int)wrong[j-1] + (int)wrong[j] - 11*'0';
						break;
					case 3:	
						rr[k] = 100*(int)wrong[j-2] + 10*(int)wrong[j-1] + (int)wrong[j] -111*'0';
						break;
				}
			}
			else//第一个字符
			{			
				for(j=0;j<record[i+1]-record[i];j++)
				{
					wrong[j] = m_error.GetAt(record[i]+j);
				}
				j = record[i+1] - record[i] -1;
				switch(record[i+1]-record[i])
				{
					case 1:
						rr[k] = (int)wrong[j] - '0';
						break;
					case 2:
						rr[k] = 10*(int)wrong[j-1] + (int)wrong[j] - 11*'0';
						break;
					case 3:	
						rr[k] = 100*(int)wrong[j-2] + 10*(int)wrong[j-1] + (int)wrong[j] -111*'0';
						break;
				}
			}
		}
		k++;			
	}
	for(i=0;i<k;i++)
	{
		if(encodeoutput[rr[i]] == 1)
		{
			encodeoutput[rr[i]] = 0;
		}
		else
		{
			encodeoutput[rr[i]] = 1;
		}
	}
	for(i = 0;i<128;i++)
	{
		temp[i] = encodeoutput[i] + '0';
	}
	m_input2.Format("%s",temp);
	ifcode = 1;
	UpdateData(FALSE);
}

void CTurbo_finalDlg::OnBUTTONabout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg dlg;
	dlg.DoModal();
}

void CTurbo_finalDlg::OnUpdateEdit3() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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