Introduction to Computing Dr. Nadeem A Khan. Lecture 4.

Slides:



Advertisements
Similar presentations
1.4 Programming Tools Flowcharts Pseudocode Hierarchy Chart
Advertisements

PSEUDOCODE & FLOW CHART
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2 - Problem Solving
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Chapter 2 - Problem Solving
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2- Visual Basic Schneider
Introduction to Computing Dr. Nadeem A Khan. Lecture 10.
Built-In Functions.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to VB prepared by Dr. I A Moneim Reference Book Schneider.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
The Program Development Cycle and Program Design Tools
Introduction to Computing Dr. Nadeem A Khan. Lecture 14.
Introduction to Computing Dr. Nadeem A Khan. Lecture 6.
Data types and variables
Introduction to Computing Dr. Nadeem A Khan. Lecture 13.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Developing logic (Examples on algorithm and flowchart)
Introduction to Computing Dr. Nadeem A Khan. Lecture 5.
1 Chapter 1 - An Introduction to Computers and Problem Solving 1.1 An Introduction to Computers 1.2 Windows, Folders, and Files 1.3 Program Development.
Objectives You should be able to describe: Data Types
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1A) UTPA – Fall 2011.
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Chapter 1 - VB 2008 by Schneider1 Chapter 1 - An Introduction to Computers and Problem Solving 1.1 An Introduction to Computers 1.2 Windows, Folders, and.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 4: Control Structures I (Selection)
Chapter 2 - VB.NET by Schneider1 Chapter 2 - Problem Solving Program Development Cycle Programming Tools.
Input, Output, and Processing
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Flowcharts. Problem Solving Computer programs are written to solve problems or perform tasks Programmers translate the solutions or tasks into a language.
Visual Basic Programming
Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source.
ICT Introduction to Programming Chapter 4 – Control Structures I.
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Introduction to Computing Dr. Nadeem A Khan. Lecture 2.
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)
CECS 5020 Computers in Education Visual Basic Variables and Constants.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.
Controlling Program Flow with Decision Structures.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Expressing Algorithms as Flowcharts and Pseudocode
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
UNIMAP Sem2-07/08EKT120: Computer Programming1 Week 2 – Introduction to Programming.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
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.
Introduction to Computing
The Selection Structure
Structured Program
Numbers.
Chapter 2- Visual Basic Schneider
Faculty of Computer Science & Information System
Chapter 2- Visual Basic Schneider
Presentation transcript:

Introduction to Computing Dr. Nadeem A Khan

Lecture 4

On the web site Assignment 2 has been posted.

Chapter 3

Program Planning 1. Analyze 2. Design 3. Choose the Interface 4. Code 5. Test and Debug 6. Complete the Documentation

The Problem-Solving Process Input Processing Output

Program Design Tools ► Pseudo-code ► Flow Charts ► Hierarchy Charts

Postage stamp problem: How many stamps to put on a envelop given one stamp is needed for every five sheets of paper or a fraction thereof How many stamps to put on a envelop given one stamp is needed for every five sheets of paper or a fraction thereof

Pseudocode ► Abbreviated version of actual computer code in English-like statements

Pseudo code: Postage Stamp Problem ► Program – Determine the number of stamps for a letter Read Sheets Set the number of stamps to sheets / 5 Round the number of stamps Display the number of stamps

Flowcharts ► Special geometric symbols connected by arrows

Postage stamp problem Start Read sheets Set stamps = sheets/ 5 Display stamps Round stamps up to next whole number End input processing output processing

Elements of Flowcharts Symbol Name Flowline Terminal Input/Output Processing Decision

Continued… Symbol Name Connector Off page Connector Predefined process Annotation

Hierarchy chart ► Shows overall program structure

Hierarchy Charts: Postage Stamp Problem Postage Stamp Problem Read Sheets Calculate stamps Display stamps Set stamps = sheets/5 Round stamps to next whole number

Another problem: Given a street number of one-way street in New York, decide the direction of the street, either eastbound or westbound Given a street number of one-way street in New York, decide the direction of the street, either eastbound or westboundNote: Even numbered street: Eastbound Odd numbered street: Westbound

Decisions ► Sequence Structure – a sequence followed without skipping any line. ► Decision Structure – a structure which requires a decision for any lines of code to be executed.

Decision Structure: Pseudocode IF condition is TRUE THEN Process step(s) 1 ELSE Process step(s) 2 Process step(s) 2 END IF

Decision Structure: Flowchart Process Step (s) 2 Is Condition True Process Step (s) 1

Decision Structure: Pseudocode What in case of multiple conditions?

Decision Structure: Pseudocode IF condition 1 is TRUE THEN Process step(s) 1 ELSE IF condition 2 is TRUE THEN Process step(s) 2 Process step(s) 2ELSE Process step(s) 3 END IF

Pseudo-Code: Street Direction Problem Get Street IF Street is EVEN Display Eastbound ELSE Display Westbound END IF

Flow Chart: Street Direction Problem End Start Get Street Is street even? Display Westbound Display Eastbound

Hierarchy Chart: Street Direction Problem Street Direction Program Get Street Number Decide whether street number is odd or even Display direction

Still Another Problem ► Calculate and report the grade-point average of a class.

The Loop Structure ► A programming structure that executes instructions many times.

Flow chart: loop structure No Process Step(s) Is condition true ? Yes

Pseudo code: loop structure ► DO WHILE condition is TRUE Process Step(s) LOOP

Draw the Flowchart for the class average problem

Pseudo code: Class Average Problem INITIALIZE Counter and Sum to 0 DO WHILE there are more data Get the next Grade Add the Grade to the Sum Increment the Counter LOOP Compute Average = Sum/Counter Display Average

Hierarchy Chart: Class Average Problem Class average program Get grade Compute sum Display average Calculate average

Chapter 4

► Already known:  String  Single  Integer Data Types

► Strings Storage: 10 bytes + string length Range: 0 to app. 2 billions chars. Declaration: Dim strVarLen As String (declares a string of a variable length) (declares a string of a variable length) Data Types (Contd.)

► Fixed-Length Strings Storage: Length of string Range: 1 to app. 65, 400 chars. Declaration: Dim strFixLen As String * 2 (declares a string of a fix size of 2 chars.) Data Types (Contd.)

► Fixed-Length Strings Usage:Example Dim strText As String * 5 Let strText = “Hello” Picture1.Print strText Let strText = “H” Picture1.Print strText Let strText = “HelloWorld” Picture1.Print strText Data Types

► Fixed-Length Strings Usage:Result: Hello(Complete string) H…. (H followed 4 spaces) Hello(First 5 characters only) => The length is fix Data Types

► Integers Storage: 2 bytes Range: -32,768 to 32,767 Declaration: Dim intExample As Integer (declares intExample as an Integer variable) (declares intExample as an Integer variable) Data Types (Contd.)

► Integers Usage:Example Dim count As Integer Let count= 6 Picture1.Print count Let count= count+1 Picture1.Print count Let count= 6/5 Picture1.Print count Let count= * 2 Picture1.Print count Data Types

► Integer Usage:Result67 1 (rounding to lower value) 5(rounding to higher value) => takes only whole number values => takes only whole number values Data Types

► Long (Integer) Storage: 4 bytes Range: -2,147,483,648 to 2,147,483,647 Declaration: Dim lngExample As Long (declares lntExample as a long variable) (declares lntExample as a long variable) Data Types (Contd.)

► Long (Integer) Usage: Same as Integer Type except the range is much larger much larger Data Types (Contd.)

► Byte Storage: 1 byte Range: 0 to 255 Declaration: Dim bytExample As Byte (declares bytExample as a Byte type variable) (declares bytExample as a Byte type variable) Data Types (Contd.)

► Byte Usage: Same as Integer Type except the range is positive and much smaller positive and much smaller Data Types (Contd.)

► Boolean Storage: 2 bytes Range: TRUE(1) or FALSE(0) Declaration: Dim blnState As Boolean (declares a Boolean type variable blnState) Data Types (Contd.)

► Boolean Usage:Example Dim blnExample As Boolean Let blnExample= FALSE Picture1.Print blnExample Let blnExample= 1 Picture1.Print blnExample Let blnExample= 6 Picture1.Print blnExample Let blnExample= -8*7+5.2 Let blnExample= -8*7+5.2 Picture1.Print blnExample Data Types (Contd.)

► Boolean Usage:Example FALSE FALSE TRUE TRUE =>Values other than 0 are TRUE =>Values other than 0 are TRUE Data Types (Contd.)

► Single (Precision Floating-Point) Storage: 4 bytes Range: -3.4…E38 to -1.4…E-45 (negative) 1.4…E-45 to 3.4…E38 (positive) Declaration: Dim sngAverage As Single (declares a Single type variable sngAverage) Data Types (Contd.)

► Double (Precision Floating-Point) Storage: 8 bytes Range: -1.7…E308 to -4.9…E-324 (negative) 4.9…E-324 to 1.7…E308 (positive) 4.9…E-324 to 1.7…E308 (positive)Declaration: Dim dblAverage As Double (declares a Double type variable dblAverage) Data Types (Contd.)

► Double Usage:Example Dim sngValue As Single, dblValue As Double Let sngValue= 1/3 Picture1.Print sngValue Let dblValue= 1/3 Picture1.Print dblValue Data Types (Contd.)

► Double Usage:Result (Single precision) (Double precision) => Value of 1/3 represented more accurately by double than by single by double than by single Data Types (Contd.)

► Double Usage:Example Dim sngValue As Single, dblValue As Double Let sngValue= 1/3 Let sngValue= sngValue * Picture1.Print sngValue Let dblValue= 1/3 Let dblValue= dblValue * Picture1.Print dblValue Data Types (Contd.)

► Double Usage:Result (Single precision; rounding error) (Double precision) => - The decimal point is floating; - Eventually both will be subjected to rounding errors value increases to large values value increases to large values - Still Double will remain more precise than Single Data Types (Contd.)

► Currency Storage: 8 bytes Range: -922,337,203,685, to 922,337,203,685, ,337,203,685, Declaration: Dim curRevenue As Currency (declares a Currency type variable curRevenue) Data Types (Contd.)

► Currency Usage:Example Dim curValue As Currency Let curValue= 1/3 Picture1.Print curValue Let curValue= 100*1/3 Picture1.Print curValue Data Types (Contd.)

► Currency Usage:Result =>- The decimal point is NOT floating; - Could be used for currency and scientific research - No rounding problems for high values Data Types (Contd.)

► Even more data types  Date Variable: for date and time  Object Variable  Variant Variable  ………. Read the book for more info. Data Types (Contd.)

Local vs Form Variables

Not only +,-,*,^ But also: But also: \ opeartor e.g: 5.1\2.04= 2 \ opeartor e.g: 5.1\2.04= 2 MOD operator e.g: 15.2 MOD 6=3 MOD operator e.g: 15.2 MOD 6=3 => First round to closest integers before operation More on Operators

More on Operators (Contd.) ► Operator Precedence 1. ^ 2.- operator (indicating a negative value) 3. * and / operator 4. \ operator 5. MOD operator 6. + and - operator

Built-in Functions ► Take one or more input values ► Return an output value ► Already seen:  Val(..), Str$(..), Asc(..), Chr(..)

Built-in Numeric Functions ► Sqr: calculates square-root and returns the value as double data type e.g: e.g:  Sqr(9) is 3  Sqr(0) is 0  Sqr(2) is  Sqr(30*2+4) is 8

Built-in Numeric Functions ► Int: Greatest integer less than and equal to a number e.g: e.g:  Int(2.7) is 2  Int(3) is 3  Int(-2.7) is -3

Built-in String Functions ► Left$, Mid$, Right$, UCase$, Trim$ Left$(“fanatic”, 3) is “fan”Right$(“fanatic”, 3) is “tic” Left$(“12/15/93”,2) is “12”Right$(“12/15/93”, 2) is “93” Mid$(“fanatic”, 5,1) is “t”Mid$(“12/15/93”,4, 2) is “15” Ucase(“Disk”) is “DISK”Ucase(“12two”) is “12TWO” Trim$(“ 1 2 ”) is “1 2”Trim$(“-12 ”) is “-12”

Built-in Functions (Contd.) ► Len Len(“Shenandoah”) is ? Len(“Just a moment”) is ? Len(“m”) is ?

Built-in Functions (Contd.) ► Len Len(“Shenandoah”) is 10 Len(“Just a moment”) is 13 Len(“m”) is 1

Built-in Functions (Contd.) ► Instr Instr(“Shenandoah”, “nand”) is ? Instr(“Just a moment”, “ ”) is ? Instr(“Croissant”, “ist”) is ?

Built-in Functions (Contd.) ► Instr Instr(“Shenandoah”, “nand”) is 4 Instr(“Just a moment”, “ ”) is 5 Instr(“Croissant”, “ist”) is 0

Built-in Functions (Contd.) Abs(10) is 10 Abs(-10) is 10 Sgn(10) is 1 Sgn(0) is 0 Sgn(-10) is -1