class length { public: int miles, furlongs, chains, feet, inches, lines; length(int m, int fu, int c, int fe, int i, int l) { miles=m; furlongs=fu; chains=c; feet=fe; inches=i; lines=l; } static length feet_inches(int f, int i) { length x(0,0,0,f,i,0); return x; } void print(void); void add(length x); void multiply(int x); }; |
void length::print(void) { printf("%d miles, %d furlongs, %d chains, %d feet, %d inches, %d lines", miles, furlongs, chains, feet, inches, lines); } void length::add(length x) { int carry; lines+=x.lines; carry=lines/12; lines=lines%12; inches+=x.inches+carry; carry=inches/12; inches=inches%12; feet+=x.feet+carry; carry=feet/66; feet=feet%66; chains+=x.chains+carry; carry=chains/10; chains=chains%10; furlongs+=x.furlongs+carry; carry=furlongs/8; furlongs=furlongs%8; miles+=x.miles+carry; } void length::multiply(iny x) { int carry; lines*=x; carry=lines/12; lines=lines%12; inches=inches*x+carry; carry=inches/12; inches=inches%12; feet=feet*x+carry; carry=feet/66; feet=feet%66; chains=chains*x+carry; carry=chains/10; chains=chains%10; furlongs=furlongs*x+carry; carry=furlongs/8; furlongs=furlongs%8; miles=miles*x+carry; } |
{ length a(0,0,0,50,10,0); length b(0,0,0,37,3,6); a.add(b); a.multiply(2); a.print(); } |
void length::add(length x) { lines+=x.lines; inches+=x.inches; feet+=x.feet; chains+=x.chains; furlongs+=x.furlongs; miles+=x.miles; normalise(); } void length::multiply(iny x) { lines*=x; inches*=x; feet*=x; chains*=x; furlongs*=x; miles*=x; normalise(); } |
void normalise(void); |
void length::normalise(void) { int carry; carry=lines/12; lines=lines%12; inches=inches+carry; carry=inches/12; inches=inches%12; feet=feet+carry; carry=feet/66; feet=feet%66; chains=chains+carry; carry=chains/10; chains=chains%10; furlongs=furlongs+carry; carry=furlongs/8; furlongs=furlong%8; miles=miles+carry; } |
x.inches=x.inches-1; |
x.inches=x.inches-1; x.normalise(); |
class length { protected: int miles, furlongs, chains, feet, inches, lines; public: length(int m, int fu, int c, int fe, int i, int l) { miles=m; furlongs=fu; chains=c; feet=fe; inches=i; lines=l; } static length feet_inches(int f, int i) { length x(0,0,0,f,i,0); return x; } void print(void); void add(length x); void multiply(int x); protected: void normalise(void); }; |
class length { protected: int lines; public: length(int m, int fu, int c, int fe, int i, int l) { lines=l+12*(i+12*(fe+66*(c+10*(fu+8*m)))); } static length feet_inches(int f, int i) { length x(0,0,0,f,i,0); return x; } void print(void); void add(length x) { lines=lines+x.lines; } void multiply(int x) { lines=lines*x; } }; void length::print(void) { int x=lines; int l=x%12; x/=12; int i=x%12; x/=12; int fe=x%66; x/=66; int c=x%10; x/=10; int fu=x%8; int m=x/8; printf("%d miles, %d furlongs, %d chains, %d feet, %d inches, %d lines", m, fu, c, fe, i, l); } |
{ length x(0,0,1,4,2,0); x.multiply(3); x.inches+=1; x.normalise(); x.print(); } |
class uncertain { protected: int number; public: void set_number(int x) { number=x; } int get_number(void) { return number; } }; |
void set_number(int x) { if (x!=13) number=x; } }; |
void length::remove_feet(void) { if (feet>=33) chains+=1; feet=0; } |
static length feet_inches(int f, int i) { length x(0,0,0,f,i,0); return x; } |
length height_of_joe=feet_inches(5,9); |
length x(0,2,4,6,2,1); blah blah blah x.add(feet_inches(5,9)); |
length add(length a, length b) { length x; x.lines=a.lines+b.lines; x.inches=a.inches+b.inches; x.feet=a.feet+b.feet; x.chains=a.chains+b.chains; x.furlongs=a.furlongs+b.furlongs; x.miles=a.miles+b.miles; return x; } |
static length add(length a, length b); |
static length length::add(length a, length b) { length x; as before return x; } |
length height_of_joe=length::feet_inches(5,9); |
length x(0,2,4,6,2,1); blah blah blah x.add(length::feet_inches(5,9)); |