Variables & Datatypes CSE 120 Spring 2017

Slides:



Advertisements
Similar presentations
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Advertisements

Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
IAT 800 Foundations of Computational Art and Design Lecture 2.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
LOOP & Type Conversion. do – while Loop In the while loop, the test expression is evaluated at the beginning of the loop. If the test condition is false.
CHAPTER # 2 Part 2 PROGRAMS AND DATA 1 st semster King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
Lesson Two: Everything You Need to Know
LCC 6310 Computation as an Expressive Medium Lecture 2.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004.
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
Nested Loops & Arrays CSE 120 Spring 2017
Chapter # 2 Part 2 Programs And data
Expressions & Control Flow CSE 120 Spring 2017
Basic Input and Output CSE 120 Spring 2017
ITM 352 Data types, Variables
ECE Application Programming
Processing Introduction CSE 120 Spring 2017
Memory, Data, & Addressing II CSE 351 Autumn 2017
Computing Fundamentals
Review Questions If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) 64 bits is the size of a pointer.
Developing an App CSE 120 Spring 2017
Functions in Processing CSE 120 Spring 2017
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Lightbot and Functions CSE 120 Winter 2017
Primitive Data, Variables, Loops (Maybe)
Mid-Quarter Review CSE 120 Winter 2018
Functions in Processing CSE 120 Winter 2018
Puzzle App II CSE 120 Winter 2018
Basic Input and Output CSE 120 Winter 2018
Variables & Datatypes CSE 120 Winter 2018
Memory, Data, & Addressing II CSE 410 Winter 2017
Processing and Drawing CSE 120 Winter 2018
Expressions & Control Flow CSE 120 Winter 2018
Introduction to Python and programming
Binary Numbers CSE 120 Spring 2017
Developing an App II CSE 120 Spring 2017
Review Questions If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) 64 bits is the size of a pointer.
Lightbot and Functions CSE 120 Winter 2018
Strings, Puzzle App I CSE 120 Winter 2018
Programming Funamental slides
Nested Loops, Arrays CSE 120 Winter 2018
Announcements Mid-Term Exam!! Quiz 5 Again + Quiz 6 Exercise 5
More programming with "Processing"
Memory, Data, & Addressing II CSE 351 Summer 2018
Introduction to Python and programming
Testing and Repetition
Chapter # 2 Part 2 Programs And data
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
ICT Gaming Lesson 3.
INC 161 , CPE 100 Computer Programming
Functions in Processing CSE 120 Winter 2019
Basic Input and Output CSE 120 Winter 2019
Variables & Datatypes CSE 120 Winter 2019
Arrays CSE 120 Winter 2019 Instructor: Teaching Assistants:
Lecture 4: Expressions and Variables
Loops.
Processing and Drawing CSE 120 Winter 2019
Life is Full of Alternatives
Loops & Nested Loops CSE 120 Winter 2019
Announcements How to save your work? Quiz solution 5/5/2019
Buttons & Boards CSE 120 Winter 2019
LCC 6310 Computation as an Expressive Medium
EECE.2160 ECE Application Programming
Lec 21 More Fun with Arrays: For Loops
Expressions & Conditionals CSE 120 Winter 2019
Lecture 2 - Names & Functions
Presentation transcript:

Variables & Datatypes CSE 120 Spring 2017 Instructor: Teaching Assistants: Justin Hsia Anupam Gupta, Braydon Hall, Eugene Oh, Savanna Yee Please stop charging your phone in public ports "Just by plugging your phone into a [compromised] power strip or charger, your device is now infected, and that compromises all your data," Drew Paik of security firm Authentic8 explained. Public charging stations and wi-fi access points are found in places like airports, planes, conference centers and parks, so people can always have access to their phones and data. But connecting your phone to an unknown port has its risks. The cord you use to charge your phone is also used to send data from your phone to other devices. If a port is compromised, there's no limit to what information a hacker could take, Paik explained. http://money.cnn.com/2017/02/15/technology/public-ports-charging-bad-stop/

Administrivia Assignments: Assignment rubrics on Canvas Taijitu due today (4/5) Reading Check 2 due tomorrow (4/6) Custom Logo due Friday (4/7) Assignment rubrics on Canvas No “big ideas” lecture this week More time on programming

Lab: Custom Logo

Lab: Custom Logo

Drawing a Square [See Demo on Panopto]

Variables Piece of your program that holds the value of something Every variable must be given a name and a datatype The values of these variables can change (i.e. vary) during the execution of your program Warning: Not like a variable in Algebra (i.e. an unknown) Assignment: give a variable a specific value e.g. x = 12; Read: use the current value of a variable e.g. y = x + 1;

Datatypes int: integers float: decimal/real numbers color: a triple of numbers representing RGB boolean: true or false Many more exist and can be found in the Processing Reference:

Declarations We declare a variable by telling Processing the variable’s datatype, followed by the variable’s name: You can also give a variable a starting value (initialization) in the same line as the declaration:

Drawing a Square with Variables [See Demo on Panopto]

Variable Rules & Guidelines Variables are case-sensitive e.g. leftside is not the same as leftSide Variable names are meaningless to computers, but meaningful to humans Choosing informative names improves readability and reduces confusion In this class, most of our variables will be declared and initialized at the very top of our programs

Variable Manipulation Executed sequentially, just like other statements For variable assignments, compute right-hand side first, then store result in variable Example: int x = 4; x = x + 1; Read the current value of x (4) for the right-hand side Add 1 to the current value of x Store the result (5) back into x

Variable Practice int x = 1; int y = 2; int z = 3; x = x + 1; y = y - 1; z = z + 2; int x = 7; int y = 2; int z = 0; x = x + 3; y = y – 2; z = x + y; int x = -1; int y = 0; int z = 5; x = x + z; y = y – x; z = x + z; x y z x y z x y z

TMNT: Donatello

Donatello with a Variable

Donatello with Motion In setup(), set x_pos = 0; In draw(), change x_pos: x_pos = x_pos + 1;

Stopping Motion Stop Donatello from running off the right side of the screen: x_pos = min(x_pos + 1, 460); Stop Donatello from running off the left side of the screen: x_pos = max(x_pos - 1, 0);

Falling Into Place Introduce variables for each body segment: Update each variable at different speeds:

Falling Into Place Update y-positions of drawing based on new variables:

Summary Variables are named quantities that can vary during the execution of a program Datatypes specific different forms of data e.g. int, float, color, Boolean Variable declarations specify a variable datatype and name to the program Generally occurs at top of program min() and max() functions can be used to limit or stop change in a variable value