Presentation is loading. Please wait.

Presentation is loading. Please wait.

So now we’re programming What do programs do? Manipulate (process) data Math Read files Write to files Create files.

Similar presentations


Presentation on theme: "So now we’re programming What do programs do? Manipulate (process) data Math Read files Write to files Create files."— Presentation transcript:

1

2 So now we’re programming

3 What do programs do? Manipulate (process) data Math Read files Write to files Create files

4 Good programmers Always Always start with pseudocode See page100

5 Programs must be named You choose the name It must be one word follow with a semi-colon Example: Program First_Program ;

6 Next, type program comments Program First_Program; (***********************************) (* Program: First.pas *) (* Programmer: Sue Halfhill *) (* Date: September, 1999 *) (* Description: Program is a point of sale *) (* system *) (***********************************)

7 Next, declare any constants Constants do not change value Program First_Program; (***********************************) (* Program: First.pas *) (* Programmer: Sue Halfhill *) (* Date: September, 1999 *) (* Description: Program is a point of sale *) (* system *) (***********************************) CONST Multiplier = 5;

8 Next, declare any variables Program First_Program; (***********************************) (* Program: First.pas *) (* Programmer: Sue Halfhill *) (* Date: September, 1999 *) (* Description: Program is a point of sale *) (* system *) (***********************************) VAR Fname : String[15]; Lname : String[25]; Sum, X, Y : Integer;

9 String Variables Contain alpha-numeric data Are 256 bytes in size unless declared –Use [ ] to declare smaller size

10 Char One byte only in size Byte Either True or False

11 Integers vs Real Whole numbers Legal values of - 32,768 to 32,767 Use LongInt for larger numbers +, -, *, div, MOD Must have decimals Can be used for exponents Maximum value determined by computer memory +, -, *, /

12 Integer vs Real Real Integer

13 Implications Integers variables can be assigned to Real Variables Real variables can not be assigned to Integer variables

14 Next Code must start with Begin and finish with End. Program First_Program; (***********************************) (* Program: First.pas *) (* Programmer: Sue Halfhill *) (* Date: September, 1999 *) (* Description: Program is a point of sale *) (* system *) (***********************************) VAR Fname : String[15]; Lname : String[25]; Sum, X, Y : Integer; Begin ====== End.

15 Putting values into variables Sum := 2 + 4; FName := ‘John’; Variable Name Assignment Operator Literal or Value being stored

16 Assigning Values Program First_Time; CONST Multiplier = 5; VAR Fname : String[15]; Lname : String[25]; Sum, Sum, X, Y : Integer; Begin X := 2; Y := 6; Sum := Multiplier(X + Y); Writeln(Sum); End;

17 How ‘Hard Code’ User Input Read from a file OH- OH

18 Read Procedure Read(parameter,parameter) Readln(parameter,pararmeter) Reading numeric data vs string data

19 Read(parameter,parameter) 7 5 Read(A,B) Space is a delimiter (separator) for integer or real data 7 5 With the read procedure the marker does not go to the next line

20 Readln(parameter,parameter) 7 5 Readln(A, B) 7 5 8 40 With the readln procedure the marker goes to the next line

21 String Variables vs Read/Readln The size of A and B determine how much is read Dataline : string[9] reads up to 9 characters (letters, spaces, numbers, etc)

22 Write/Writeln Cursor similar to Read/Readln; Directs data to –screen Writeln(‘What is your name’); –to file Writeln(filename, Sum); –to printer Writeln(lst, ‘What is your name?’);

23 What’s A Function Black Box Command Result X := Length(Data_line) ;

24 String Functions

25 Begin Writeln(‘Please enter your social security number.’) Read(SSNumber); Writeln(‘Please enter your first name and last name.’) Readln(Data_line); X := Length(Data_line); Y := POS(Blank,Data_line); First_Name := COPY(Data_Line,1,y-1); Delete(Data_Line,1,y); X := Length(Data_Line); Last_Name := Data_line; End.

26 X := Length(Data_line) ; Y := POS(Blank, Data_line) ; First_Name := COPY(Data_line, 1, 5) ; Delete(Data_line, 1, y) ;

27 X := Length(Data_line); Anatomy of a Function Function Name Parameters Variable which holds value

28 X := Length(Data_line) ; Sue Halfhill Data_Line X = 12

29 Y := POS(Blank, Data_line) ; Sue Halfhill Blank Y = 4 2 parameters !!!!

30 First_Name := COPY(Data_line, 1, 3) ; First_Name Sue Halfhill Data_line } 3 1 Sue 3 parameters !!!!

31 Delete Delete(Data_line,1,y)

32 Math Functions Round Trunc Sqr Sqrt Str

33 STR(X,S) X is an integer or real value X must be formatted. X:4:2 S is a string variable.


Download ppt "So now we’re programming What do programs do? Manipulate (process) data Math Read files Write to files Create files."

Similar presentations


Ads by Google