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

📄 tfnmat.cpp

📁 大规模定制中评价系统源码!对其中配置后的产品进行优化,寻优!
💻 CPP
字号:
#include "TFNMat.h"
#include <iostream>
#include <math.h>
const double ESP = 0.00001;
using namespace std;

CTFNMat::CTFNMat(int nRow, int nCol)
{
	if (nRow <= 0 || nCol <= 0)
	{
		m_nRow = 0;
		m_nCol = 0;
		m_pTFN = NULL;
		
	}
	else
	{
		m_nRow = nRow;
		m_nCol = nCol;
		m_pTFN = new CTFN[nRow * nCol];
	}
}

CTFNMat::~CTFNMat(void)
{
	delete [] m_pTFN;
}

CTFNMat::CTFNMat(const CTFNMat &mat)
{
	m_nRow = mat.m_nRow;
	m_nCol = mat.m_nCol;
	m_pTFN = new CTFN[m_nRow * m_nCol];
	for (int i = 0; i < m_nRow; i++)
	{
		for (int j = 0; j < m_nCol; j++)
		{
			m_pTFN[i * m_nCol + j] = mat.m_pTFN[i * m_nCol + j];
		}
	}
}

CTFNMat CTFNMat::operator =(const CTFNMat &otherMat)
{
	if (&otherMat == this)
	{
		return *this;
	}
	else
	{
		m_nRow = otherMat.m_nRow;
		m_nCol = otherMat.m_nCol;
		if (m_pTFN != NULL)
		{
			delete [] m_pTFN;
		}
		m_pTFN = new CTFN[m_nRow * m_nCol];
		for (int i = 0; i < m_nRow; i++)
		{
			for (int j = 0; j < m_nCol; j++)
			{
				m_pTFN[i * m_nCol + j] = otherMat.m_pTFN[i * m_nCol + j];
			}
		}
	}
	return *this;
}

int CTFNMat::GetCol() const
{
	return m_nCol;
}

int CTFNMat::GetRow() const
{
	return m_nRow;
}

void CTFNMat::SetCol(int nCol)
{
	if (nCol == 0)
	{
		return;
	}
	else
	{
		m_nCol = nCol;
		delete [] m_pTFN;
		m_pTFN = new CTFN[m_nRow * nCol];
	}
}

void CTFNMat::SetRow(int nRow)
{
	if (nRow == 0)
	{
		return;
	}
	else
	{
		m_nRow = nRow;
		delete [] m_pTFN;
		m_pTFN = new CTFN[m_nRow * m_nCol];
	}
}

CTFNMat CTFNMat::operator *(const CTFNMat &mat)
{
	if (m_nCol != mat.m_nRow)
	{
		return *this;
	}
	else
	{
		CTFNMat tempMat(m_nRow, mat.m_nCol);
		for (int i = 0; i < m_nRow; i++)
		{
			for (int j = 0; j < mat.m_nCol; j++)
			{
				CTFN sum;
				for (int k = 0; k < m_nCol; k++)
				{
					sum = sum + m_pTFN[i * m_nCol + k] * mat.m_pTFN[k * mat.m_nCol + j];
				}
				tempMat.m_pTFN[i * mat.m_nCol + j] = sum;
			}
		}
		return tempMat;
	}
}

CTFNMat CTFNMat::operator +(const CTFNMat &mat)
{
	if (mat.m_nRow != m_nRow || mat.m_nCol != m_nCol)
	{
		return *this;
	}
	else
	{
		CTFNMat tempMat(m_nRow, m_nCol);
		for (int i = 0; i < m_nRow; i++)
		{
			for (int j = 0; j < m_nCol; j++)
			{
				tempMat.m_pTFN[i * m_nCol + j] = m_pTFN[i * m_nCol + j] + mat.m_pTFN[i * m_nCol + j];
			}
		}
		return tempMat;
	}
}

CTFNMat CTFNMat::operator -(const CTFNMat &mat)
{
	if (mat.m_nRow != m_nRow || mat.m_nCol != m_nCol)
	{
		return *this;
	}
	else
	{
		CTFNMat tempMat(m_nRow, m_nCol);
		for (int i = 0; i < m_nRow; i++)
		{
			for (int j = 0; j < m_nCol; j++)
			{
				tempMat.m_pTFN[i * m_nCol + j] = m_pTFN[i * m_nCol + j] - mat.m_pTFN[i * m_nCol + j];
			}
		}
		return tempMat;
	} 
}

CTFNMat CTFNMat::operator *(double d)
{
	CTFNMat tempMat(*this);
	for (int i = 0; i < m_nRow; i++)
	{
		for (int j = 0; j < m_nCol; j++)
		{
			tempMat.m_pTFN[i * m_nCol + j] = m_pTFN[i * m_nCol + j] * d;
		}
	}
	return tempMat;
}

CTFNMat CTFNMat::operator +(double d)
{
	CTFNMat tempMat(*this);
	for (int i = 0; i < m_nRow; i++)
	{
		for (int j = 0; j < m_nCol; j++)
		{
			tempMat.m_pTFN[i * m_nCol + j] = m_pTFN[i * m_nCol + j] + d;
		}
	}
	return tempMat;
}

CTFNMat CTFNMat::operator -(double d)
{
	CTFNMat tempMat(*this);
	for (int i = 0; i < m_nRow; i++)
	{
		for (int j = 0; j < m_nCol; j++)
		{
			tempMat.m_pTFN[i * m_nCol + j] = m_pTFN[i * m_nCol + j] - d;
		}
	}
	return tempMat;
}

CTFNMat CTFNMat::operator /(double d)
{
	if (fabs(d) < ESP)
	{
		return *this;
	}
	CTFNMat tempMat(*this);
	for (int i = 0; i < m_nRow; i++)
	{
		for (int j = 0; j < m_nCol; j++)
		{
			tempMat.m_pTFN[i * m_nCol + j] = m_pTFN[i * m_nCol + j] - d;
		}
	}
	return tempMat;
}

CdMat CTFNMat::doublize()
{
	CdMat Mat(m_nRow, m_nCol);
	for (int i = 0; i < m_nRow; i++)
	{
		for (int j = 0; j < m_nCol; j++)
		{
			Mat.m_pdData[ i * m_nCol + j] = m_pTFN[i * m_nCol + j].doublize();
		}
	}
	return Mat;
}



⌨️ 快捷键说明

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