📄 matrix1.cpp
字号:
// Matrix1.cpp : implementation file
//
#include "stdafx.h"
#include "Matrix.h"
#include "Matrix1.h"
#include "MatrixClass.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMatrix dialog
CMatrix::CMatrix(CWnd* pParent /*=NULL*/)
: CDialog(CMatrix::IDD, pParent)
{
//{{AFX_DATA_INIT(CMatrix)
m_col1 = 0;
m_row2 = 0;
m_col2 = 0;
m_row1 = 0;
m_matrix1 = _T("");
m_matrix2 = _T("");
m_matrix = _T("");
m_k =0;
//}}AFX_DATA_INIT
}
void CMatrix::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMatrix)
DDX_Control(pDX, IDC_CHECK8, m_r2);
DDX_Control(pDX, IDC_CHECK7, m_r1);
DDX_Control(pDX, IDC_CHECK6, m_nums);
DDX_Control(pDX, IDC_CHECK5, m_choose2);
DDX_Control(pDX, IDC_CHECK4, m_choose1);
DDX_Control(pDX, IDC_CHECK3, m_mul);
DDX_Control(pDX, IDC_CHECK2, m_sub);
DDX_Control(pDX, IDC_CHECK1, m_add);
DDX_Text(pDX, IDC_EDIT4, m_col1);
DDV_MinMaxInt(pDX, m_col1, 0, 200);
DDX_Text(pDX, IDC_EDIT5, m_row2);
DDV_MinMaxInt(pDX, m_row2, 0, 200);
DDX_Text(pDX, IDC_EDIT6, m_col2);
DDV_MinMaxInt(pDX, m_col2, 0, 200);
DDX_Text(pDX, IDC_EDIT3, m_row1);
DDV_MinMaxInt(pDX, m_row1, 0, 200);
DDX_Text(pDX, IDC_EDIT8, m_k);
DDX_Text(pDX, IDC_EDIT1, m_matrix1);
DDX_Text(pDX, IDC_EDIT2, m_matrix2);
DDX_Text(pDX, IDC_EDIT7, m_matrix);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMatrix, CDialog)
//{{AFX_MSG_MAP(CMatrix)
ON_BN_CLICKED(IDC_BUTTON1, OnCreat1)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
ON_BN_CLICKED(IDC_BUTTON2, OnCreat2)
ON_BN_CLICKED(IDOK, OnCalculate)
ON_BN_CLICKED(IDC_CHECK4, OnChoose1)
ON_BN_CLICKED(IDC_CHECK5, OnChoose2)
ON_BN_CLICKED(IDC_BUTTON3, OnTranspose)
ON_BN_CLICKED(IDC_BUTTON4, OnNumMul)
ON_BN_CLICKED(IDC_CHECK6, OnNums)
ON_BN_CLICKED(IDC_CHECK7, OnR1)
ON_BN_CLICKED(IDC_CHECK8, OnR2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMatrix message handlers
void CMatrix::OnCreat1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
p1=new Matrix<int>(m_row1,m_col1);
srand(time(0));
for(int i=0;i<p1->RowMax;i++)
{
for(int j=0;j<p1->ColMax;j++)
{
int a=rand()%10;
p1->SetValue(i,j,a);
}
}
m_matrix1=p1->Print();
UpdateData(false);
}
void CMatrix::OnCreat2()
{
// TODO: Add your control notification handler code here
UpdateData(true);
p2=new Matrix<int>(m_row2,m_col2);
srand(time(0));
for(int i=0;i<p2->RowMax;i++)
{
for(int j=0;j<p2->ColMax;j++)
{
int a=rand()%10;
p2->SetValue(i,j,a);
}
}
m_matrix2=p2->Print();
UpdateData(false);
}
void CMatrix::OnCheck1()
{
// TODO: Add your control notification handler code here
m_sub.SetCheck(0);
m_mul.SetCheck(0);
m_nums.SetCheck(0);
}
void CMatrix::OnCheck2()
{
// TODO: Add your control notification handler code here
m_add.SetCheck(0);
m_mul.SetCheck(0);
m_nums.SetCheck(0);
}
void CMatrix::OnCheck3()
{
// TODO: Add your control notification handler code here
m_add.SetCheck(0);
m_sub.SetCheck(0);
m_nums.SetCheck(0);
}
void CMatrix::OnCalculate()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_add.GetState()==1)
{
if(p1->RowMax!=p2->RowMax||p1->ColMax!=p2->ColMax)
m_matrix="无法相加!";
else
{
Matrix<int> temp(p1->RowMax,p1->ColMax);
temp=*p1 + *p2;
m_matrix="Matrix1 + Matrix:\r\n";
m_matrix+=temp.Print();
}
}
else if(m_sub.GetState()==1)
{
if(p1->RowMax!=p2->RowMax||p1->ColMax!=p2->ColMax)
m_matrix="无法相减!";
else
{
Matrix<int> temp(p1->RowMax,p1->ColMax);
temp=*p1 - *p2;
m_matrix="Matrix1 - Matrix:\r\n";
m_matrix+=temp.Print();
}
}
else if(m_mul.GetState()==1)
{
if(p1->ColMax!=p2->RowMax)
m_matrix="无法相乘!";
else
{
Matrix<int> temp(p1->RowMax,p2->ColMax);
temp=*p1 * *p2;
m_matrix="Matrix1 * Matrix:\r\n";
m_matrix+=temp.Print();
}
}
else if(m_nums.GetState()==1)
{
if(m_r1.GetState()==1)
{
if(p1==NULL)
{
m_matrix="无法运算!";
}
else
{
Matrix<int> temp(p1->RowMax,p1->ColMax);
temp=m_k*(*p1);
m_matrix="k*matrix1";
m_matrix+="\r\n";
m_matrix+=temp.Print();
}
}
else if(m_r2.GetState()==1)
{
if(p2==NULL)
{
m_matrix="无法运算!";
}
else
{
Matrix<int> temp(p2->RowMax,p2->ColMax);
temp=m_k*(*p2);
m_matrix="k*matrix2";
m_matrix+="\r\n";
m_matrix+=temp.Print();
}
}
else
m_matrix="请选择要转置的矩阵!";
}
else if(p1==0||p2==0)
m_matrix="未创建足够数组!";
else
m_matrix="未选择运算方式!";
UpdateData(false);
}
void CMatrix::OnChoose1()
{
// TODO: Add your control notification handler code here
m_choose2.SetCheck(0);
}
void CMatrix::OnChoose2()
{
// TODO: Add your control notification handler code here
m_choose1.SetCheck(0);
}
void CMatrix::OnTranspose()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_choose1.GetState()==1)
{
if(p1==0)
m_matrix="未创建Matrix1";
else
{
Matrix<int> temp=transpose(*p1);
m_matrix="转置Matrix1:\r\n";
m_matrix+=temp.Print();
}
}
else if(m_choose2.GetState()==1)
{
if(p2==0)
m_matrix="未创建Matrix2";
else
{
Matrix<int> temp=transpose(*p2);
m_matrix="转置Matrix2:\r\n";
m_matrix+=temp.Print();
}
}
else
m_matrix="请选择要转置的矩阵!";
UpdateData(false);
}
void CMatrix::OnNumMul()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_choose1.GetState()==1)
{
if(p1==0)
m_matrix="未创建Matrix1";
else
{
Matrix<int> temp=m_k**p1;
m_matrix="integer*Matrix1:\r\n";
m_matrix+=temp.Print();
}
}
else if(m_choose2.GetState()==1)
{
if(p2==0)
m_matrix="未创建Matrix1";
else
{
Matrix<int> temp=m_k**p2;
m_matrix="integer*Matrix2:\r\n";
m_matrix+=temp.Print();
}
}
else
m_matrix="请选择要数乘的矩阵!";
UpdateData(false);
}
void CMatrix::OnCancel()
{
// TODO: Add extra cleanup here
m_matrix1.Empty();
m_matrix2.Empty();
m_matrix.Empty();
UpdateData(false);
CDialog::OnCancel();
}
void CMatrix::OnNums()
{
m_add.SetCheck(0);
m_sub.SetCheck(0);
m_mul.SetCheck(0);
}
void CMatrix::OnR1()
{
m_r2.SetCheck(0);
}
void CMatrix::OnR2()
{
m_r1.SetCheck(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -