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
|
// *******************************************************************************
food food operator + (const food& a, const food& b){
string nme = a.name;
double cpro = a.protein + b.protein;
double cfib = a.fiber + b.fiber;
double cft = a.fat + b.fat;
double ccal = a.calories + b.calories;
food temp( nme, cpro, cfib, cft, ccal);
return temp;
}
// *******************************************************************************
food food operator - ( food& a, const food& b){
string st= a.name;
int del = st.find(b.name);
del = del -1;
string st2 = b.name;
int nxt = st2.length();
st.erase(del,nxt);
double cpro = a.protein - b.protein;
double cfib = a.fiber - b.fiber;
double cft = a.fat - b.fat;
double ccal = a.calories - b.calories;
food temp( st, cpro, cfib, cft, ccal);
return temp;
}
// *******************************************************************************
food food operator / (const food& a, int div){
string nme = a.name;
double cpro = a.protein / div;
double cfib = a.fiber / div;
double cft = a.fat / div;
double ccal = a.calories / div;
food temp( nme, cpro, cfib, cft, ccal);
return temp;
}
// *******************************************************************************
food food operator * (food& a, const int mul){
string nme = a.name;
double cpro = a.protein * mul;
double cfib = a.fiber * mul;
double cft = a.fat * mul;
double ccal = a.calories * mul;
food temp( nme, cpro, cfib, cft, ccal);
return temp;
}
// *******************************************************************************
bool food :: operator < (food& a, food& b){
return (a.calories < b.calories);
}
// *******************************************************************************
bool food :: operator > (food& a, food& b){
return (a.calories > b.calories);
}
// *******************************************************************************
bool food operator == (const food& a,const food& b){
return bool (a.calories == b.calories);
}
// *******************************************************************************
food food operator = (const food& b){
if(this == &b)
return *this;
}
|