# VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Size: px
Start display at page:

Download "VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs."

Transcription

1 Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer the data is stored in the computer s memory. To visualise this, you might think of the computer s memory as millions of little boxes, each holding a single value. Normally, each box is numbered starting at zero. As a computer uses binary numbers (made up of 0s and 1s), the boxes may be numbered something like this: , which is 162 in decimal. The actual number of boxes depends on the amount of memory in the specific computer. When data is put into the computer, the computer stores the data in the boxes that are part of the computer s Random Access Memory (RAM), and the number of those boxes is referred to as the memory address. Obviously, for humans to refer to memory addresses by their binary index would be very difficult, so programming languages use a device called a variable. A variable is a word label that the programmer assigns to a piece of data, so they don t need to worry about where it is stored in memory or how to tell the computer where to find it. Variables are simple memory boxes with names. You, the programmer, supply these names. For example, the following lines first declare a variable called myage of data type Integer (it will store whole numbers), and then assigns the integer value 25 to myage: Dim myage As Integer myage = 25 When you declare a variable, you must give it a name (and then compiler will claim some memory space and associate the name with the binary address), and specify the type of data that will be stored in that variable. The keyword Dim (short for dimension) instructs the compiler to claim some memory space, set its name, and define the data type that will be stored in it. At this point, the variable will be empty, or more accurately, will contain a Null value. Null value exceptions can cause a lot of problems in programs and will be discussed in detail later. In the example above, the second line stores the value 25 in the variable named myage. This is called initialising a variable. It is important to initialise variables as soon as you have declared them, to prevent the possibility of Null exceptions, even if you don t know what value it will eventually hold (e.g. you will be getting data from the user later in your program). Variables can represent almost any value, and can be used in mathematical operations. 1

2 When naming your variables, there are a few rules you must follow to comply with the formal syntax for Visual Basic.NET. Variable names: Must start with a letter (a to z, A to Z) Can contain any number of letters or digits (a digit is 0 to 9) Can contain the underscore (e.g. _) Can be up to 255 characters long Visual Basic.NET is not case sensitive. This means that once a variable named, say width is declared, you cannot then declare another variable named, say Width, as to VB, they are considered identical. There are several different naming conventions used in programming; a popular style, Hungarian Notation, is described below. Make your variable names suggestive of what the variable represents, to increase readability of your code. Also, try to keep your names short and concise. It doesn t matter which naming style you decide to use, but be consistent, as changing styles throughout a program may make it hard to understand and maintain. Because text display is so important in computing, Visual Basic.NET has a number of functions and commands that manipulate text. For example, you can join two or more strings into one, find the length of a string, or convert numbers to strings or strings to numbers (more about string operations later). Arrays An array is a collection of one or more variables of the same type, which allows you to store many values under a single variable name. An array s subscript identifies each element of the array. You can think of arrays as being similar to a series of post boxes for an apartment building. Each apartment has its own post box, which is numbered (this is the subscript of the array), and the whole collection of post boxes is given the street address of the apartment building (this is the variable name of the array). To easily access each element of the array (say, within a loop) you can use a numerical variable for the array s subscript. An array subscript is placed between parentheses, i.e. (). By declaring an array with a Dim statement, VB will allocate the appropriate amount of memory for the array. For example, the following line declares an array of Integers called scores, which can hold six separate Integer values: Dim scores(5) As Integer Notice that the size of the array (how many elements it can hold) is declared between the parentheses; this array can hold six elements, with indices numbered from 0 to 5. This is an important point to remember indices are numbered from 0. Forgetting this will result in an "off by one" error. Assigning values to the separate elements of an array is done by specifiying the subscript, for example, this statement stores the value 30 in the third element of the scores array: scores(2) = 30 2

3 You can also use a variable for the subscript. The following lines declare a variable to be used for the array index and assign it the value of 2. Then using the variable called index, assign the third element of the scores array the value of 5: Dim index As Integer index = 2 scores(index) = 5 HUNGARIAN NOTATION Developed by Charles Simonyi from Microsoft, Hungarian Notation is a naming convention used to help programmers define and (more importantly) identify variable data types by a short abbreviation at the beginning of the variable name. There are many advantages with using Hungarian Notation. These include: The ability to quickly and easily debug programs. The ability for teams of programmers to work on the same code without getting confused by the names of variables. Mnemonic value, allowing the programmer to easily remember the name of a variable. Efficient creation of variable names. By using Hungarian Notation, the time taken to ponder over an effective name for a variable is dramatically reduced. Hungarian Notation uses a set of naming rules to ensure that all of the above advantages (and many more) are realised: Convenient punctuation is used to define a variable type and name. For example strname represents a string variable that will contain data on a person s name. Simple data types are named by short tags that are chosen by the programmer. This ensures the variable names do not become too long, making them more prone to typographical errors which could result in bugs. A short tag also reduces the time it takes to type out the variable, making the programmer more efficient. For example, intphone would be better to use than integerphone. As the variable names are determined by the programmer, each programmer may differ on their preferred views of how to use Hungarian Notation. For example, one programmer may declare a variable as curaccountbalance and another may declare it as curraccountbalance (note the extra r in curr). Both of these examples fit within the conventions of Hungarian Notation. As you can see, Hungarian Notation is an extremely useful convention. It is not required when you program in VB (or any other language) but it is highly recommended to get into the habit of using the convention to make your programs easy to debug and modify (by yourself and other programmers). By understanding the different data types, you will realise how useful Hungarian Notation is. By the way, the reason Hungarian Notation is named as such is due to the facts that Microsoft programmers who first saw it commented that the variables looked like they were in a language that was non-english and also that the creator Charles Simonyi was Hungarian. 3

4 KINDS OF VARIABLES (DATA TYPES) There are different types of variables for different types of data. The different data types require different amounts of memory, and your compiler will allocate the appropriate amount when you declare variables. Below is a list of some of the most commonly used numerical variable data types: Integer variables The standard integer can store whole numbers in the range -32,768 to 32,767. Long integer variables A variable for storing large integers, whole numbers in the range -2,147,483,648 to 2,147,483,647. Single precision floating point variables Used to store fractions in the range of E38 to E38. Double precision floating point variables Another large variable used to store fractions with high accuracy; numbers in the range E308 and E308. ASSIGNING VARIABLE VALUES Just as you can assign a value to a variable, you can assign one variable's value to another. For example, look at the following piece of code: intyourscore = inthighscore = intyourscore The first statement sets intyourscore (an integer) to The next statement, which is executed immediately after the first, assigns the value of intyourscore to inthighscore, i.e. it is a copy of the value in intyourscore both variables would contain exactly the same value. You can do more than that though. Say, you want to set one variable's value to be 100 more than another's. The following code does just that: dblworkersalary = 1000 dblbosssalary = dblworkersalary From the above example dblbosssalary will equal Now each time those two statements are executed, dblbosssalary (a double precision floating point variable) will be set to be 100 more than dblworkersalary (i.e. 1100). If dblworkersalary = 300 in the first statement then dblbosssalary will equal 400 in the second statement. Other mathematical operators could be used to produce the same or similar results, such as: dblworkersalary = dblbosssalary This statement has the same effect as the previous example, only written differently. 4

5 dblbosssalary = dblworkersalary Sets dblbosssalary to be 100 less than dblworkersalary (an unlikely event). dblbosssalary = dblworkersalary * 2 Sets dblbosssalary to be 2 times dblworkersalary (a more likely event). dblbosssalary = dblworkersalary / 3 Sets dblbosssalary to be one third of dblworkersalary (never going to happen). Now say you wish to increase a variable's value by 100. The following will increase dblbosssalary by 100: dblbosssalary = dblbosssalary When the statement is executed, the value of dblbosssalary is calculated first, and then the result is stored in dblbosssalary. This has the effect of increasing dblbosssalary by 100. Any mathematical operator can be used, for example, the following will double the variable's value: dblbosssalary = dblbosssalary * 2 For the most part, standard integers are used other data types such as floating point variables are rarely used. OPERATOR PRECEDENCE Arithmetic operators are the basic set of operators used to perform mathematical calculations. Operator Meaning ^ exponent (power of) * multiply / division of doubles \ division of integers Mod modulo (the remainder in a division, e.g. 3 Mod 2 = 1) + addition - subtraction The precedence of these operators means the order in which they are evaluated in a single statement. In the table above, exponent (^) has a higher precedence than multiplication (*) or division (/) which have the same precedence. Addition and subtraction have the lowest precedence, meaning they are evaluated last within a statement. Parentheses can be used to group calculations and ensure the correct evaluation of a statement. In the following two examples, the value of Total is different because of the parenthesies used in example two. 1. Total = 2+5*3 results in Total = Total = (2+5)*3 results in Total = 21 5

6 In example one above, the multiplication is evaluated first (i.e. multiplication has a higher precedence) and then the addition is calculated. The use of parentheses in the second example causes the addition to be evaluated first, even though normally addition is of lower precedence than multiplication. STRINGS Strings are variables that store text, words, phrases, sentences etc. If you type a letter in a word processor, the letter itself is held in a string variable in the computer's memory. To store text in a string, you have to enclose it in quotes and assign it to a string variable. For example, the following statement will store the phrase I'll be back in the strcliche string variable: strcliche = "I'll be back" The string variable strcliche now contains the phrase I'll be back, without the surrounding quotation marks. The quotation marks are only there to indicate where the text string begins and ends. All literal strings need to be surrounded by quote marks. As peculiar as it may sound, string variables can be added. Look at the following three statements: strword1 = "car" strword2 = "pet" strword3 = strword1 + strword2 The result is that strword3 would contain carpet. Because string variables contain text and not numerical values, the two strings are joined together, one after the other, to form one string (i.e. in string math, "car" + "pet" = "carpet"). The process of adding strings together to form larger strings is called concatenation. More than one string can be added at a time. For example, if the code were changed to: strword1 = "car" strword2 = "pet" strword3 = "My " + strword2 + " got " + strword1 + "sick." strword3 would now contain "My pet got carsick", because all those strings were joined together, one after the other. String variables (such as strword1) and literal strings (such as "got") may be added together. Note the use of spaces there is a space after My in the "My ", and one space before and one after got in the " got " string. These are put there to separate the text "My" from "pet" and "got" from "pet" and "car" respectively. There is no space in the "sick" string so that it forms up with the car to become "carsick". Note: Strings can ONLY be added and not subtracted. strword3 = strword1 strword2 is meaningless and will only result in Visual Basic.NET giving an error message. 6

8 2. Add a label control and a button control to the form. Change the properties of the controls so they display any way you like explore the options in the Properties panel and be creative; maybe add colour or change the font. Here s an example: 3. Double click on the form to display the Form1_Load() method. Add the following code: 'hide the label Label1.Hide() 4. Return to the form and double click on the Button to display the Button1_Click() method. Add the following code: 'declare some variables and initialise their values Dim num1 As Integer Dim num2 As Integer num1 = 8 num2 = 5 'Add the variables and display the sum in the label Label1.Text = num1 + num2 'Show the label Label1.Show() 8

9 5. Remember to indent your code appropriately. Your program should look like this: 6. Save your files (both the form and the code page), then click the Run button on the toolbar: 7. When the application first runs, After clicking the Add button, you should see: you should see: 9

### Programming Logic and Design Seventh Edition Chapter 2 Elements of High-Quality Programs

Programming Logic and Design Chapter 2 Elements of High-Quality Programs Objectives In this chapter, you will learn about: Declaring and using variables and constants Assigning values to variables [assignment

### Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Java Programming Fundamentals - Day 1 07.09.2016 Instructor: Jason Yoon Website: http://mryoon.weebly.com Quick Advice Before We Get Started Java is not the same as javascript! Don t get them confused

### Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

Chapter 2 Input, Processing, and Output Fall 2016, CSUS Designing a Program Chapter 2.1 1 Algorithms They are the logic on how to do something how to compute the value of Pi how to delete a file how to

### Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

### Variables, expressions and statements

Variables, expressions and statements 2.1. Values and data types A value is one of the fundamental things like a letter or a number that a program manipulates. The values we have seen so far are 2 (the

### Unit 3. Operators. School of Science and Technology INTRODUCTION

INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

### printf( Please enter another number: ); scanf( %d, &num2);

CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

### Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with

### Full file at

Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

### CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

### VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

VARIABLES WHAT IS A VARIABLE? A variable is a storage location in the computer s memory, used for holding information while the program is running. The information that is stored in a variable may change,

### Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

### Only to be used for arranged hours. Order of Operations

Math 84 Activity # 1 Your name: Order of Operations Goals: 1) Evaluate Real numbers with Exponents. ) Use the Order of Operations to Evaluate Expressions. ) Review Exponents and Powers of Ten Integer exponents

### VBScript: Math Functions

C h a p t e r 3 VBScript: Math Functions In this chapter, you will learn how to use the following VBScript functions to World Class standards: 1. Writing Math Equations in VBScripts 2. Beginning a New

### Section 1.1 Definitions and Properties

Section 1.1 Definitions and Properties Objectives In this section, you will learn to: To successfully complete this section, you need to understand: Abbreviate repeated addition using Exponents and Square

### Chapter 17. Fundamental Concepts Expressed in JavaScript

Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program

### TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

### C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

C++ PROGRAMMING For Industrial And Electrical Engineering Instructor: Ruba A. Salamh CHAPTER TWO: Fundamental Data Types Chapter Goals In this chapter, you will learn how to work with numbers and text,

### ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python ENGG1811 UNSW, CRICOS Provider No: 00098G W4 Computers have changed engineering http://www.noendexport.com/en/contents/48/410.html

### LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

LESSON VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT PROF. JOHN P. BAUGH PROFJPBAUGH@GMAIL.COM PROFJPBAUGH.COM CONTENTS INTRODUCTION... Assumptions.... Variables and Data Types..... Numeric Data Types:

### } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.

### Outline. Data and Operations. Data Types. Integral Types

Outline Data and Operations Data Types Arithmetic Operations Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Built-in) Functions Data and Operations Data and Operations

### Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

### LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

### Properties and Definitions

Section 0.1 Contents: Operations Defined Multiplication as an Abbreviation Visualizing Multiplication Commutative Properties Parentheses Associative Properties Identities Zero Product Answers to Exercises

### Creating a C++ Program

Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

### Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships

### CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

### Chapter 2 Basic Elements of C++

C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

### Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

Objectives Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs In this chapter, you will learn about: Declaring and using variables

### Chapter 2 Working with Data Types and Operators

JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics

### COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,

### CPS122 Lecture: From Python to Java last revised January 4, Objectives:

Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

### JME Language Reference Manual

JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.

### MITOCW watch?v=kz7jjltq9r4

MITOCW watch?v=kz7jjltq9r4 PROFESSOR: We're going to look at the most fundamental of all mathematical data types, namely sets, and let's begin with the definitions. So informally, a set is a collection

### UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . \$, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

### Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

### CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

### Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions Variable is a letter or symbol that represents a number. Variable (algebraic)

### CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 Course Web Site http://www.nps.navy.mil/cs/facultypages/squire/cs2900 All course related materials will be posted

### Intro. Scheme Basics. scm> 5 5. scm>

Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

### Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

### Variables and Constants

HOUR 3 Variables and Constants Programs need a way to store the data they use. Variables and constants offer various ways to work with numbers and other values. In this hour you learn: How to declare and

### C++ for Java Programmers

Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

### T H E I N T E R A C T I V E S H E L L

3 T H E I N T E R A C T I V E S H E L L The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform. Ada Lovelace, October 1842 Before

### CPS122 Lecture: From Python to Java

Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

### CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

### Programming Lecture 3

Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

### BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

### Programming Fundamentals and Python

Chapter 2 Programming Fundamentals and Python This chapter provides a non-technical overview of Python and will cover the basic programming knowledge needed for the rest of the chapters in Part 1. It contains

### Program Fundamentals

Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

### Learning the Language - V

Learning the Language - V Fundamentals We now have locations to store things so we need a way to get things into those storage locations To do that, we use assignment statements Deja Moo: The feeling that

### C-1. Overview. CSE 142 Computer Programming I. Review: Computer Organization. Review: Memory. Declaring Variables. Memory example

CSE 142 Computer Programming I Variables Overview Concepts this lecture: Variables Declarations Identifiers and Reserved Words Types Expressions Assignment statement Variable initialization 2000 UW CSE

### 1. Introduction to Microsoft Excel

1. Introduction to Microsoft Excel A spreadsheet is an online version of an accountant's worksheet, which can automatically do most of the calculating for you. You can do budgets, analyze data, or generate

### A Beginner s Guide to Programming Logic, Introductory. Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

A Beginner s Guide to Programming Logic, Introductory Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs Objectives In this chapter, you will learn about: Declaring and

### Programming Language 2 (PL2)

Programming Language 2 (PL2) 337.1.1 - Explain rules for constructing various variable types of language 337.1.2 Identify the use of arithmetical and logical operators 337.1.3 Explain the rules of language

### Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom

### 3 The Building Blocks: Data Types, Literals, and Variables

chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating

### Primitive Data, Variables, and Expressions; Simple Conditional Execution

Unit 2, Part 1 Primitive Data, Variables, and Expressions; Simple Conditional Execution Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Overview of the Programming Process Analysis/Specification

### QUIZ. What is wrong with this code that uses default arguments?

QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

### Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence

### 2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Remembering numbers (and other stuff)... Let s talk about one of the most important things in any programming language. It s called a variable. Don t let the name scare you. What it does is really simple.

### Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

### 2. Numbers In, Numbers Out

COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

### Decisions, Decisions. Testing, testing C H A P T E R 7

C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little

### Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different

### Variables and Literals

C++ By 4 EXAMPLE Variables and Literals Garbage in, garbage out! To understand data processing with C++, you must understand how C++ creates, stores, and manipulates data. This chapter teaches you how

### Excel Basics: Working with Spreadsheets

Excel Basics: Working with Spreadsheets E 890 / 1 Unravel the Mysteries of Cells, Rows, Ranges, Formulas and More Spreadsheets are all about numbers: they help us keep track of figures and make calculations.

### Signed umbers. Sign/Magnitude otation

Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,

### VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 L J Howell UX Software 2009 Ver. 1.0 TABLE OF CONTENTS INTRODUCTION...ii What is this book about?... iii How to use this book... iii

### Midterms Save the Dates!

University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Primitive Data Types Arithmetic Operators Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch 4.1-4.2.

### Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

### Expressions and Casting

Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence

### Maciej Sobieraj. Lecture 1

Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They

### Language Fundamentals

Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long

### IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

### Divisibility Rules and Their Explanations

Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although

### CSE / ENGR 142 Programming I

CSE / ENGR 142 Programming I Variables, Values, and Types Chapter 2 Overview Chapter 2: Read Sections 2.1-2.6, 2.8. Long chapter, short snippets on many topics Later chapters fill in detail Specifically:

### Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Chapter 03: Computer Arithmetic Lesson 09: Arithmetic using floating point numbers Objective To understand arithmetic operations in case of floating point numbers 2 Multiplication of Floating Point Numbers

### Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

### CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignments Reading Assignment: Chapter 3: Introduction to Parameters and Objects The Class 10 Exercise

C++ By A EXAMPLE Memory Addressing, Binary, and Hexadecimal Review You do not have to understand the concepts in this appendix to become well-versed in C++. You can master C++, however, only if you spend

### The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

### L-System Fractal Generator: Language Reference Manual

L-System Fractal Generator: Language Reference Manual Michael Eng, Jervis Muindi, Timothy Sun Contents 1 Program Definition 3 2 Lexical Conventions 3 2.1 Comments...............................................

### Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

### IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and

### Lecture 3. Input, Output and Data Types

Lecture 3 Input, Output and Data Types Goals for today Variable Types Integers, Floating-Point, Strings, Booleans Conversion between types Operations on types Input/Output Some ways of getting input, and

### Bits, Words, and Integers

Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

### Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Intro to Programming & C++ Unit 1 Sections 1.1-4 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2019 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program a set

### Long (LONGMATH) variables may be used the same as short variables. The syntax is the same. A few limitations apply (see below).

Working with Long Numbers. Long Variables Constants You define a long variable with the LONG statement, which works similar to the DIM statement. You can define long variables and dimension long variable

### Part II Composition of Functions

Part II Composition of Functions The big idea in this part of the book is deceptively simple. It s that we can take the value returned by one function and use it as an argument to another function. By

### POWERONE TEMPLATES A DOCUMENT DESCRIBING HOW TO CREATE TEMPLATES.

I N F I N I T Y S O F T W O R K S POWERONE TEMPLATES A DOCUMENT DESCRIBING HOW TO CREATE TEMPLATES www.infinitysw.com/help/create Templates What is a template? powerone uses templates as its primary medium

### Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

Coding Workshop Learning to Program with an Arduino Lecture Notes Table of Contents Programming ntroduction Values Assignment Arithmetic Control Tests f Blocks For Blocks Functions Arduino Main Functions

### Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

### The C++ Language. Arizona State University 1

The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

### Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your