String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.

Slides:



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

Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction to Python
Introduction to C Programming
Basic Input/Output and Variables Ethan Cerami New York
Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
COMPUTER SCIENCE I C++ INTRODUCTION
CS0004: Introduction to Programming Variables – Numbers.
Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
CS0004: Introduction to Programming Variables – Strings.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
CSE 131 Computer Science 1 Module 1: (basics of Java)
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Variables and Expressions CMSC 201 Chang (rev )
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
ICAPRG301A Week 2 Strings and things Charles Babbage Developed the design for the first computer which he called a difference engine, though.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
‘Tirgul’ # 2 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #2.
Chapter 2 Variables.
1 STRINGS String data type Basic operations on strings String functions String procedures.
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
Arrays and others. Annoucement Today’s office hour move to Friday 1:00PM to 3:00PM Today’s office hour move to Friday 1:00PM to 3:00PM Today Today  Call.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
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)
Welcome to AP Computer Science A We use the Java language, but this class is much more rigorous than Intro to Java More programming, but also more theory.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
Strings PART I STRINGS, DATES, AND TIMES. FUNDAMENTALS OF CHARATERS AND STRINGS VB represents characters using American National Standards Institute(ANSI)
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
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.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Objects Allow us to represent and control the computer technology Use methods to make the object do something Use properties to find out and change the.
A variable is a name for a value stored in memory.
Chapter 2 Basic Computation
Chapter 2 - Introduction to C Programming
Variables Data Types and Assignment
Chapter 2 - Introduction to C Programming
VB Math All of your favorite mathematical operators are available in VB: + Addition - Subtraction * Multiplication / Division \ Integer Division Mod Modulo.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Sub Procedures and Functions
Chapter 7: Using Functions, Subs, and Modules
Chapter 2 - Introduction to C Programming
Variables Data Types and Assignment
Chapter 2 - Introduction to C Programming
Variables Data Types and Assignment
Introduction to C Programming
Presentation transcript:

String and General Procedures

Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain to the left of previous remains No Print 1 To the left of Previous remains End Yes Output number If number Equal to 1 or 0 Yes No

Statistics of Exam 1 Max: 98 Max: 98 Average: Average: Median: 75 Median: 75

Strings Strings are variables that hold letters, words, sentences, or even numbers Strings are variables that hold letters, words, sentences, or even numbers String holds a bunch of ASCII codes. String holds a bunch of ASCII codes. You can not do mathematical operations on string. You can not do mathematical operations on string. So you need to use Val(string) function to convert strings to numbers. So you need to use Val(string) function to convert strings to numbers.

String Variables Declaring Strings Declaring Strings Dim Phrase1 As String Assigning value to a string variable Assigning value to a string variable –Phrase1 = “Hello” Phrase1 H e l l o ASCII code

& Adding Two Strings & Phrase1 = TextBox1.Text Phrase2 = TextBox2.Text Sentence = Phrase1 & Phrase2 Adding two strings is called “CONCATENATING”

Adding text to a String Variable Dim TheAnswer as String Dim TheAnswer as String TheAnswer = “a plague upon society!” TheAnswer = “a plague upon society!” Sentence= “Boy Bands are ” & “TheAnswer” Sentence= “Boy Bands are ” & “TheAnswer” Sentence= “Boy Bands are ” & TheAnswer Sentence= “Boy Bands are ” & TheAnswer

Spacing Spacing: Does not insert spaces for you Spacing: Does not insert spaces for you –“This is” & “not right”  This isnot right –“This is ” & “right”  This is right Space itself has an ASCII code, which is 32 (10 base), or (binary) Space itself has an ASCII code, which is 32 (10 base), or (binary)

String Relationships String can be compared. String can be compared. StringA = StringB : comparing if two string is identical. StringA = StringB : comparing if two string is identical. StringA <> StringB : different from StringA <> StringB : different from –“Hello” <> “hello” is true. StringA < StringB : if the string A will appear earlier in a dictionary than B. StringA < StringB : if the string A will appear earlier in a dictionary than B. >, = >, =

String Functions Functions are built in processes that do something to a variable or piece of information Functions are built in processes that do something to a variable or piece of information Functions have ARGUMENTS, or values that you put into them Functions have ARGUMENTS, or values that you put into them ARGUMENTS go inside parentheses ARGUMENTS go inside parentheses Left(“fanatic”, 3) Left(“fanatic”, 3) Left(fanatic, 3) Left(fanatic, 3)

String Functions Len(string) – finds length Len(string) – finds length Left(string, n) takes left most n characters Left(string, n) takes left most n characters Right(string, n) does same from right Right(string, n) does same from right Ucase(string) makes string UPPERCASE Ucase(string) makes string UPPERCASE Trim(string) – takes spaces off ends Trim(string) – takes spaces off ends Mid(string, start, length) – takes a string from middle (great for dividing strings up into pieces) Mid(string, start, length) – takes a string from middle (great for dividing strings up into pieces) InStr(string, substring) searches for substring in string InStr(string, substring) searches for substring in string

Mid String DNA=“ACGTGACACTGAC” DNA=“ACGTGACACTGAC” Base1=Mid(DNA, 1, 1) “A” Base1=Mid(DNA, 1, 1) “A” Base2=Mid(DNA, 2, 4) “CGTG” Base2=Mid(DNA, 2, 4) “CGTG”... Base6=Mid(DNA, 6, 2) “AC” Base6=Mid(DNA, 6, 2) “AC”

InStr() – In String DNA=“ACGTGACACTGAC” DNA=“ACGTGACACTGAC” Location=InStr(DNA, “CACTG”) Location=InStr(DNA, “CACTG”) Returns location of first character of substring

Working with Text Strings Comparison = means “identical to” Comparison = means “identical to” “yes” is not equal to “Yes” “yes” is not equal to “Yes” “yes “ is not equal to “yes” “yes “ is not equal to “yes” Prepare strings for comparison Prepare strings for comparison –answer = Ucase(answer) – makes it all caps –answer = Trim(answer) – takes off spaces Then, compare to all caps! Then, compare to all caps! –if answer = “YES” then

Numeric Functions answer = Sqr(varNum) answer = Int(varNum) – truncates (cuts off decimal stuff) and makes integer Int(3.7)  3 Int(-2.34)  -2 answer= Round(varNum) – rounds number Round(3.7)  4

Procedures String and numeric functions belong to a VB category called “procedure” String and numeric functions belong to a VB category called “procedure” Procedures are pre-defined code fragments. Procedures are pre-defined code fragments. There are three types of procedures. There are three types of procedures. –Event procedure (event handler) –General procedure –Function procedure

Event Procedure Event procedure is also called event handler. Event procedure is also called event handler. It is associated with an event of the object. It is associated with an event of the object. The name of a event procedure is specially structured. The name of a event procedure is specially structured. Private Sub ObjectName_EventName() … End Sub Underscore

General Procedures Defined by key word Sub Defined by key word Sub Private Sub ProcedureName() Block of code End Sub Not linked with any event Not linked with any event Can be called by other part of code. Can be called by other part of code. –Call ProcedureName()

Why using general procedures? Making the code clear and well structured. Making the code clear and well structured. –Rule of coding #1: Don’t write a procedure that is more than 50 lines long. Distinguishing different function blocks. Distinguishing different function blocks. Reusing the repetitive code Reusing the repetitive code

Passing arguments to a procedure Analogy Analogy –Inputs for a computer is as : –Arguments for a procedure. Defination Defination Private Sub ProcedureName(arg1 as type, arg2 as type) Block of code End Sub In the code section that calls it In the code section that calls it Call ProcedureName(arg1, arg2)

A computer without a output device? A sub procedure is like a computer that only has input device. A sub procedure is like a computer that only has input device. Although you can display result on the screen, other output devices are definitely helpful. Although you can display result on the screen, other output devices are definitely helpful. Therefore we need another kind of procedure --- function procedure. Therefore we need another kind of procedure --- function procedure.

Functions procedure Function is a sub procedure with a returned value. Function is a sub procedure with a returned value. Function procedure is used in the same way as a built-in numeric or string function. Function procedure is used in the same way as a built-in numeric or string function. Variable = FunctionName(arguments…) Define a function Define a function Private Function FunctionName(arg1 As type1, arg2 As type2,…) As ReturnType Block of code FunctionName=expression End Function

Homework Read book page Read book page Lots of useful information in the comments section of the book. Lots of useful information in the comments section of the book. Today’s office hours are rescheduled to Wednesday 1:30-3:30 only for this week. Today’s office hours are rescheduled to Wednesday 1:30-3:30 only for this week.