64,282
社区成员
发帖
与我相关
我的任务
分享
//head.h
#include <iostream>
#include <string>
#include <valarray>
using namespace std;
#ifndef HEAD_H_
#define HEAD_H_
template<class T1, class T2>
class Pair
{
private:
T1 a;
T2 b;
public:
Pair(const T1 & aval, const T2 & bval);
Pair();
};
class Wine
{
private:
typedef std::valarray<int> ArrayInt;
typedef Pair<ArrayInt, ArrayInt> PairArray;
string label; // wine brandname
int years; // number of years
PairArray data;
public:
Wine() : label("none"), years(0), data(ArrayInt(),ArrayInt()) {}
Wine(const char * l, int y, const int yr[], const int bot[]);
Wine(const char * l, const ArrayInt & yr, const ArrayInt & bot);
Wine(const char * l, const PairArray & yr_bot);
Wine(const char * l, int y);
};
#endif
#include "head.h"
template <typename T1, typename T2>
Pair<T1, T2>::Pair ():a(),b(){}
template <typename T1, typename T2>
Pair<T1, T2>::Pair (const T1 & t1, const T2 & t2):a(t1),b(t2){}
Wine::Wine(const char * l, int y, const int yr[], const int bot[])
: label(l), years(y), data(ArrayInt(yr,y),ArrayInt(bot,y) ){}
Wine::Wine(const char * l, const ArrayInt & yr, const ArrayInt & bot)
: label(l), years(yr.size()), data(ArrayInt(yr), ArrayInt(yr)){}
Wine::Wine(const char * l, const PairArray & yr_bot)
: label(l), years(yr_bot.first().size()), data(yr_bot) { }
Wine::Wine(const char * l, int y) : label(l), years(y),
data(ArrayInt(0,y),ArrayInt(0,y)){}