PA+-+Pascal

Doc. RNDr. Pavel Satrapa, Ph. D. Email: pavel.satrapa (at) tul.cz Tel: +420 48 535 3685 Office: A9
 * Programming paradigms**


 * Some usefull links for our PAP course:** (Satrapa's presentations)

[|Programming paradigms 1] [|http://www.kai.vslib.cz/~satrapa/en/programming/]

[|Programming paradigms 2] [|http://www.kai.vslib.cz/~satrapa/en/paradigms/]

0 if N<=0 255 if N>=255 N otherwise
 * Exam #4:**
 * 1)** Create an Integer function named //Restrict// which takes one Integer argument N and returns it restricted to the interval 0...255. This means that it should return:

For example //Restrict// (-15) returns 0, //Restrict// (37) returns 37, and //Restrict// (1000) returns 255.

//Solution: //


 * 2)** Create a program to check if the input sequence is exponential. The input is a sequence of positive integers ended by 0. The output will return true or other positive message only if every number in the input sequence is equal to the double of its predecessor (Xn=2*Xn-1). If not the program will return false. First input value is not checked.

EXAMPLE: If the input contains: 3 6 12 24 48 96 0 ............. result TRUE

//Solution: //


 * Exam #3:**
 * 1)** Create an Integer function named //RandomRange// which takes two Integer arguments M, N and returns a random number in the range from M to N. (Use the standard function Random(x) returning a random integer value from 0 to x-1.)

For example //RandomRange// (10,20) returns random value from 10 to 20.

//Solution: //


 * 2)** Change the input sequence of numbers to a non-decreasing one. Every value from the input which is smaller than the previous is replaced by the previous value. Therefore all the values in the output sequence are larger or equal to their predecessors.

EXAMPLE: If the input contains: 3 8 12 9 15 7 14 25 38 -5 the result should be: 3 8 12 12 15 15 15 25 38

//Solution: //


 * 3)** Find a row in a multi-line input text containing a maximum number of digits. The text should be ended by a line with only one dot. The output of the program should be the line with the highest number of digits.

EXAMPLE: If the input contains: //An infinitude of prime numbers exists, as demonstrated by Euclid in about 300 BC. First 5 prime numbers are 2, 3, 5, 7, 11. See the list of prime numbers for more. .//

the result should be: //First 5 prime numbers are 2, 3, 5,//

//Solution: //


 * Exam #2:**
 * 1)** Create a Boolean function named IsMultiple which takes two Integer arguments A and B. The function should return True, if B is a multiple of A - otherwise it should return False. (B is a multiple of A = if B is divisible by A without any rest)

For example IsMultiple(4,32) returns True, IsMultiple (4,15) returns False.

//Solution: //

INPUT: Sequence of non-zero real numbers, ended by 0. OUTPUT: The number expressing how many values in the input are larger then their predecessors. The first number should be processed as if its predecessor is zero.
 * 2)** Create a program calculating number of increases in the input.

EXAMPLE: If the input contains: 4 6.5 -2.2 12 17 8 4 10 0 The result should be 5 because there are five numbers larger than the number before (4, 6.5, 12, 17, 10).

//Solution: //

INPUT: First line of input contains 10 characters representing the cipher. The first character is replacement for the digit 0, the second will replace 1, next replace 2 etc. The second line contains the encrypted text. OUTPUT: The second line from input, where all digits are replaced bz corresponding characters, as defined by the first line. EXAMPLE: If the input contains:
 * 3)** Create program encrypting the digits in the input. It uses the simple cipher where every digit is replaced by particular character (for example “B” is uses instead of “1”). Other characters remain intact.

CFESTLOYHN 300 + 19 = 319

The result will be SCC+FN=SFN


 * Exam #1:**

//Solution:// // //


 * (this one is can be without the //case// command, but it is much easir to use the //case// command)**


 * Pre-Exam:**

http://www.kai.vslib.cz/%7Esatrapa/en/programming/demo-exam.pdf

Solution: http://www.kai.vslib.cz/%7Esatrapa/en/programming/demo-exam1.pas http://www.kai.vslib.cz/%7Esatrapa/en/programming/demo-exam2.pas http://www.kai.vslib.cz/%7Esatrapa/en/programming/demo-exam3.pas