You are on page 1of 2

Pow is for bringing things up with exponents

X^2 = pow (x, 2)


X^5 = pow (x, 5)
3.3

Operations are performed between operands of the same type.


If not the same type, C++ will convert it.
Hierachy of Conversion:
o Long double
o Double
o Float
o Unsigned long
o Long
o Unsigned int
o Int
Type Coercion: automatic conversion of an operand to another data type
Promotion: convert to a higher type
Demotion: convert to a lower type
Rules
o Char, shorts, and unsigned shorts automatically promoted to int
o When operating on values of different types, it goes to the higer one.

3.5
static_cast<DataType>(Value)

DataType is the type of data that you want the value to be


Value is the variable that we want converted

double number = 37;


int val;
val = static_cast<int>(number);

3.6
Multiple Assignment and Combined Assigned
X=y=z=5
sum = sum + 1
sum + = 1
3.7

Formatting Output

Can control how output displays for numeric, string data:


o Size
o Position
o Number of digits
Requires header file iomanip
Stream Manupulators
o Used to control how an output field is displayed
o Some affect just the next value displayed:
Setw(x): print in a field at least x spaces wide.
o Some affect values until changed again:
Fiexed: use decimal notation for floating-point values
Setprecision(x): when used with fixed, print floating- point value
using x dogots after the decimal.

3.8
C++ passes over spaces
Use getline to include strings with spaces
Ex: getline (cin, name) ;
Use cin.get () to allow you to cin any character even if it is a white space (space,
tab)
Ex: cin.get (ch);

You might also like