Programming in c++ Division Operator the result of the division operator depends on the type of its operands o if one or both operands has a floating point type, the result is a floating point type. Otherwise, the result is an integer type 今 Examples 11/4 has value 2 11.0/4.0 has value2.75 11/4.0 has value 2.75
11 Division Operator vthe result of the division operator depends on the type of its operands vif one or both operands has a floating point type, the result is a floating point type. Otherwise, the result is an integer type vExamples 11 / 4 has value 2 11.0 / 4.0 has value 2.75 11 / 4.0 has value 2.75
Programming in c++ Main returns an int value to the operating system lr3 l Boil program l This program computes the midpoint between l the freezing and boiling points of water ∥/k*********★********★ 火火 # include≤ iostream> using namespace std const float FREEZE PT 32.0; Freezing point of water const float BOIL PT 212.0; l Boiling point of water int main( float avg Temp l/ Holds the result of averaging ∥/ FREEZE PT and BOIL Pt 12
12 Main returns an int value to the operating system //*************************************************************************** // FreezeBoil program // This program computes the midpoint between // the freezing and boiling points of water //*************************************************************************** #include < iostream > using namespace std; const float FREEZE_PT = 32.0 ; // Freezing point of water const float BOIL_PT = 212.0 ; // Boiling point of water int main ( ) { float avgTemp ; // Holds the result of averaging // FREEZE_PT and BOIL_PT
Programming in c++ Function main(Cont) cout<<“ Water freezes at“≤ FREEZE PT<<endl; cout<“ and boils at“≤<BOL_PT≤“ degrees.”≤<end; avg Temp FREEZE PT BOIL PT; avg Temp avg Temp /2.0; cout≤≤“ Halfway between is“ cout≤≤ avg Temp≤≤“ degrees.”≤endl return 0: 13
13 Function main (Cont.) cout << “Water freezes at “ << FREEZE_PT << endl ; cout << “ and boils at “ << BOIL_PT << “ degrees.” << endl ; avgTemp = FREEZE_PT + BOIL_PT ; avgTemp = avgTemp / 2.0 ; cout << “Halfway between is “ ; cout << avgTemp << “ degrees.” << endl ; return 0 ; }
Programming in c++ Modulus Operator o the modulus operator can only be used with integer type operands and always has an integer type result o its result is the integer type remainder of an integer division EXAMPLE 11 4 has value 3 because R 4)1 14
14 Modulus Operator vthe modulus operator % can only be used with integer type operands and always has an integer type result vits result is the integer type remainder of an integer division EXAMPLE 11 % 4 has value 3 because 4 ) 11 R = ?
Programming in c++ More C++ Operators int age; 8 age =8, age age= age + 1; 9 age 15
15 More C++ Operators 8 int age; age = 8; age = age + 1; age 9 age