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

📄 item.h

📁 vc实现的0-1背包问题
💻 H
字号:
//////////////////////////////////////////////////////////////////////////
//
//									Item.h
//
//////////////////////////////////////////////////////////////////////////

#ifndef ITEM_H_H
#define ITEM_H_H

#include "CustomizedTypes.h"

#include <FSTREAM>
using namespace std;

template <class TProfit, class TWeight>
class Item
{
public:
	Item(TProfit p = 0, TWeight w = 0): m_profit(p), m_weight(w) {};					//constructor

	Item(const Item<TProfit, TWeight>& aItem) {											//copy constructor
		m_profit = aItem.GetProfit();
		m_weight = aItem.GetWeight();
	}

	TProfit GetProfit() const {
		return m_profit;
	}

	void SetProfit(TProfit p) {
		m_profit = p;
	}

	TWeight GetWeight() const {
		return m_weight;
	}

	void SetWeight(TWeight w) {
		m_weight = w;
	}

	operator = (const Item<TProfit, TWeight>& item) {									//重载赋值运算符
		m_profit = item.GetProfit();
		m_weight = item.GetWeight();
	}

	friend ofstream& operator << (ofstream& out, const Item<TProfit, TWeight>& item) {	//重载"<<"运算符
		out<<"("<<item.GetProfit()<<","<<item.GetWeight()<<")";
		return out;
	}

private:
	TProfit m_profit;
	TWeight m_weight;
};

#endif //ITEM_H_H

⌨️ 快捷键说明

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