Operators Same as standard math operators with 2 exceptions –* for multiplication –^ for exponentiation Order of operations strictly observed –Please Excuse.

Slides:



Advertisements
Similar presentations
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Advertisements

Introduction to C Programming
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Chapter 4 - VB.Net by Schneider1 Chapter 4 General Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular.
Introduction to C Programming
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
VB .NET Programming Fundamentals
Basic Elements of C++ Chapter 2.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
CS0004: Introduction to Programming Input and Output.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET VB.NET Controls VB.NET Events Numbers Strings Input and Output.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Chapter 12: How Long Can This Go On?
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Input, Output, and Processing
1 Chapter 5 - General Procedures 5.1 Function Procedures 5.2 Sub Procedures, Part I 5.3 Sub Procedures, Part II 5.4 Modular Design.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Numbers continued The Integer Data Type Multiple Declarations Parentheses Three Types of Errors.
Applications Development
6.2 For…Next Loops General Form of a For…Next Loop
JavaScript, Fourth Edition
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Controlling Program Flow with Decision Structures.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
3.4 Strings Variables and Strings Using Text Boxes for Input and Output Concatenation ANSI Character Set String Properties and Methods: LengthToUpper TrimToLower.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Subroutines and Functions Chapter 6. Introduction So far, all of the code you have written has been inside a single procedure. –Fine for small programs,
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Visual Basic 6 (VB6) Data Types, And Operators
Basic Elements of C++.
Multiple variables can be created in one declaration
The Selection Structure
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Basic Elements of C++ Chapter 2.
Numbers.
String Variable, Methods and Properties
CIS16 Application Development Programming with Visual Basic
String Variable, Methods and Properties
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Topics Designing a Program Input, Processing, and Output
String Variable, Methods and Properties
Topics Designing a Program Input, Processing, and Output
String Variable, Methods and Properties
Unit 3: Variables in Java
Presentation transcript:

Operators Same as standard math operators with 2 exceptions –* for multiplication –^ for exponentiation Order of operations strictly observed –Please Excuse My Dear Aunt Sally –And Mod operator returns the remainder –Example x = a mod b gives the remainder when a is divided by b A series of numeric values and operators is know as an “expression” = ( ) / 4 4

Variables Data containers (bags or shoeboxes) Variable names –Up to 16,383 characters long, –Begin with a letter or an underscore, and –Consist of letters, digits, and underscores only. Declared (created) with Dim statement –Dim varname as type

2 numeric variable types Integer: contains +/- whole numbers –Approx range = -2 billion to 2 billion Double: contains +/- floating point (decimal) numbers –Approx range = -1.8*10^308 and 1.8*10^308 –Use scientific notation for large values hence “floating” point

Assignment Statements “=“ used to place data into variable (container) varname = value (dump truck) Value can be –literal: 3.5 for example (know as constant in algebra) –other variable –expression: or x + 2

List Box Easy way to show output Contains “items” displayed one per line Use list box tool to place on form Control contents with –lst.Items.add ( ) method Data placed inside parentheses displayed in box –lst.Items.clear ( ) Removes all items from list –With block Shorthand With..EndWith boundaries With lstResults.Items.add(~~) or.clear( ) EndWith

Characters Character = any written symbol –A..Z, a..z, 0..9, etc. –Spaces, return and tab –Some other special use items

String A sequence of characters String literal = “qwerty” String variables –Dim varName As String Dim today As String today = "Monday"

Concatenation Joining strings & is the concatenation operator –Dim quote1, quote2, quote As String –quote1 = "The ballgame isn't over, " –quote2 = "until it's over." –quote = quote1 & quote2 –txtOutput.Text = quote & " Yogi Berra"

Using string variables If x, y,..., z are characters and strVar is a string variable, then the statement –strVar = "xy...z" assigns the string literal xy...z to the variable and the statement –lstBox.Items.Add("xy...z") or –lstBox.Items.Add(strVar) are equivalent.

Using Text Boxes for Input and Output Input –strVar = txtBox.Text Output –txtBox.Text = strVar

Numeric to string conversion String data can not be used in calculations String data must be converted to numeric –dblVar = CDbl(txtBox.Text) –txtBox.Text = CStr(dblVar)

Formatting Numeric Values FunctionString Value FormatNumber( , 1)12,345.6 FormatCurrency( , 2)$12, FormatPercent(0.185, 2)18.50% Usage lblWinPercent.text = FormatPercent( dblWinPercent, 2 ) txtSalary = FormatCurrency( dblSalary, 2)

Zone Formatting What is it about? 1.Setting up zones – setting up tab stops. 2.Force output into columns 3.Use formatting tags to format numbers How is it done? 1.Create zone string to define zones 2.Make zone string and data parameters to String.Format method 3.Use above as parameter to.Add method of Listbox

Dialog Boxes stringVar = InputBox(prompt, title) Causes a dialog box to pop up Text enter in dialog placed in stringVar

Dialog Box Sample Dim stringVar As String stringVar = InputBox("Please enter a number", "Just A Sample") Just like World.Ask in Alice

Procedures As In Alice but with a different nameAs In Alice but with a different name Break code down in small segmentsBreak code down in small segments Reuse in different parts of programsReuse in different parts of programs

Procedure syntax HeaderHeader –Reserved word “Sub” –Procedure name –Parentheses CodeCode End SubEnd Sub Sub ProcedureName() statement(s) End Sub

Procedure Placement Between Class.. End ClassBetween Class.. End Class But not between any Sub.. End Sub pairBut not between any Sub.. End Sub pair Generally placed below last event procedureGenerally placed below last event procedure Non event procedures should be placed in a groupNon event procedures should be placed in a group

Parameter Passing Locate the callsLocate the calls –Arguments inside parentheses Locate the headerLocate the header –Parameters inside parentheses –ByVal replaces Dim Private Sub btnAdd_Click(...) Handles btnAdd.Click 'Display the sum of two numbers lstResult.Items.Clear() ExplainPurpose()lstResult.Items.Add("") DisplaySum(2, 3) End Sub Sub DisplaySum(ByVal num1 As Double, ByVal num2 As Double) 'Display numbers and their sum lstResult.Items.Add("The sum of " & num1 & " and " & num2 & " is " & num1 + num2 & ".") End Sub

Parameters and other variables Locate parameter definitionLocate parameter definition Locate parameter useLocate parameter use Locate Local Variable definitionLocate Local Variable definition Locate Local Variable useLocate Local Variable use Sub CalculateDensity(ByVal state As String, ByVal pop As Double, ByVal area As Double) Dim rawDensity, density As Double 'The density (people per square mile) 'will be displayed rounded 'to one decimal place rawDensity = pop / area density = Math.Round(rawDensity, 1) 'Round to one decimal place lstDensity.Items.Add("The density of " & state & " is " & density) lstDensity.Items.Add("people per square mile.") End Sub

ByVal or ByRef pages Only applicable when argument is a variableOnly applicable when argument is a variable ByVal gives the called procedure a copy of the argument’s valueByVal gives the called procedure a copy of the argument’s value –Parameter and argument not connected –Changing parameter value doesn’t affect argument value ByRef gives the called procedure the address of the argumentByRef gives the called procedure the address of the argument –Parameter and argument connected –Changing parameter value does affect argument value

Local and Class Variable Scope pages Local – defined inside Sub.. End Sub pairLocal – defined inside Sub.. End Sub pair –Variable “exists” only while execution is between its Sub.. End Sub –Variable undefined outside those boundaries. Class – defined outside any Sub.. End Sub pair but inside Class.. End ClassClass – defined outside any Sub.. End Sub pair but inside Class.. End Class –Variable “exists” everywhere in program –Value may be accessed and modified in any procedure

Character relations American National Standards Institute – code for characters –Characters 0 – 9 => codes 48 – 57 –Capital letters => codes 65 – 90 –Small letters => codes 97 – before A, A before a

Relational Operators Used to create conditions –Equal to= –Not equal to<> –Greater than> –Less than< –Greater than or equal to>= –Less than or equal to<=

Logical operators Used to combine conditions –And…..the combination is true only if both conditions are true –Or…….the combination is true if either or both of the conditions are true – Not……produces the opposite value of the condition

Boolean Variables Can be set to true or false Once set can be used in place of condition Often used as flag

Repetition Group instructions that need to be repeated Create condition that controls number of repetitions

While Condition is true at start Continue until the condition is false Something in loop must happen to make condition false

Terminator While not terminated –“I’ll be back” Used to control input loop –Loop repeatedly asks for input of a certain type, for example, positive numbers or a list of names. –Choose terminator that would NOT occur naturally in the input.

Piggy Bank Piggy bank plus ¢ N=N+? Incrementor: –n=n+1 Accumulator: –n=n+x Above is bad algebra but excellent computer A specific expected value for n could be used as terminator

For.. Next Loops Loop keeps count Count ↑ or ↓ Stops when it finishes counting Could be done with a while loop Initial value – number to count from Terminating value – number to count to Control variable – holds count, can be used in loop

Count to 5 Dim n As Integer For n = 1 To 5 lstTable.Items.Add(n & " " & n ^ 2) Next n is the control variable 1 is initial value 5 is terminating value n is used for output and calculation

Start with any initial value Dim pop As Double = Dim yr As Integer For yr = 2006 To 2010 lstTable.Items.Add(yr & “ “ & pop)) pop += 0.03 * pop Next

Use any step Dim n, s, As Double Dim index As Double n = CDbl(txtEnd.Text) s = CDbl(txtStep.Text) lstValues.Items.Clear() For index = 0 To n Step s lstValues.Items.Add(index) Next

Count down Dim m, j As Integer, temp As String ="" m = info.Length For j = m - 1 To 0 Step -1 temp &= info.Substring(j, 1) Next

Reading Assignments Read section 3.2 Read section 3.3 Read section 3.4 Read section 3.5 Read section 4.1 Read section 5.1 Read section 5-2 Read section 6-1 Read section 6-3