Translating Pseudocode into computer languages Lecture 14 Data

  • Slides: 17
Download presentation
Translating Pseudocode into computer languages Lecture 14

Translating Pseudocode into computer languages Lecture 14

Data Types Pseudocode Integer Floating point Boolean Character String Pascal/Delphi Integer Single, Double Boolean

Data Types Pseudocode Integer Floating point Boolean Character String Pascal/Delphi Integer Single, Double Boolean Char String C++ int, long float, double bool char string

Module Declaration Pseudocode Name Statement/s END Pascal/Delphi C++ PROCEDURE Name(parameter if any); BEGIN Statement/s

Module Declaration Pseudocode Name Statement/s END Pascal/Delphi C++ PROCEDURE Name(parameter if any); BEGIN Statement/s ; END; void Name(parameter if any); { statement/s; }; FUNCTION Name(parameter if any): datatype Name(parameter if any) { statement/s; return value; }; datatype; BEGIN statement/s; Name : = return. Value; or RESULT : = return. Value; END;

Variable & Constant Declaration Pseudocode Pascal/Delphi C++ Variable Declaration VAR variable. Name 1, .

Variable & Constant Declaration Pseudocode Pascal/Delphi C++ Variable Declaration VAR variable. Name 1, . . . : datatype; datatype variable. Name 1, . . . ; CONSTNAME = value; const datatype CONSTNAME = value;

Assigning Value Pseudocode Pascal/Delphi SET variable. Name TO value or variable. Name = value

Assigning Value Pseudocode Pascal/Delphi SET variable. Name TO value or variable. Name = value variable. Name : = value ; C++ variable. Name = value ;

Conditinal Operators Pseudocode operand = operand NOT = operand < operand > operand <=

Conditinal Operators Pseudocode operand = operand NOT = operand < operand > operand <= operand Pascal/Delphi (operand = operand) (operand <> operand) (operand < operand) (operand > operand) (operand <= operand) C++ (operand == operand) (operand != operand) (operand < operand) (operand > operand) (operand <= operand)

Logical Operators Pseudocode operand AND operand OR operand NOT operand Pascal/Delphi operand AND operand

Logical Operators Pseudocode operand AND operand OR operand NOT operand Pascal/Delphi operand AND operand OR operand NOT (operand) C++ (operand && operand) (operand || operand) ! (operand)

IF ELSE Pseudocode IF (condition) THEN True statement/s block ELSE False statement/s block ENDIF

IF ELSE Pseudocode IF (condition) THEN True statement/s block ELSE False statement/s block ENDIF Pascal/Delphi C++ IF (condition) THEN BEGIN True statement/s block; END if (condition) { True statement/s block; } ELSE else { BEGIN False statement/s block; END; False statement/s block; };

CASE OF Pseudocode Pascal/Delphi CASE OF single_variable value_1 : statement block_1 value_2 : statement

CASE OF Pseudocode Pascal/Delphi CASE OF single_variable value_1 : statement block_1 value_2 : statement block_2. . . value_n : statement block_n. . . value_other : statement block_other ENDCASE single_variable OF value_1 : statement block_1; value_2 : statement block_2; . . . value_n : statement block_n; ELSE statement block_other; END; C++ SWITCH (single_variable) { case value_1 : statement/s ; break; case value_2 : statement/s; break; . . . case value_n : statement/s; break; default: statement/s; };

DO WHILE Pseudocode DO statement/s WHILE (condition) DOWHILE (condition) statement/s ENDDO Pascal/Delphi C++ REPEAT

DO WHILE Pseudocode DO statement/s WHILE (condition) DOWHILE (condition) statement/s ENDDO Pascal/Delphi C++ REPEAT statement/s; UNTIL NOT (condition); do { statement/s; } while (condition); WHILE (condition) DO BEGIN while (condition) { statement/s; END; statement/s; };

REPEAT UNTIL Pseudocode REPEAT statement/s UNTIL (condition) Pascal/Delphi REPEAT statement/s; UNTIL (condition); C++ do

REPEAT UNTIL Pseudocode REPEAT statement/s UNTIL (condition) Pascal/Delphi REPEAT statement/s; UNTIL (condition); C++ do { statement/s; } while !(condition);

COUNTER Pseudocode DO counter = begin TO end statement/s ENDDO Pascal/Delphi C++ FOR counter

COUNTER Pseudocode DO counter = begin TO end statement/s ENDDO Pascal/Delphi C++ FOR counter : = begin TO end DO BEGIN statement/s; END; for (counter = begin; counter <= end; counter++) { statement/s; };

RECORD STRUCTURE Pseudocode Record structures record. Name fieldname 1 fieldname 2. . . fieldname.

RECORD STRUCTURE Pseudocode Record structures record. Name fieldname 1 fieldname 2. . . fieldname. N Pascal/Delphi TYPE record. Name = RECORD field 1 : datatype; field 2 : datatype; . . field. N: datatype; END; C++ struct record. Name. Type { datatype field 1; datatype field 2; . . datatype field. N; };

Sequential Files -Reading Pseudocode Initial processing READ variable. Name DOWHILE NOT EOF. . READ

Sequential Files -Reading Pseudocode Initial processing READ variable. Name DOWHILE NOT EOF. . READ variable. Name ENDDO Final processing Pascal/Delphi Program Name(Input, Output, file. Handle) VAR file. Handle : TEXTFILE; . . . BEGIN ASSIGNFILE(file. Handle, ´´sourcefile´´); RESET (file. Handle); {Open for Reading} WHILE NOT (EOF(file. Handle)) DO BEGIN. . READLN(file. Handle, variable); END; . . . CLOSEFILE(file. Handle); END. C++ #include <fstream. h>. . . Ifstream in. File. Handle; . . . in. File. Handle. open(``source file``); . . . in. File. Handle >> variable. Name; while (!in. File. Handle. eof()) {. . . in. File. Handle >> variable. Name; }; in. File. Handle. close();

Sequential Files - Writing Pseudocode WRITE variable. Name Pascal/Delphi Program Name(Input, Output, file. Handle)

Sequential Files - Writing Pseudocode WRITE variable. Name Pascal/Delphi Program Name(Input, Output, file. Handle) VAR file. Handle : TEXTFILE; . . . BEGIN ASSIGNFILE(file. Handle, ´´sourcefile´´); REWRITE (file. Handle); {Open for Reading} WRITELN(file. Handle, variable or value); . . . CLOSEFILE(file. Handle); END. C++ #include <fstream. h>. . . ofstream out. File. Handle; . . . out. File. Handle. open(``source file``); . . . out. File. Handle << variable. Name<<`` ``; }; out. File. Handle. close();

Arrays Pseudocode Declaring arrays One-dimensional SET array. Name(max. Num. Elements) Declaring arrays Two-dimensional SET

Arrays Pseudocode Declaring arrays One-dimensional SET array. Name(max. Num. Elements) Declaring arrays Two-dimensional SET array. Name (row, column) Processing Array Elements Assigning a value array. Name (index) = value Reading a value variable. Name = array. Name (index) Pascal/Delphi C++ VAR array. Name : ARRAY[begin. . end] OF datatype; datatype array. Name [max. Num. Elements]; VAR array. Name : ARRAY[begin. . maxrow, begin. . maxcolumn] OF datatype; datatype array. Name [row][columns]; array. Name [index] : = value; array. Name [index] = value ; variable. Name : = array. Name [index]; variable. Name = array. Name [index];

END OF THE CLASS Good Luck for The Examination 15 June 2005 E 2,

END OF THE CLASS Good Luck for The Examination 15 June 2005 E 2, 11. 00 – 13. 00