Variables & Datatypes CSE 120 Winter 2018

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

Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
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.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CPS120: Introduction to Computer Science
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
CHAPTER # 2 Part 2 PROGRAMS AND DATA 1 st semster King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
LCC 6310 Computation as an Expressive Medium Lecture 2.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004.
Bill Tucker Austin Community College COSC 1315
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
Processing Introduction CSE 120 Spring 2017
Memory, Data, & Addressing II CSE 351 Autumn 2017
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Functions in Processing CSE 120 Spring 2017
Lightbot and Functions CSE 120 Winter 2017
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
Memory, Data, & Addressing II CSE 410 Winter 2017
Processing and Drawing CSE 120 Winter 2018
Expressions & Control Flow CSE 120 Winter 2018
Introduction to C++ Programming
Variables & Datatypes CSE 120 Spring 2017
Lightbot and Functions CSE 120 Winter 2018
Strings, Puzzle App I CSE 120 Winter 2018
Programming Funamental slides
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
CS111 Computer Programming
T. Jumana Abu Shmais – AOU - Riyadh
Nested Loops, Arrays CSE 120 Winter 2018
Announcements Mid-Term Exam!! Quiz 5 Again + Quiz 6 Exercise 5
Memory, Data, & Addressing II CSE 351 Summer 2018
Algorithms CSE 120 Winter 2018 Instructor: Teaching Assistants:
Memory, Data, & Addressing II CSE 351 Autumn 2018
Chapter # 2 Part 2 Programs And data
ICT Gaming Lesson 3.
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:
The Data Element.
Variables Lesson Outline
Loops & Nested Loops CSE 120 Winter 2019
Buttons & Boards CSE 120 Winter 2019
IAT 800 Foundations of Computational Art and Design
The Data Element.
Variables in C Topics Naming Variables Declaring Variables
LCC 6310 Computation as an Expressive Medium
Variables and Constants
Expressions & Conditionals CSE 120 Winter 2019
Presentation transcript:

Variables & Datatypes CSE 120 Winter 2018 Instructor: Teaching Assistants: Justin Hsia Anupam Gupta, Cheng Ni, Eugene Oh, Sam Wolfson, Sophie Tian, Teagan Horkan A Browser You’ve Never Heard of Is Dethroning Google in Asia "A mobile browser rarely used in the West has outflanked Google’s Chrome in some of Asia’s fastest-growing markets, giving owner Alibaba Group Holding Ltd. an advantage in the race among technology giants to capture the next generation of internet users. “Hundreds of millions of people in India, Indonesia and other emerging markets getting online for the first time are picking UC Browser, owned by Chinese e-commerce giant Alibaba, over ones made by U.S. rivals. Users say UC Browser works better in countries dominated by low-end smartphones and spotty mobile service. https://www.wsj.com/amp/articles/a-browser-youve-never- heard-of-is-dethroning-google-in-asia-1514808002

Administrivia Assignments: Signing up for Piazza [demo] Taijitu due before lab tomorrow (1/11) Reading Check 1 due tomorrow (1/11) Logo Design due Friday (1/12) Signing up for Piazza [demo]

Homework: Logo Design

Homework: Logo Design

Drawing a House One solution from worksheet: triangle(7,1, 3,5, 11,5); rect(3, 5, 8, 8); rect(8, 9, 2, 4); What if we wanted to move the house?

Variables Piece of your program that holds the value of something Every variable must be given a name and a data type 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/Write: give a variable a specific value e.g. x = 12;

Variables Piece of your program that holds the value of something Every variable must be given a name and a data type 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) Read: use the current value of a variable e.g. ellipse(x+1, 50, 20, 20);

Datatypes int integers (e.g. 12) float decimal/real numbers (e.g. 3.14) color RGB (e.g. color(0)) char characters (e.g. 'J') boolean true or false (e.g. true) 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:

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

Variable Rules & Guidelines Variable naming rules: Variables are case-sensitive (e.g. myx vs. myX) Numbers allowed, but not at beginning (e.g. k9 vs. 9k) Generally avoid symbols other than underscore (e.g. my_x) 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

Drawing a House with Variables Initial solution: triangle(7,1, 3,5, 11,5); rect(3, 5, 8, 8); rect(8, 9, 2, 4); What properties might be useful to store in variables?

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; 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); In draw(), change x_pos: x_pos = min(x_pos + 1, 460); In draw(), change x_pos: x_pos = min(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