int main() { Stonewt arr[6] = {50, 100, 150}; for(int i = 3; i < 6; ++i) { cout << "Stonewt[" << i << "]: "; double pds; cin >> pds; Stonewt st = Stonewt(pds); arr[i] = st; } cin.get(); Stonewt max = arr[0], min = arr[0]; int num = 0; Stonewt eleven = Stonewt(11); for(int i = 0; i < 6; ++i) { if(arr[i] > max) max = arr[i]; if(arr[i] < min) min = arr[i]; if(arr[i] > eleven) num++; } cout << "max: " << endl; max.show_lbs(); cout << "min: " << endl; min.show_lbs(); cout << num << " elements > 11 stones" << endl; cin.get(); return 0; }
int main(int argc, char *argv[]) { // a syntax for initializing a class object when using a // constructor with one argument. This is equivalent to the // other two forms: // standard syntax forms for initializing class objects // Stonewt incognito(275); // Stonewt incognito = Stonewt(275); Stonewt incognito = 275; // uses constructor to initialize Stonewt wolfe(285.7); // same as Stonewt wolfe = 285.7 Stonewt taft(21, 8); cout << "The celebrity weighed "; incognito.show_stn(); cout << "The detective weighted "; wolfe.show_stn(); cout << "the President weighed "; taft.show_lbs(); incognito = 276.8; // uses constructor for conversion taft = 325; // same as taft = Stonewt(325); cout << "After dinner, the celebrity weighed "; incognito.show_stn(); cout << "After dinner, the President weighed "; taft.show_lbs(); display(taft, 2); cout << "The wrestler weighed even more.\n"; display(422, 2); // convert 422 to double, then to Stonewt cout << "No stone left unearned\n"; return 0; }
int main(int argc, char const *argv[]) { Stonewt pavarotti = 260; Stonewt wolfe(285.7); Stonewt taft(21, 8); cout << "The tenor weighed "; pavarotti.show_stn(); cout << "The detective weighed "; wolfe.show_stn(); cout << "The President weighed "; taft.show_lbs(); pavarotti = 265.8; taft = 325; cout << "After dinner, the tenor weighed "; pavarotti.show_stn(); cout << "Afer dinner, the President weighed "; taft.show_lbs(); display(taft, 2); cout << "The wrestler weighed even more.\n"; display(422, 2); cout << "No stone left unearned\n"; double p_wt = pavarotti; cout << "Convert to double => "; cout << "pavarotti : " << p_wt << " pounds.\n"; cout << "Convert to int => "; cout << "pavarotti: " << int(pavarotti) << " pavarotti.\n"; return 0; }
int main() { Stonewt incognito = 275; // uses constructor to initialze Stonewt wolfe(285.7); // same as Stonewt wolfe = 285.7 Stonewt taft(21, 8); cout << "The celebrity weighed "; incognito.show_stn(); cout << "The detective weighed "; wolfe.show_stn(); cout << "The President weighed "; taft.show_lbs(); incognito = 276.8; // uses constructor for conversion; taft = 325; // same as taft = Stonewt(325); cout << "After dinner, the celebrity weighed "; incognito.show_stn(); cout << "After dinner, the President weighed "; taft.show_lbs(); display(taft, 2); cout << "The wrestler weighed even more.\n"; display(422, 2); cout << "No stone left unearned\n"; return 0; }
int main( int argc, char *argv[] ) { Stonewt incognito = 275; Stonewt wolfe(285.7); Stonewt taft(21, 8); cout << "The celebrity weigned "; incognito.show_stn(); cout << "The detective weighed "; wolfe.show_stn(); cout << "The President weighed "; taft.show_lbs(); incognito = 276.8; taft = 325; cout << "After dinner, the celebrity weighed "; incognito.show_stn(); cout << "After dinner, the President weighed "; taft.show_lbs(); display(taft, 2); cout << "The wrestler weighed even more.\n"; display(422, 2); cout << "No stone left unearned\n"; return 0; }
int main() { Stonewt incognito = 275; Stonewt wolfe(285.7); Stonewt taft(21.8); taft.mode_lbs(); cout << "Example #1:\n"; cout << "The celebrity weighed " << incognito; cout << "The detective weighed " << wolfe; cout << "The president weighed " << taft; incognito = 276.8; taft = 325; cout << "After dinner, the celebrity weighed " << incognito; cout << "After dinner, the detective weighed " << wolfe; cout << "After dinner, the president weighed " << taft; display(taft, 2); cout << "The wrestler weighed even more.\n"; display(422, 2); cout << "No stone left unearned\n"; cout << "Example #2:\n"; Stonewt poppins(9, 2.8); double p_wt = poppins; cout << "Convert to double => "; cout << "Poppins: " << p_wt << " pounds.\n"; cout << "Convert to int => "; cout << "Poppins: " << int(poppins) << " pounds.\n"; cout << "Example #3:\n"; incognito = 100; incognito.mode_lbs(); cout << "incognito = " << incognito; cout << "incognito * 1.242 = " << incognito * 1.242; cout << "incognito / 4.22 = " << incognito / 4.22; cout << "0.33 * incognito = " << 0.33 * incognito; cout << "taft = " << taft; cout << "incognito + taft = " << incognito + taft; cout << "incognito - taft = " << incognito - taft; cout << "Example #4:\n"; incognito.mode_stn(); cout << "incognito = " << incognito; cout << "taft = " << taft; cout << "incognito < taft: " << (incognito < taft) << '\n'; cout << "incognito <= taft: " << (incognito <= taft) << '\n'; cout << "incognito > taft: " << (incognito > taft) << '\n'; cout << "incognito >= taft: " << (incognito >= taft) << '\n'; cout << "incognito == taft: " << (incognito == taft) << '\n'; cout << "incognito != taft: " << (incognito != taft) << '\n'; return 0; }
void display(const Stonewt & st, int n) { for (int i = 0; i < n; i++) { cout << "Wow! "; st.show_stn(); } }
int main(void) { Stonewt pavarotti = 260; Stonewt wolfe(285.7); Stonewt taft(21, 8); cout << "The tenor weighed "; pavarotti.show_stn(); cout << "The President weighed "; taft.show_lbs(); pavarotti = 265.8; taft = 325; cout << "After dinner, the tenor weighted "; pavarotti.show_stn(); display(taft, 2); cout << "The wretler weighted even more.\n"; display(422,2); cout << "Noo stone left unearned\n"; return 0; }
int main() { Stonewt pavarotti = 260; // uses constructor to initialize Stonewt wolfe(285.7); // same as Stonewt wolfe = 285.7; Stonewt taft(21, 8); cout << "The tenor weighed "; pavarotti.show_stn(); cout << "The detective weighed "; wolfe.show_stn(); cout << "The President weighed "; taft.show_lbs(); pavarotti = 265.8; // uses constructor for conversion taft = 325; // same as taft = Stonewt(325); cout << "After dinner, the tenor weighed "; pavarotti.show_stn(); cout << "After dinner, the President weighed "; taft.show_lbs(); display(taft, 2); cout << "The wrestler weighed even more.\n"; display(422, 2); cout << "No stone left unearned\n"; return 0; }