120 likes | 270 Views
Sha Tin Methodist College F.4 Computer Studies. Pascal Programming. 10. ASCII Table and String Comparison. Converting a character to ASCII code: e.g. ord(“char type”); Converting an ASCII code to character: e.g. chr(“integer type”); String Comparison. 11. String Manipulation.
E N D
Sha Tin Methodist CollegeF.4 Computer Studies Pascal Programming
10. ASCII Table and String Comparison • Converting a character to ASCII code: e.g. ord(“char type”); • Converting an ASCII code to character: e.g. chr(“integer type”); • String Comparison
11. String Manipulation • The length of the string: e.g. length(“string type”); • Selecting a character from a string: e.g. a[n]
11. String Manipulation • Selecting part of string: e.g. copy(string1, integer1,integer2); • String concatenation: e.g. concat(string1, string2); or “+”
11. String Manipulation • Convert a number into a string: e.g. str(“integer type”, “string type”); • Convert a string into numeric form: e.g. val(string1, number1, error_postion); • <eoln>: end of line (“Enter”)
12. Procedures • Procedure is a group of statements which can be called from different parts in a program. • Global and local variables • Parameter passing
13. File Handling • Steps in creating a new file: 1.Declare a file variable: e.g. var phone: text; 2.Assign the file variable with a file name: e.g. assign(phone, ‘tele.txt’);
13. File Handling 3.Open the file for output: e.g. rewrite(phone); 4.Write to the file: e.g. writeln(phone, variable1, variable2…); 5.Close the file: e.g. close(phone);
13. File Handling • Steps in reading a new file:Same as steps in creating a new file except step 3 and 4: reset(phone); readln(phone, variable1, variable2…); • End of file consideration: <eof>
14. Two dimensional array • Declaration of 2D array: e.g. var A: array[1..3, 1..4] of integer; • Use 2 for loops
15. Sorting • Bubble Sort
15. Sorting • Procedure “Swap” • Use 2 for loops in the main program • Merge SortThe Algorithm of the sorting