Variables, Constants, Methods, and Calculations Chapter 3 - Review.

Slides:



Advertisements
Similar presentations
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 2: Designing Applications
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
1.
VBA Modules, Functions, Variables, and Constants
Chapter 2: Input, Processing, and Output
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Basic Elements of C++ Chapter 2.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
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.
Variables and Constants
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
CIS Computer Programming Logic
Chapter 4: The Selection Structure
Programming.
Chapter 3 Part 11 Variables, Constants, and Calculations Chapter 3 Section 3.3 Chapter 3 Section 3.4.
Input, Output, and Processing
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Chapter 2: Using Data.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Visual Basic Programming
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.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 7 Where Can I Store This?
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
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.
Controlling Program Flow with Decision Structures.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
A variable is a name for a value stored in memory.
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
Arithmetic Expressions Function Calls Output
Chapter 2: Input, Processing, and Output
Basic Elements of C++.
Chapter 3: Using Variables and Constants
The Selection Structure
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.
Basic Elements of C++ Chapter 2.
Variables and Arithmetic Operations
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
An Introduction to Programming with C++ Fifth Edition
Chapter 2: Input, Processing, and Output
Presentation transcript:

Variables, Constants, Methods, and Calculations Chapter 3 - Review

Variables Creating a space in memory to hold data to be utilized while the application is running. Every variable has a: Name Data type Scope Lifetime

Selecting a Data Type for a Variable Each variable must be assigned a data type Data type: the type of data the variable can store Each data type is a class

Selecting a Name for a Variable Identifier: descriptive name given to a variable Use a meaningful name that reflects the purpose of the variable Use Hungarian Notation (intNumber, strName) Variable names must conform to naming rules (no spaces, no reserved words, start with characters, no punctuation except the underscore _)

Declaring a Variable Declaration statement: used to declare, or create, a variable Declaration statement includes Scope keyword: Dim or Private or Static Name of the variable Data type Initial value (optional)

Assigning Data to an Existing Variable Assignment statement: Used to assign values to properties of controls Used to assign values to variables Assignment operator: (=) Value on the right of the = operator is assigned to the variable on the left of the = operator

Option Explicit ON Option Explicit ON = must declare (create) the variable before using Protects against misspelled variable names in code Placed in the General Declarations section of code editor

Option Explicit ON

Data Typing Implicit type conversion: can occur if the value on the right side of an assignment statement is not the same data type as the variable on the left side Example: converted to Integer = converted to Integer = 25

Data Typing Promoting: when a value is converted to another data type that stores larger numbers Demoting: when a value is converted to another data type that stores only smaller numbers Data loss can occur with demoting

Option Strict ON Option Strict ON = prevents possible loss of data by not allowing any implicit type conversions Can be used to enforce correct data typing Placed in the General Declarations section of the code editor

General Declaration

Program Design TOE Charts Pseudocode Flowcharts All are visual tools to help design the logical flow of the program.

TOE Charts Task Object Event

TOE Charts TOE Charts help the programmer to think through what the application will do and what it will need to run properly. 1. Input 2. Calculate 3. Print out to screen or paper 4. Clear used data from controls 5. Exit program

TOE Chart – Task 1 – Input 2 – Calculate 3 – Print to screen or paper 4 – Exit program 5 – Clear form

TOE Charts TOE Charts provide a visual tool to identify the tasks of the application, the objects used in the user interface and the events (clicking, double-clicking) that trigger the code. TOE Charts identifies the tasks, objects and events of the FORM.

Perry Primary School MainForm TaskObjectEvent 1.Calculate the sum of and the difference between the two numbers 2.Display the sum and difference in the sumLabel and differenceLabel controls computeButtonClick End the applicationexitButtonClick Display the sum and difference (from computeButton) sumLabel, differenceLabel None Get and display two numbersfirstTextBox, secondTextBox None Display the DialogFormoptionsButtonClick Display the SplashScreenFormMainFormLoad DialogForm TaskObjectEvent Change the color of the MainForm ’ s text to red redButtonClick Change the color of the MainForm ’ s text to black blackButtonClick SplashScreenForm TaskObjectEvent Close the SplashScreenFormsplashTimerTick

Pseudocode Pseudocode identifies the steps of a procedure and writes it in short phases. Each procedure will have it’s own pseudocode.

Skate-Away Pseudocode

Flowcharts Flowcharts identifies the steps of a procedure and diagrams it using special symbols.

Flowcharts Oval – start / stop symbol Rectangles – process symbols represents tasks such as making calculations Parallelogram – input / output symbol represent input tasks – getting information from user represent output tasks – displaying information Lines – flowlines symbol represents logical flow connects the symbols

Flowcharts Flowcharts identifies the steps of a procedure and diagrams it using special symbols. Each procedure will have it’s own flowchart.

General Design Guide 1. Input 2. Calculate 3. Output (print to screen and/or paper) 4. Clear old data 5. End program

Code Flow Step – by – step

General Design Guide 1. Input 2. Calculate 3. Output (print to screen and/or paper) 4. Clear old data 5. End program

General Design Guide 1. Input  Validate 2. Calculate 3. Output (print to screen and/or paper) 4. Clear old data 5. End program

General Design Guide 1. Input  Validate  Convert 2. Calculate 3. Output (print to screen and/or paper) 4. Clear old data 5. End program

Using the TryParse Method Method: a specific portion of a class’s instructions that performs a task for the class TryParse method: Part of every numeric data type’s class Used to convert a string to that numeric data type

Using the TryParse Method TryParse method has 4 arguments String: string value to be converted Variable: location to store the result IFormatProvider (optional): specifies formatting NumberStyles (optional): allows formatting characters to be in the data to be converted

Using the TryParse Method Method: a specific portion of a class’s instructions that performs a task for the class TryParse method: Part of every numeric data type’s class Used to convert a string to that numeric data type

Using the TryParse Method TryParse method has 4 arguments String: string value to be converted Variable: location to store the result IFormatProvider (optional): specifies formatting NumberStyles (optional): allows formatting characters to be in the data to be converted

General Design Guide 1. Input  Validate  Convert 2. Calculate 3. Output (print to screen and/or paper) 4. Clear old data 5. End program

General Design Guide 1. Input 2. Calculate 3. Output (print to screen and/or paper) 4. Clear old data 5. End program

General Design Guide Calculate  RULE 1: There is an order in which the computer performs the operation in an expression  RULE 2: All variables must be of the same data type to be able to do mathematical calculations

Arithmetic Operators – Precedence Order

General Design Guide Calculate  RULE 1: There is an order in which the computer performs the operation in an expression  RULE 2: All variables must be of the same data type to be able to do mathematical calculations

General Design Guide Calculate  RULE 1: There is an order in which the computer performs the operation in an expression  RULE 2: All variables must be of the same data type to be able to do mathematical calculations  When possible, have the TryParse Method convert the user input (String Data Type) to the numeric data type needed for the calculation.

General Design Guide 1. Input 2. Calculate 3. Output (print to screen and/or paper) 4. Clear old data 5. End program

General Design Guide 1. Input 2. Calculate 3. Output (print to screen and/or paper) 4. Clear old data 5. End program

General Design Guide 1. Input 2. Calculate 3. Output (print to screen and/or paper)  Convert data type to STRING  Format output 4. Clear old data 5. End program

General Design Guide Output / Display  RULE: Output to be displayed on the screen must be of the data type STRING.

General Design Guide Output / Display  RULE: Output to be displayed on the screen must be of the data type STRING.  RULE: Values (data) assigned to the Text Property must be of the data type STRING.

General Design Guide Output / Display  RULE: Output to be displayed on the screen must be of the data type STRING.  RULE: Values (data) assigned to the Text Property must be of the data type STRING.  Provide proper formatting of the output as required.

Formatting Numeric Output Formatting: specifying the number of decimal places and any special characters to display Format specifier: specifies the type of formatting to use (“C”) (“N”) (“D”) (“P”) Precision specifier: controls the number of significant digits or zeros to the right of the decimal point (“C2”)(“N1”)

Format Specifier

Format Specifier and Precision Specifier

Formatting Numeric Output (continued)