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 58 59 60 61 62 63 64 65 66 67 68 69 70
|
enum breed_t {dalmatian, boxer, bloodhound /*etc...*/};
breed_t string_to_breed_t(string x)
{
if (x=="dalmatian") return dalmatian;
/*etc.*/
}
string breed_t_to_string(breed_t x)
{
switch(x)
{
case dalmatian: return "dalmatian"; break;
/*etc.*/
}
}
class Dog
{
public:
struct date_t
{
int day, month, year;
date_t() :day(), month(), year(){}
date_t (int a, int b, int c): day(a), month(b), year(c){}
};
date_t arrival, birth;
breed_t breed;
ostream& operator<< (ostream& stm);
ifstream& operator>> (ifstream& fin);
Dog(): arrival(), birth(){}
friend string breed_t_to_string(breed_t x);
friend breed_t string_to_breed_t(string x);
Dog(int a, int b, int c, int d, int e, int f, string x): arrival(a, b, c), birth(d, e, f)
{
breed=string_to_breed_t(x);
}
};
ostream& operator<<(ostream& stm, Dog dog)
{
return stm<<dog.arrival.day<<"."<<dog.arrival.month<<"."<<dog.arrival.year
<<"."<<"\t"<<dog.birth.day<<"."<<dog.birth.month<<"."<<dog.birth.year
<<"."<<"\t"<<breed_t_to_string(dog.breed);
}
ifstream& operator>>(ifstream& fin, Dog& dog)
{
string a;
fin>>dog.arrival.day>>dog.arrival.month>>dog.arrival.year
>>dog.birth.day>>dog.birth.month>>dog.birth.year>>a;
dog.breed=string_to_breed_t(a);
return fin;
}
int main()
{
vector<Dog> array;
Dog a;
ifstream fin("sample.txt");
do
{
fin>>a;
array.push_back(a);
} while (!fin.eof());
for (auto a:array)
{
cout<<a<<endl;
}
}
| |