15
1 homework • Due today: hw #1 (mailing list printout) • readings to date: chapter 1 and chapter 3.1-3.10 • read appendix B (3 pages on DOS) and 2.1-2.8 and 2.10 of the supplement for Thursday • The hw due next Tuesday will be assigned during lab

1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

Embed Size (px)

Citation preview

Page 1: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

1

homework

• Due today: hw #1 (mailing list printout)

• readings to date: chapter 1 and chapter 3.1-3.10

• read appendix B (3 pages on DOS) and 2.1-2.8 and 2.10 of the supplement for Thursday

• The hw due next Tuesday will be assigned during lab

Page 2: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

2

Next class will be held in the lab

• 14 Washington Place• Print and bring: (both are available on the

main course homepage)– “Supplement for Turbo Pascal 7.0”– “Printing the Output screen at 14 Wash Pl.”

• Do not forget to bring two 3.5” floppy disks to the lab.

Page 3: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

3

What is a variable?

Programs manipulate data such as numbers and letters. In order to store the data produced by subcomputations and in order to have a way to name the data, Pascal and many other programming languages use objects called variables

Page 4: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

4

Variables (con’t)

Remember the variables we used in high school algebra.

2x + 3 = 9 (x would be evaluated to x=3)

Pascal variables are similar to the algebra variables in the fact that they hold values.

Page 5: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

5

Variable identifier vs. value

• A variable identifier is the name of a particular variable.

• A variable’s value is the value that the variable “holds”

• Actually, the variable identifier refers to a point in the computers memory which holds the variable’s value.

Page 6: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

6

Variables (con’t)

• Variables can hold different “types” of data.

• Pascal is called a “strongly typed” language because once a variable is “declared”, it can only hold one type of data.– For example a Pascal variable can hold an

integer OR a real number OR a character but you cannot re-use the variable to hold a different type later in your program.

Page 7: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

7

Declaring variables in Pascal

PROGRAM variable1;

VAR number: integer;

The reserved word VAR lets the compiler know youare about to declare a variable list (in this case a listof size 1)

After VAR you list the variable identifiers you will be using in the program

Finally you tell the compiler what type the variables in each list will be.

Page 8: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

8

Assigning values to variables

PROGRAM Variable1;

VAR number: integer;

BEGIN

number := 17;

Variable identifier

Value to be assigned to the location which the identifier number points to in memory

The assignment operator

Page 9: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

9

Pascal identifier rules• An identifier name must begin with any

letter or an underscore. The remaining characters can be letters, underscores or numerical digits.

• Turbo Pascal recognizes the first 63 characters of the identifier name.

• The Turbo Pascal compiler does not distinguish between uppercase and lowercase letters (ie it is not case sensitive)

Page 10: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

10

Garbage values• All variables must be given an initial value

before used on the right hand side of an expression or in output. This is called initializing the variable.

• Prior to initialization, it is unpredictable what value is stored in that variable. (It is true that Turbo Pascal will initialize values for you in certain cases but you cannot rely on that fact for this class)

Page 11: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

11

Pascal Data Types

• For now, we will study:– integers– reals– character– strings– boolean

Page 12: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

12

integer values

• A variable of type integer holds integer values (think positive and negative whole numbers). For example 1, 2, 10000, -50, 0.

• Integers values cannot contain decimals, commas or any non-numerical characters.

• The values must lie between -32768 and 32767. (note: There are several other integer types we will look at shortly.)

Page 13: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

13

character values

• A character value is any single character. You must put the character between single quotes in a Pascal program. For example: ‘A’, ‘a’, ‘1’, ‘*’, ‘ ‘, etc.

• There is a difference between uppercase and lowercase with character values.

Page 14: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

14

string constants

• A string constant contains one or many characters. When it is written in the program, it must appear in single quotation marks. For example ‘Evan’, ‘v22.0002.003’, etc.

• A string variable’s size is defined by the programmer. The default is the maximum size which is 255.

Page 15: 1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter 3.1- 3.10 read appendix B (3 pages on DOS) and 2.1- 2.8 and

15

Boolean values

• There are only two Boolean values in Pascal: TRUE and FALSE. There is no difference between true and TRUE. (ie. Boolean values are not case sensitive.)