#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;
}
}
c++primer plus第十四章第一题Wine类有一个string类对象和一个pair对象
最新推荐文章于 2022-04-09 22:05:56 发布