{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 3 - Looping and Counting

Lecture 3 - Looping and Counting - LoopingandCounting...

Info icon This 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 [email protected] http://www.cct.lsu.edu/˜ hkaiser /fall_2011/csc1254.html  
Image of page 1

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

View Full Document Right 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/2 011,  Lecture  3 CSC 1254,  Fall 2011,  Looping  and  Counting 2
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 8/30/2 011,  Lecture  3 CSC 1254,  Fall 2011,  Looping  and  Counting 3
Image of page 3

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

View Full Document Right Arrow Icon
Types and Literals Built-in types Boolean type bool Character types char Integer types int and short and long Floating-point types Boolean literals true, false Character literals 'a', 'x', '4', '\n', '$' Integer literals 0, 1, 123, -6, 0x34,  0xa3 Floating point literals 8/30/2 011,  Lecture  3 CSC 1254,  Fall 2011,  Looping  and  Counting 4
Image of page 4
Types and Value Ranges int short long double float char string 4 bytes: -231…+231-1 2 bytes: -215…+215-1 8 bytes: -263…+263-1 8 bytes: -1.8e+308 …  1.8e+308, 15 digits 4 bytes: -3.4e+38 …  3.4e+38, 6 digits 1 byte: -27…+27-1 Arbitrary length character  8/30/2 011,  Lecture  3 CSC 1254,  Fall 2011,  Looping  and  Counting 5
Image of page 5

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

View Full Document Right Arrow Icon
Definition and Initialization int a = 7; int b = 9; char c = 'a'; double x = 1.2; std::string s1 = "Hello"; 8/30/2 011,  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:
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/2 011,  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:
Image of page 7

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

View Full Document Right Arrow Icon
Types and Objects A type
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern