Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to Programming

Similar presentations


Presentation on theme: "An Introduction to Programming"— Presentation transcript:

1 An Introduction to Programming

2 1.4 Character and String Data
Character data (alphanumerics) All the characters you can type at the keyboard A character string (i.e., a string) is a sequence of characters. The data type is String or Character

3 The Declare Statement Variables should be declared to identify their data type. In this text, a statement such as the following will set aside a space in the computer’s memory to store a variable of a given data type: Declare VariableName As DataType

4 Declaring String and Character Variables
The following statement declares a variable named Response to be of Character data type: Declare Response As Character A Character variable can contain only a single character The following statement declares a variable named UserName to be of String data type: Declare UserName As String A String variable can contain as many characters as desired but the whole string of characters must be enclosed within the quotes. Note that spaces, punctuation, and special symbols such as the *, and so forth are all considered characters.

5 Concatenation Concatenation takes two strings and joins them to create a string result The concatenation operator is symbolized, in pseudocode, with a + sign Example: if: String1 = “yellow” and String2 = “duckie” then the statement: Set MyFriend = String1 + String2 results in: MyFriend = “yellowduckie”

6 1.5 Integer Data Examples:
Integers are all the positive, negative, or zero whole numbers Examples: 8 is an integer 8.3 is not an integer -24,567,890 is an integer 0 is an integer 4.0 is not an integer because it has a decimal part

7 Declaring Integer Variables
Each language has a specific way to declare the data type of its variables In this text we use: Declare VariableName As Integer

8 Initializing Integer Variables
Each language has a specific way to initialize (set an initial value) of its variables In this text we use: Set VariableName = value If you try to set a variable to a value that is not of the same type as the variable’s declared data type, you will get an error message.

9 1.6 Floating Point Data All floating point numbers have both an integer part and a fractional part Examples: 5.65 9.00 -456, Repeating numbers like … Irrational numbers like pi or sqrt(2)

10 The Declare Statement Revisited
In this text we will declare variables with the following data types: To declare a variable named Number1 as a floating point variable use: Declare Number1 As Float To declare a variable named Number2 as an integer variable use: Declare Number2 As Integer To declare a variable named OneLetter as a character variable use: Declare OneLetter As Character To declare a variable named OneWord as a string variable use: Declare OneWord As String

11 Any Questions ?


Download ppt "An Introduction to Programming"

Similar presentations


Ads by Google