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

📄 matrix.cpp

📁 大规模定制中评价系统源码!对其中配置后的产品进行优化,寻优!
💻 CPP
字号:
#include "Matrix.h"

template <typename T>
CMatrix<typename T>::CMatrix(int nDim, int nSize)
{
	m_nDim = nDim;
	m_nSize = nSize;
	m_pNum = new T[nSize]; 
}

template <typename T>
CMatrix<typename T>::~CMatrix(void)
{
	delete [] m_pNum;
}

template <typename T>
void CMatrix<typename T>::Init()
{
	for (int i = 0; i < nDim; i++)
	{
		for (int j = 0; j < nSize/nDim; j++)
		{
			cin >> m_pNum[i * nSize / nDim + j];
			cout << "\t";
		}
		cout << endl;
	}
}

template <typename T>
 CMatrix<typename T>::CMatrix(const CMatrix<T> &otherMat)
{
	m_nDim = otherMat.m_nDim;
	m_nSize = otherMat.m_nSize;
	m_pNum = new T[m_nSize];
	for (int i = 0; i < m_nSize; i++)
	{
		m_pNum[i] = otherMat.m_pNum[i];
	}
}

 template <typename T>
 const CMatrix<T>& CMatrix<typename T>::operator =(const CMatrix<T> &otherMat)
 {
	 if (&otherMat == this)
		 return *this;
	 m_nDim = otherMat.m_nDim;
	 m_nSize = otherMat.m_nSize;
	 m_pNum = new T[m_nSize];
	 for (int i = 0; i < m_nSize; i++)
	 {
		 m_pNum[i] = otherMat.m_pNum[i];
	 }
	 return *this;
}

template <typename T>
CMatrix<T> CMatrix<typename T>::operator +(const CMatrix<T> &otherMat)
{
	if(m_nSize != otherMat.m_nSize)
		return *this;
	CMatrix<typename T> tempmat(1,m_nSize);
	for(int i = 0; i < m_nSize; i++)
	{
		tempmat.m_pNum[i] = m_pNum[i] + otherMat.m_pNum[i];
	}
	return tempmat;

}

template <typename T>
CMatrix<T> CMatrix<typename T>::operator -(const CMatrix<T> &otherMat)
{
	if(m_nSize != otherMat.m_nSize)
		return *this;
	CMatrix<typename T> tempmat(1,m_nSize);
	for(int i = 0; i < m_nSize; i++)
	{
		tempmat.m_pNum[i] = m_pNum[i] - otherMat.m_pNum[i];
	}
	return tempmat;

}

template <typename T>
CMatrix<T> CMatrix<typename T>::operator *(const CMatrix<T> &otherMat)
{
	if(m_nSize != otherMat.m_nSize)
		return *this;
	CMatrix<typename T> tempmat(1,m_nSize);
	for(int i = 0; i < m_nSize; i++)
	{
		tempmat.m_pNum[i] = m_pNum[i] * otherMat.m_pNum[i];
	}
	return tempmat;

}





⌨️ 快捷键说明

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