Chapter 3: Variables, Functions, Math, and Strings

Slides:



Advertisements
Similar presentations
PIIT Computer Science Summer Camp - Alice July 10, 2012 Brenda Parker Computer Science Department MTSU.
Advertisements

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Chapter 2: Input, Processing, and Output
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Branching and Looping Examples, cont’d. Remember the generic triple jump world…
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Section 3 Calculations National 4/5 Scratch Course.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
Section 2 Variables National 4/5 Scratch Course. What you should know after this lesson What a variable is Where variables are stored How to get data.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Exam scores by range 3-1.
Variables & Random Number Generation.  A penguin is playing arctic basketball. The penguin has a basketball and will push the basketball toward.
Introduction to Programming with RAPTOR
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Nonvisual Arrays by Chris Brown under Prof. Susan Rodger Duke University June 2012.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Chapter 02 (Part II) Introduction to C++ Programming.
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
Chapter 2 Basic Computation
Starting Out with Alice: A Visual Introduction to Programming
Chapter 2: Input, Processing, and Output
Chapter 3: Variables, Functions, Math, and Strings
2.5 Another Java Application: Adding Integers
Design & Technology Grade 7 Python
The Selection Structure
Variables, Expressions, and IO
Introduction to Scripting
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
Variables and Arithmetic Operations
Topics Introduction to File Input and Output
Introduction to C++ Programming
WEB PROGRAMMING JavaScript.
T. Jumana Abu Shmais – AOU - Riyadh
Chapter 2: Programming in Alice
Introduction to TouchDevelop
CIS 16 Application Development Programming with Visual Basic
Variables and Expressions
Using Functions
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
An Introduction to Programming Using Alice 2.2, Second Edition
Using Lists and Functions to Create Dialogue
ICT Gaming Lesson 3.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Chapter 2 Programming Basics.
Using screens and adding two numbers - addda.cbl
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
JavaScript: Introduction to Scripting
Chapter 2: Input, Processing, and Output
Unit 3: Variables in Java
Topics Introduction to File Input and Output
Presentation transcript:

Chapter 3: Variables, Functions, Math, and Strings Starting Out with Alice: A Visual Introduction to Programming Third Edition by Tony Gaddis

3.1 Variables Programs may need to store data when running and it stores that data in a variable A variable is a named storage location in the computer’s memory The following types of data (or variables) can be stored: local variables parameter variables class-level variables world-level variables

Variable Types Local variables Parameter variables 3.1 Variable Types Local variables belongs to a specific method used only by the instructions that the variable belongs to when a method stops, the variables cease to exist Parameter variables used to hold an argument that is passed to a called method Class-level variables variable that belongs to a specific object World-level variables variable that belongs to the world

Creating Local Variables 3.1 Creating Local Variables Local variables belong to a specific method (such as world.my first method) Variables require 3 things: name type initial value name type value

Names and Types and Initial Values 3.1 Names and Types and Initial Values Variable Names Must be unique within the method Should be meaningful and reflect the variable’s purpose Named using camelCase Variable Types Numbers, Boolean, Objects, Other (such as String, Color, or Sound) Initial Value Value initially stored in the variable

Variables Tile appearance shows the type of variable 3.1 Variables Tile appearance shows the type of variable Creating the tile is called variable declaration variable area

Variable Assignment Variables have an initial value 3.1 Variable Assignment Variables have an initial value Initial value held until a different value is assigned New values can be assigned while the method is running Set instructions can be created to store (or set) different values Request to set a value occurs when variable tile dropped into Methods Editor

Variable Task……

Functions Each object has a set of primitive functions 3.2 Functions Each object has a set of primitive functions List of functions is categorized Boolean logic Math Random String Ask user Mouse Time Advanced math Other

Asking the User for Input 3.2 Asking the User for Input World has three primitive functions that ask for user input Each function is displayed in a dialog box Is it Yes or is it No?

Primitive Object Functions 3.2 Primitive Object Functions Each object has primitive functions different from the world’s primitive functions Proximity Size Spatial relation Point of view Other

Task…. -Complete Tutorial 3-1 Creating and using a variable on page 116-117 -Complete tutorial 3-2 Creating a set instruction for a variable on pages 118-119 Create the tutorial 3-3 on page 122 which is called Calling an ask user function on pages 122-125(You will use Tutorial 3-2 the jumping penguins for this task)

Creating Math Expressions 3.3 Creating Math Expressions Math Operators are used to create math expressions Math expressions perform a calculation and return a value Operands appear to the right and left of an operand payRate * hoursWorked “payRate” and “hoursWorked” are operands Operator Description + Addition - Subtraction * Multiplication / Division

Task…….. Create tutorial 3-4 called Using a proximity function on pages 127 -129 Complete the Using Math to avoid collisions within Tutorial 3-5 on pages 132-138

Working with Strings and Text 3.4 Working with Strings and Text A string is a sequence of characters Strings represent: names addresses messages etc.

Asking the User to Enter a String 3.4 Asking the User to Enter a String World’s primitive function can ask use to enter string (text) The function returns the text the user enters Joining separate sets of strings is called concatenation “Hello” joins with the user’s name What’s your name? Hello, Jo!

Joining Strings String Concatenation 3.4 Joining Strings String Concatenation Joins string a with string b Strings a and b are arguments Does not change the values of strings a or b…but combines the two strings Strings are NOT just text… but any alphanumeric character Can convert numbers to a string for use as well

Task…. Open Tutorial 3-5 and add the Nerd and the methods that are located on page 138-140. Remember to first create a variable called name, then drag the variable into the method to assign an initial value, then you will use the worlds function to ask user for a string and finally use the Nerds method to say what was typed. Then add a way to join strings(figure3-49) Complete the tutorial on page 141 3-6 called Converting a Number variable to a string.

Text can be added to Alice worlds 3.4 3D Text Text can be added to Alice worlds 3D text option is available at the end of the local gallery

Skills Check…… Students will choose two of the following to complete from pages 146 – 148. (50 points each) -Exercise 1,3,4,5 Students should complete the following challenge programs(100 points each) 7&8