Types-expressions-functions

# Types-expressions-functions - Data Types, Expressions and...

This preview shows pages 1–9. Sign up to view the full content.

Data Types, Expressions and Functions (part I)

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

View Full Document
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
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

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

View Full Document
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 ? *
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

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

View Full Document
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 (E can be upper or lower case) Examples 1.84E1 5E2 8E-1 -.127358E3
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 (it truncates!!) Examples 11 / 4 has value 2 11.0 / 4.0 has value 2.75 11 / 4.0 has value 2.75 11.0 / 4 has value 2.75

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

View Full Document
//*************************************************** // 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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/13/2011 for the course CS 115 taught by Professor Staff during the Fall '08 term at Kentucky.

### Page1 / 41

Types-expressions-functions - Data Types, Expressions and...

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

View Full Document
Ask a homework question - tutors are online