{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

08 lecture

# 08 lecture - constants-if you have variables in your...

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

4/4/08 Roundoff Error : -We are used to thinking about numbers in the base 10 where the first column is the tenth place the second the hundredth place and so on. -A computer works in base 2 where the first place is 1, then 2, then 4, then 8, then 16, and so on up to 64. A computer uses combinations of these to create larger numbers Reassignment of variables: int a=4; int b=6; b=b+1; //this tells the computer to overwrite what the original value for b was, now b is 7 a= b-a; //now a is 3 Cast: - A way to treat one data type as another int a=7; int b=4; double c= (double) a/b; //since both a and b are int we will get one but since we assign it as a temporary double we will get floating point division -if you want to round a number int d= (int)(c + .5) // since the computer will only round down, by adding .5 we have a more accurate rounding because if c is less that 2.5 it will round down and if c is 2.5 or greater it will be 3 and in a sense round up

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: constants:-if you have variables in your program that you want to forbid from being reassigned you make it a constant const int A= 17; //if you try to change a later you will see an error. convention says that it is to be all caps-this helpful if you need to make changes later to a variable that shows up many times in your program Strings: # include <string> string z= "Bob"; cout<< z; //we would see it just print Bob because it is a string-the computer stores the string as B being 0, o being 1, and b being 2 dot notation: int c= z.length ( ); // this would set c as three because bob (z variable) is three characters long above is formatted as: object_name.member_function_name(parameters) string initial= z.substr(0,1); //the 0 is the start position and the 1 is the length-by doing something like this it would set the string initial as being bo because the parameter does not include the last b....
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

08 lecture - constants-if you have variables in your...

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

View Full Document
Ask a homework question - tutors are online