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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
class item
{
public:
int code;
string title;
string trainer;
int duration;
struct date
{
int day, month, year;
date() :day(), month(), year(){}
date (int a, int b, int c): day(a), month(b), year(c){}
inline bool operator==(const date& x)
{
return day==x.day && month==x.month && year==x.year;
}
};
date start, end;
double price;
item(): code(), title(), trainer(), duration(), start(), end(), price() {}
item(int c, string tit, string train,
int dur, int dstart, int mstart, int ystart,
int dend, int mend, int yend, double pr):
code(c), title(tit), trainer(train), duration(dur),
start(dstart, mstart,ystart), end(dend, mend, yend), price(pr) {}
inline bool operator==(const item& x)
{
return code==x.code && title==x.title && trainer==x.trainer &&
duration==x.duration && start==x.start && end==x.end && price==x.price;
}
};
istream& operator>>(istream& fin, item::date a)
{
return fin>>a.day>>a.month>>a.year;
}
ostream& operator<<(ostream& stm, item::date a)
{
return stm<<a.day<<"."<<a.month<<"."<<a.year<<".";
}
istream& operator>>(istream& fin, item& a)
{
return fin>>a.code>>a.title>>a.trainer>>a.duration>>a.start>>a.end>>a.price;
}
ostream& operator<<(ostream& stm, item& a)
{
return stm<<a.code<<"\t"<<a.title<<"\t"<<a.trainer<<"\t"<<
a.duration<<"\t"<<a.start<<"\t"<<a.end<<"\t"<<a.price;
}
ostream& operator<<(ostream& stm, const vector<item>& vec)
{
for(auto a:vec)
{
stm<<a<<endl;
}
return stm;
}
class user
{
public:
string name;
string email;
string phone;
bool is_mediu;
vector<item> items;
double cost;
user(): name(), email(), phone(), is_mediu(), items(), cost(){}
user(string n, string mail, string num, bool mediu):
name(n), email(mail), phone(num), is_mediu(mediu), items(), cost(){}
void register_to(item it)
{
if (find(items.begin(), items.end(), it)!=items.end())
items.push_back(it);
if (is_mediu) cost+=it.price/5.0*4.0;
else cost+=it.price;
}
};
istream& operator>>(istream& fin, user& a)
{
a=user();
return fin>>a.name>>a.email>>a.phone>>a.is_mediu;
}
ostream& operator<<(ostream& stm, user& a)
{
return stm<<a.name<<"\t"<<a.items<<"\t"<<a.cost;
}
int main()
{
ifstream fin("sample.txt");
int n;
vector<user> users;
user temp1;
item temp2;
while (!fin.eof())
{
fin>>temp1>>n;
for (int i=0; i<n; i++)
{
fin>>temp2;
temp1.register_to(temp2);
}
}
cout<<"name\tcode\ttitle\ttrainer\tduration\tstart\tend\tprice\ttotal cost";
for(auto a:users)
{
cout<<a<<endl;
}
}
|