Lecture 3 - Looping and Counting

Lecture 3 - Looping and Counting - Looping and Counting...

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

View Full Document Right Arrow Icon
Looping and Counting Lecture 3 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/˜hkaiser/fall_2011/csc1254.html
Background image of page 1

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

View Full DocumentRight Arrow Icon
Abstract First we’ll discuss types and type safety. Then we will modify the program we developed last time (Framing a Name) to make it more flexible. We will touch on arithmetic expressions, looping constructs and conditions. In addition we will talk about loop invariants and counting. 8/30/2011, Lecture 3 CSC 1254, Fall 2011, Looping and Counting 2
Background image of page 2
Types C++ provides a set of types ▫ E.g. bool, char, int, double ▫ Called “built-in types” C++ programmers can define new types ▫ Called “user-defined types” ▫ We'll get to that eventually The C++ standard library provides a set of types ▫ E.g. string, vector, complex ▫ Technically, these are user-defined types they are built using only facilities available to every user 8/30/2011, Lecture 3 CSC 1254, Fall 2011, Looping and Counting 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Types and Literals Built-in types Boolean type bool Character types char Integer types int and short and long Floating-point types double and float Standard-library types std::string std::complex<Scalar> Boolean literals true, false Character literals 'a', 'x', '4', '\n', '$' Integer literals 0, 1, 123, -6, 0x34, 0xa3 Floating point literals 1.2, 13.345, .3, -0.54, 1.2e3F, 3F, .3F String literals: "asdf", "Howdy, all y'all!" Complex literals std::complex<double>(12.3,99) std:: complex<float>(1.3F) 8/30/2011, Lecture 3 CSC 1254, Fall 2011, Looping and Counting 4
Background image of page 4
Types and Value Ranges int short long double float char string 4 bytes: -2 31 …+2 31 -1 2 bytes: -2 15 …+2 15 -1 8 bytes: -2 63 …+2 63 -1 8 bytes: -1.8e+308 … 1.8e+308, 15 digits 4 bytes: -3.4e+38 … 3.4e+38, 6 digits 1 byte: -2 7 …+2 7 -1 Arbitrary length character sequence 8/30/2011, Lecture 3 CSC 1254, Fall 2011, Looping and Counting 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
Definition and Initialization int a = 7; int b = 9; char c = 'a'; double x = 1.2; std::string s1 = "Hello"; std::string s2 = "1.2"; 8/30/2011, Lecture 3 CSC 1254, Fall 2011, Looping and Counting 6 7 9 'a' 1.2 5 | "Hello" 3 | "1.2" a: b: c: x: s1: s2:
Background image of page 6
Objects An object is some memory that can hold a value (instance) of a given type A variable is a named object A declaration names an object 8/30/2011, Lecture 3 CSC 1254, Fall 2011, Looping and Counting 7 int a = 7; char c = 'x'; complex<double> z(1.0,2.0); string s = "qwerty"; 7 a: "qwerty" 6 s: 'x' c: 1.0 2.0 z:
Background image of page 7

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

View Full DocumentRight Arrow Icon
Types and Objects A type ▫ Defines a set of values and a set of operations (for an object) An object ▫ Is some memory that holds a value of a given type A value ▫ Is a set of bits in memory interpreted according to a type A variable ▫ Is a named object A declaration ▫ Is a statement giving a name to an object
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/29/2011 for the course CSC 1254 taught by Professor Blanks,l during the Fall '08 term at LSU.

Page1 / 31

Lecture 3 - Looping and Counting - Looping and Counting...

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

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