




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





CSE 1301
Figures from Lewis, āC# Software Solutionsā, Addison Wesley
CSE 1301 (^) 5B-
CSE 1301 (^) 5B-
CSE 1301 (^) 5B-
// Part 1: Compute 11 * .1 two ways double d1 = .0; // add .1 to 0 eleven times d1 += .1; // 1 d1 += .1; // 2 d1 += .1; // 3 d1 += .1; // 4 d1 += .1; // 5 d1 += .1; // 6 d1 += .1; // 7 d1 += .1; // 8 d1 += .1; // 9 d1 += .1; // 10 d1 += .1; // 11 double d2 = .1 * 11; // compute 11 *. C.O.Wln( "d1 = " + d1 ); C.O.Wln( "d2 = " + d2 ); if ( d1 == d2 ) C.O.Wln( "d1 and d2 are equal" ); else C.O.Wln( "d1 and d2 are not equal" ); // Part 2: Compare float and double with same value float piF = 3.141592653589793f; double piD = 3.141592653589793; C.O.Wln( "\npiF = " + piF ); C.O.Wln( "pid = " + piD ); if ( piF == piD ) C.O.Wln( "piF and piD are equal" ); else C.O.Wln( "piF and piD are not equal" );
CSE 1301 (^) 5B-
// Part 1: Same as last example C.O.Wln( "d1 = " + d1 ); C.O.Wln( "d2 = " + d2 ); if ( Math.abs( d1 - d2 ) < .0001 ) C.O.Wln( "d1 and d2 are considered equal" ); else C.O.Wln( "d1 and d2 are not equal" );
// Part 2: Compare float and double with same value float piF = 3.141592653589793f; double piD = 3.141592653589793; C.O.Wln( "\npiF = " + piF ); C.O.Wln( "piD = " + piD ); if ( Math.abs( piF - piD ) < .0001 ) C.O.Wln( "piF and piD are considered equal" ); else C.O.Wln( "piF and piD are not equal" );
CSE 1301 (^) 5B-
CSE 1301 (^) 5B-
if ( Math.abs( d1 - d2 ) < THRESHOLD ) C.WL("d1 and d2 are considered equal"); else C.WL("d1 and d2 are not equal");
CSE 1301 (^) 5B-
CSE 1301 (^) 5B-
CSE 1301 (^) 5B-
CSE 1301 (^) 5B-
if ( x == 2 ) if ( y == x ) C.O.Wln( "x and y equal 2" ); else
CSE 1301 (^) 5B-
if ( x == 2 ) { if ( y == x ) C.O.Wln( "x and y equal 2" ); } else C.O.Wln( "x does not equal 2" );
if ( x == 2 ) if ( y == x ) C.O.Wln( "x and y equal 2" ); else // paired with ( y == x ) C.O.Wln( "y does not equal 2" ); else // paired with ( x == 2 ) C.O.Wln( "x does not equal 2" ); else // no matching if! C.O.Wln( "x and y are not equal" );
CSE 1301 (^) 5B-
float average;
average = 100.0;
if ( average >= 60.0 ) if ( average < 70.0 ) C.O.Wln(āMarginal PASSā); else C.O.Wln(āFAILā);
average
CSE 1301 (^) 5B-
float average;
average = 100.0;
if ( average >= 60.0 ) { if ( average < 70.0 ) C.O.Wln(āMarginal PASSā); } else C.O.Wln(āFAILā);
average
CSE 1301 (^) 5B-
CSE 1301 (^) 5B-
switch ( char or integer expression ) { case constant1: // statement(s); break; // optional case constant2: // statement(s); break; // optional ⦠default: // optional statement(s); ⦠}
CSE 1301 (^) 5B-
Write a logical assignment statement for each of the following:
CSE 1301 (^) 5B-
CSE 1301 (^) 5B-
if (taxCode == āTā)
price = price + taxRate * price;
if ( code == 1) { taxDue = income * taxRate; C.O.Wln(taxDue); }
CSE 1301 (^) 5B-
if ( ( A > 0 ) && (A < 5) )
else