c++primer plus第十四章第一题Wine类有一个string类对象和一个pair对象

#ifndef WINE_H_
#define WINE_H_
class Wine
{
private:
	typedef valarray<int>Arrayint;
	typedef pair<Arrayint, Arrayint>pairarray;
	string m_name;
	int m_year;
	pairarray m_num;
public:
	Wine(const char*l, int y) :m_name(l), m_year(y) { m_num.first.resize(y); m_num.second.resize(y); }
	Wine(const char*l, int y, const int yr[], const int bot[]);
	void Getbottles();
	string&Label();
	int sum()const;
	void show()const;
};
#endif
Wine::Wine(const char*l, int y, const int yr[], const int bot[]) :m_name(l), m_year(y)
{
	m_num.first.resize(y); 
	m_num.second.resize(y);
	for (int i = 0; i < m_year; i++)
	{
		m_num.first[i] = yr[i];
		m_num.second[i] = bot[i];
	}
}
void Wine::Getbottles()
{
	cout << "Enter Gully Wash data for " << m_year << "year(s)" << endl;
	for (int i = 0; i < m_year; i++)
	{
		cout << "Enter year: ";
		cin >> m_num.first[i];
		cout << "Enter bottle for that year: ";
		cin >> m_num.second[i];
	}
}
string&Wine::Label()
{
	return m_name;
}
int Wine::sum()const
{
	return m_num.second.sum();
}
void Wine::show()const
{
	cout << "Wine:  " << m_name << endl;
	cout << "\tYear" << "\tBottle" << endl;
	for (int i = 0; i < m_year; i++)
	{
		cout << "\t" << m_num.first[i] << "\t" << m_num.second[i] << endl;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值