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

📄 tfn.cpp

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


CTFN::CTFN(int nSize)
{
	if (nSize <= 0)
	{
		m_nSize = 0;
		m_pdNum = NULL;
	}
	else
	{
		m_nSize = nSize;
		m_pdNum = new double[nSize];
		for (int i = 0; i < m_nSize; i++)
		{
			m_pdNum[i] = 0;
		}
	}
}

CTFN::~CTFN(void)
{
	delete [] m_pdNum;

}

CTFN::CTFN(const CTFN &otherTFN)
{
	m_nSize = otherTFN.m_nSize;
	m_pdNum = new double[m_nSize];
	for (int i = 0; i < m_nSize; i++)
	{
		m_pdNum[i] = otherTFN.m_pdNum[i];
	}
}

void CTFN::Init()
{
	cout << "Please input FN:\n(";
	for (int i = 0; i < m_nSize; i++)
	{
		cin >> m_pdNum[i];
		cout << " , ";
	}
	cout << ")";
}

int CTFN::GetSize() const
{
	return m_nSize;
}

void CTFN::SetSize(int nSize)
{
	if (nSize < 0)
		return ;
	m_nSize = nSize;
	delete [] m_pdNum;
	m_pdNum = new double[m_nSize];
	Init();
}

CTFN CTFN::operator -(const CTFN &othertfn)
{
	CTFN tempTFN(m_nSize);
	if (m_nSize != othertfn.GetSize())
	{
		return *this;
	}
	else
	{
		for (int i = 0; i < m_nSize; i++)
		{
			tempTFN.m_pdNum[i] = m_pdNum[i] - othertfn.m_pdNum[i];
		}

	}
	return tempTFN;
}

const CTFN& CTFN::operator = (const CTFN &othertfn)
{
	if (&othertfn == this)
	{
		return *this;
	}
	m_nSize = othertfn.GetSize();
	delete [] m_pdNum;
	m_pdNum = new double[m_nSize];
	for (int i = 0; i < m_nSize; i++)
	{
		m_pdNum[i] = othertfn.m_pdNum[i];
	}
	return *this;
}

CTFN CTFN::operator +(const CTFN &othertfn)
{
	CTFN tempTFN(m_nSize);
	if (m_nSize != othertfn.GetSize())
	{
		return *this;
	}
	else
	{
		for (int i = 0; i < m_nSize; i++)
		{
			tempTFN.m_pdNum[i] = m_pdNum[i] + othertfn.m_pdNum[i];
		}

	}
	return tempTFN;
}

CTFN CTFN::operator *(const CTFN &othertfn)
{
	CTFN tempTFN(m_nSize);
	if (m_nSize != othertfn.GetSize())
	{
		return *this;
	}
	else
	{
		for (int i = 0; i < m_nSize; i++)
		{
			tempTFN.m_pdNum[i] = m_pdNum[i] * othertfn.m_pdNum[i];
		}

	}
	return tempTFN;
}

CTFN CTFN::operator *(double d)
{
	CTFN tempTFN(m_nSize);
	
	for (int i = 0; i < m_nSize; i++)
	{
		tempTFN.m_pdNum[i] = m_pdNum[i] * d;
	}

	return tempTFN;

}

CTFN CTFN::operator +(double d)
{
	CTFN tempTFN(m_nSize);
	
	for (int i = 0; i < m_nSize; i++)
	{
		tempTFN.m_pdNum[i] = m_pdNum[i] + d;
	}

	
	return tempTFN;

}

CTFN CTFN::operator -(double d)
{
	CTFN tempTFN(m_nSize);
	
	for (int i = 0; i < m_nSize; i++)
	{
		tempTFN.m_pdNum[i] = m_pdNum[i] - d;
	}

	
	return tempTFN;

}

CTFN CTFN::operator /(double d)
{
	CTFN tempTFN(m_nSize);
	if (fabs(d) < ESP)
	{
		return *this;
	}
	else
	{
		for (int i = 0; i < m_nSize; i++)
		{
			tempTFN.m_pdNum[i] = m_pdNum[i] / d;
		}

	}
	return tempTFN;
}

int CTFN::GetMax()
{
	double temp;
	temp = m_pdNum[0];
	for (int i = 0; i < m_nSize; i++)
	{
		if (temp < m_pdNum[i])
		{
			temp = m_pdNum[i];
		}
	}
	return int(temp);
}

int CTFN::GetMin()
{
	double temp;
	temp = m_pdNum[0];
	for (int i = 0; i < m_nSize; i++)
	{
		if (temp > m_pdNum[i])
		{
			temp = m_pdNum[i];
		}
	}
	return int(temp);
}

double CTFN::GetDmax(double dMax)
{
	double dDist;
	if (m_nSize == 3)
	{
		dDist = (m_pdNum[1] - dMax) * ( m_pdNum[1] - dMax); 
		dDist += 1 / 2 * (m_pdNum[1] - dMax) * ( ( m_pdNum[2] - m_pdNum[1]) - (m_pdNum[1] - m_pdNum[0]) );
		dDist += 1 / 9 * ( (m_pdNum[2] - m_pdNum[1]) * (m_pdNum[2] - m_pdNum[1]) + (m_pdNum[1] - m_pdNum[0]) * (m_pdNum[1] - m_pdNum[0]));
		dDist -= 1 / 9 * (m_pdNum[2] - m_pdNum[1]) * (m_pdNum[1] - m_pdNum[0]) ;
	}
	return dDist;
}

double CTFN::GetDmin(double dMin)
{
	double dDist;
	if (m_nSize == 3)
	{
		dDist = (m_pdNum[1] - dMin) * ( m_pdNum[1] - dMin); 
		dDist += 1 / 2 * (m_pdNum[1] - dMin) * ( ( m_pdNum[2] - m_pdNum[1]) - (m_pdNum[1] - m_pdNum[0]) );
		dDist += 1 / 9 * ( (m_pdNum[2] - m_pdNum[1]) * (m_pdNum[2] - m_pdNum[1]) + (m_pdNum[1] - m_pdNum[0]) * (m_pdNum[1] - m_pdNum[0]));
		dDist -= 1 / 9 * (m_pdNum[2] - m_pdNum[1]) * (m_pdNum[1] - m_pdNum[0]) ;
	}
	else
	{
		return 0;
	}
	return dDist;
}

double CTFN::doublize()
{
	return GetDmin(0);
}

⌨️ 快捷键说明

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