1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream> // Have all your includes in the header.
#include <valarray>
#include <string>
using namespace std;
typedef std::valarray<int> ArrayInt; // This is good
typedef std::pair<ArrayInt, ArrayInt> PairArray; // And so is this
// FIRST OFF BUILD YOUR CLASS //
class Wine : private PairArray, private std::string{
public:
Wine(const char * l, int y);
Wine(const char * l, int y, const int yr[], const int bot[]);
virtual ~Wine();
void Show() const;
void GetBottles();
private:
int m_iSize;
};
// THEN ALSO IN THE HEADER FILE ADD YOUR MEMBERS AFTER THE CLASS HAS BEEN BUILT //
Wine::Wine(const char * l, int y, const int yr[], const int bot[]) :
string(l), m_iSize(y), PairArray(ArrayInt(yr, y), ArrayInt(bot, y)) {
}
Wine::Wine(const char * l, int y) :
string(l), m_iSize(y), PairArray(ArrayInt(y), ArrayInt(y)) {
}
Wine::~Wine() {
}
void Wine::Show() const {
cout << (const string &)(*this) << endl << "year \t bottles\n";
for (int i = 0; i < m_iSize; i++) {
cout << PairArray::first[i] << "\t" << PairArray::second[i] << endl;
}
return;
}
void Wine::GetBottles() {
for (int i = 0; i < m_iSize; i++) {
cout << "Year, please: ";
cin >> PairArray::first[i];
cout << "Bottles, please: ";
cin >> PairArray::second[i];
}
cout << "job done!\n";
}
|