lecture1slides

lecture1slides - Whats Up Today? 1. Project #1 Questions...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Whats Up Today? 1. Project #1 Questions and Answers 2. Lots of programming examples 3. More about variables 4. if statements and expression evaluation 5. Programming challenges // example of printing to the screen #include <iostream> int main(void) { std::cout << "Hello world!"; std::cout << "Goodbye...\n "; return(0); } // questions: // 0. what does #include do? // 1. what is a statement? // 2. how will this print out? // 3. indentation? // 4. what does return(0) do? // 5. what is a string? // 6. can statements span multiple // lines? // printing to the screen with newlines #include <iostream> int main(void) { std::cout << "Hello world!\n"; std::cout << "Good\nbye!\n"; return(0); } // printing to the screen with other // escape codes #include <iostream> int main(void) { std::cout << "Hello world!\n"; std::cout << "Good\tbye!\n"; // question: how do we insert a // backslash in a string? // how about a quote? return(0); } // this example shows: // 1. integer variable declaration, // use meaningful variable names // 2. use of math // 3. more complex output with cout #include <iostream> int main(void) { int years_old, careys_hairs; std::cout << "How old is carey? "; std::cin >> years_old; careys_hairs = 100 - years_old; std::cout << "carey has " << careys_hairs << " hairs left." << std::endl; return(0); } Questions: 1. naming rules for variables? 2. case sensitivity of all C++ code 3. what values can integers hold? 4. are variables case sensitive? 5. how do we choose variable names? 6. where should you define variables? 7. what does endl do? Variable Overview We declare variables in our C++ programs to hold data for our program. In our program, each variable has a type , a name , a value and a size . Common types and their attributes: Type Size Information int 4 bytes (or 2) Can hold whole numbers between -2147483648 to 2147483647 (-32768 to 32767) long 4 bytes (or 8) Can hold whole numbers between -2147483648 to 2147483647 (-9223372036854775808 to 9223372036854775807) char 1 byte Can hold whole numbers from -128 to 127 unsigned int 4 bytes (or 2)...
View Full Document

This note was uploaded on 10/08/2011 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.

Page1 / 21

lecture1slides - Whats Up Today? 1. Project #1 Questions...

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

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