CHAP03 - Chapter 3 Numeric Types, Expressions, and Output

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Chapter 3 Topics Constants of Type int and float Evaluating Arithmetic Expressions Implicit Type Coercion and Explicit Type Conversion Calling a Value-Returning Function Using Function Arguments Using C++ Library Functions in Expressions Calling a Void Function C++ Manipulators to Format Output String Operations length , find , substr
Background image of page 2
3 C++ Data Types C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long double
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 C++ Simple Data Types C++ Simple Data Types simple types integral floating char short int long bool enum float double long double unsigned
Background image of page 4
5 Standard Data Types in C++ Integral Types represent whole numbers and their negatives declared as int , short , or long Floating Types represent real numbers with a decimal point declared as float , or double Character Type represents single characters declared as char
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Samples of C++ Data Values int sample values 4578 -4578 0 float sample values 95.274 95. .265 9521E-3 -95E-1 95.213E2 char sample values B d 4 ? *
Background image of page 6
7 Scientific Notation 2.7E4 means 2.7 x 10 4 = 2.7000 = 27000.0 2.7E-4 means 2.7 x 10 - 4 = 0002.7 = 0.00027
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 More About Floating Point Values floating point numbers have an integer part and a fractional part, with a decimal point in between. Either the integer part or the fractional part, but not both, may be missing EXAMPLES 18.4 500. .8 -127.358 alternatively, floating point values can have an exponent, as in scientific notation--the number preceding the letter E doesn’t need to include a decimal point EXAMPLES 1.84E1 5E2 8E-1 -.127358E3
Background image of page 8
9 Division Operator the result of the division operator depends on the type of its operands 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 value 2.75 11 / 4.0 has value 2.75
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 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
Background image of page 10
11 Function main Continued 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 ; }
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 Modulus Operator
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 85

CHAP03 - Chapter 3 Numeric Types, Expressions, and Output

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online