Labs and Tasks
{0.3 points}
Task 1:
To do: Two integers are given. Check if the following statement is True: the first number is greater than the second (the program must return True if it is true, and False otherwise).
Expected output:
please enter two integers >>> 23 >>> 1 23 is greater than 1 is True
[Program name: L3task01.pas]
{0.3 points}
Task 2:
To do: Two integers are entered. Check the truth of the statement: the first number is not equal to the second (the program must return True if it is true and False otherwise).
Expected output:
please enter two integers >>>5 >>>5 5 is not equal to 5 is False
[Program name: L3task02.pas]
{0.3 points}
Task 3:
To do: Three integers are given: the values of variables A, B, C. Check the truth of the double inequality A < B < C. Make sure that your program is correct with at least two input data sets, give the log of the program in the form of a comment.
Expected output:
please enter three integers >>>3 >>>6 >>>2 3 is less than 6 less than 2 is False please enter three integers >>>2 >>>5 >>>7 2 is less than 5 less than 7 is True
[Program name: L3task03.pas]
{0.6 point}
Task 4:
To do: Three-digit integer is given. Check the truth: the first digit (left digit) of the number is less than the second (middle) and third (right).
Expected output:
please enter a three digit number >>> 854 8 is less than 5 and 4 is : False
[Program name: L3task04.pas]
{0.6 point}
Task 5:
To do: Two integers are entered. Check the truth of the statement: at least one of these numbers is odd.
Note: Use the odd standard function:
// The function odd returns True when its argument is odd integer: print (odd(5)); // true print (odd(6)); // false
Check the following:
- -5, 8 => True
- 12, 0 => False
- 6, -1 => True
- 11, 7 => True
Expected output:
please enter two integer numbers >>> 9 >>> 2 Either 9 or 2 is an odd number. This is : True
[Program name: L3task05.pas]
{0.3 points}
Task 6:
To do: An integer is entered. If this is positive number, you should add 1 to it. Output the result.
Check the following:
- -3 => -3
- 0 => 0
- 1 => 2
- 5 => 6
Expected output:
please enter an integer number >>> -77 The result is -77
[Program name: L3task06.pas]
{0.3 points}
Task 7:
To do: An integer is given. If this is even number then multiply it by 10. Output the result.
Check the following:
- 2 => 20
- 1 => 1
- -10 => -100
Expected output:
please enter an integer number >>> 8 The result is 80
[Program name: L3task07.pas]
{0.5 points}
Task 8:
To do: An integer is given. If this is an even number, then multiply it by 3, if it is not even, then divide it by 3. Output.
Check the following:
- 4 => 12
- 9 => 3
- -10 => -30
Expected output:
please enter an integer number >>> 12 The result is 36
[Program name: L3task08.pas]
{0.5 points}
Task 9:
To do: An integer is given. If this is a positive number then add 1 to it; otherwise subtract it by 2. Output.
Check the following:
- -3 => -5
- 0 => 1
- 1 => 2
- 5 => 6
Expected output:
please enter an integer number >>> 48 The result is 49
[Program name: L3task09.pas]
{0.5 points}
Task 10:
To do: An integer is given (age of the person). If it is greater than or equal to 18, then output "you can watch this movie"; if the number is less than 10, then output "you should watch the cartoon". Otherwise, print "you can take a walk".
Expected output:
how old are you? >>> 8 you should watch the cartoon how old are you? >>> 15 you can take a walk
[Program name: L3task10.pas]
{0.5 points}
Task 11:
To do: The student received a grade. If it is 2 points, then the program should output "it's very bad"; if it is a 3 - program should print "it's bad"; if it is 4 - "it's good", in case of 5 - "it's excellent", otherwise - "there are no such marks".
Expected output:
what's your grade? >>> 2 "it's very bad" what's your grade? >>> 4 "it's good"
[Program name: L3task11.pas]
{0.5 points}
Task 12:
To do: The program must request the time of a day in hours (from 1 to 24). Depending on the time entered, display a message indicating what time of a day the entered hour belongs to (midnight (24), night (1-4), morning (5-11), day (12-16), evening (17-13)).
Expected output:
what's time of the day? >>> 2 "night" what's time of the day? >>> 24 "midnight"
[Program name: L3task12.pas]
{0.5 points}
Task 13:
To do: Two integer values are given (set them to variables A and B). Assign a sum of these values to each variable if their values are not equal; otherwise (if they are equal) assign zero to the variables. Output the new values of variables A and B.
Expected output:
please enter two integer numbers 3 5 The result is A = 8, B = 8 please enter two integer numbers 4 4 The result is A = 0, B = 0
[Program name: L3task13.pas]
{0.5 points}
Task 14:
To do: An two-digit integer N is entered, |N| ∈ [10;99].
- If it is even and divided by 4, then "add" 4 digit from the left (that is, to form a new number, which in the category of hundreds has 4, and the digits of tens and units are left as in the original number);
- If it is even, but is not divided by 4, then "add" 2 digit from the left of the number;
- If it is odd, then "add" 0 digit from the right of the number. Print the resulting number.
Expected output:
N: >>> 16 result = 416 N: >>> 86 result = 286 N: >>> 31 result = 310
[Program name: L3task14.pas]
{0.5 points}
Task 15:
To do: Integer number x is entered. Calculate the value of the function f:
f(x) = x + 4, if x ≥ 0 f(x) = x - 4, if x < 0
Expected output:
Enter an integer: >>> 4 Result is 8
[Program name: L3task15.pas]
{0.5 points}
Task 16:
To do: Real number x is entered. Calculate the value of the function f:
f(x) = 6 - x, if x ≤ 0 f(x) = 2 sin(x), if x > 0
Expected output:
please, enter an x value: -2 result of 6-x = 8 please, enter an x value: 5 result of 2sin(x) = -1.91784854932628
[Program name: L3task16.pas]
{0.5 points}
Task 17:
To do: A three-digit integer a is entered. Print True if there is a permutation of digits that makes number which is divided by 10, and False otherwise (e.g. 602 => True [620, 260]).
Note: It is allowed to use no more than three operators div and mod (in total).
Expected output:
Enter three-digit integer: >>> 602 True Enter three-digit integer: >>> 311 False Enter three-digit integer: >>> -100 True
[Program name: L3task17.pas]
{0.3 points}
Task 18:
To do: Perform the task using the Case statement. The student received a grade. If it is 2 points, then the program should output "it's very bad"; if it is a 3 - program should print "it's bad"; if it is 4 - "it's good", in case of 5 - "it's excellent", otherwise - "there are no such marks".
Expected output:
what's your grade? >>> 2 "it's very bad" what's your grade? >>> 4 "it's good"
[Program name: L3task18.pas]
{0.3 points}
Task 19:
To do: Perform the task using the Case statement. An integer in the range [1;7] is entered. Output a name of the day corresponding to this number (1 - “Monday”, 2 - “Tuesday”, etc.).
Expected output:
please enter an integer from 1-7, for day of the week 4 Thursday please enter an integer from 1-7, for day of the week 9 such day does not exist
[Program name: L3task19.pas]
{0.3 points}
Task 20:
To do: Perform the task using the Case statement. Arithmetic operations are numbered as follows: 1 - addition, 2 - subtraction, 3 - multiplication, 4 - division. Ask user to enter number - arithmetic operation (integer in the range of [1;4]) and two reals A and B (B is not = 0). Output the result of the specified arithmetic operation with the given numbers.
Expected output:
Enter arithmetic operation, please (from 1 till 4): >>> 1 Enter two real numbers: >>> 2.2 >>> 5.0 the result is 2.2 + 5.0 = 7.2 Enter arithmetic operation, please (from 1 till 4): >>> 2 Enter two real numbers: >>> 5.3 >>> 3.2 the result is 5.3 - 3.2 = 2.5
[Program name: L3task20.pas]
{0.3 points}
Task 21:
To do: Perform the task using the Case statement. Program requests to enter a number of the mass units (1 means kilogram, 2 means ounce, 3 - gram, 4 - ton, 5 - pound). Then the program requests body weight in one of these units. Output body weight in kilograms (1 ounce = 0.0283 kilograms, 1 gram = 0.0010 kilograms, 1 ton = 1000 kilograms, 1 pound = 0.4536 kilograms).
Expected output:
enter body weight >>> 4 enter mass 1..5 >>> 4 in kilograms = 4000
[Program name: L3task21.pas]
{0.5 points}
Task 22:
To do: Perform the task using the Case statement. The commands are numbered as follows:
- check if the number is negative;
- check if the number is odd;
- check if the number is the divided by entered number D (the number D is entered by the user when this command is selected).
Note: In response to entering an incorrect command, you should display the message "Command is unknown!".
Expected output:
N : >>> -23 C : >>> 1 True N : >>> 103 C : >>> 3 D : >>> 7 False
[Program name: L3task22.pas]
{0.2 points}
Task 24:
To do: Perform the task using Case statement: The program must request the time of a day: midnight or night or morning or day or evening. The program must display a range of hours belonging to entered time of a day (midnight (24), night (1-4), morning (5-11), day (12-16), evening (17-23)).
Expected output:
enter the time of the day >>> night result: a range of hours for night is 1..4
[Program name: L3task24.pas]
{0.2 points}
Task 25:
To do: Perform the task using Case statement with ranges: The program must request the time of day in hours (from 1 to 24). Depending on the time entered, display a message indicating what time of day the entered hour belongs to (midnight (24), night (1-4), morning (5-11), day (12-16), evening (17-13)).
Expected output:
Enter a time of a day in hours (from 1 to 24), please: >>> 14 result: 14 hours belongs to day Enter a time of a day in hours (from 1 to 24), please: >>> 24 result: 24 hours belongs to midnight
[Program name: L3task25.pas]
{0.2 points}
Task 26:
To do: Perform the task using Case statement with ranges: The program must request number - the age. Depending on the entered number display a message indicating the age of person in words (infancy: from 0 to 1 year old, early childhood: 2-4 years old, preschool: 5-7 years old, school age: 8 - 12 years old, youth: 13-19 years old, second youth: 20–35 years old, adulthood: 36-65 years, old age: over than 66 years).
Expected output:
how old are you? >>> 6 preschool how old are you? >>> 37 adulthood
[Program name: L3task26.pas]
Tasks for self-solving
Note: tasks should be saved in a file with the name of the task, and be sure to insert a comment with the statement of the task in the code.
CASE
Case6.
The units of length are numbered as: 1 — decimeter, 2 — kilometer, 3 — meter, 4 — millimeter, 5 — centimeter. The order number N of a unit of length and also the length L of a segment are given (N is an integer in the range 1 to 5, L is a real number). Output the length of the segment in meters.
Expected output:
<< dm =3.15 results: m = 0.315
Case12.
Elements of a circle are numbered as: 1 — radius R, 2 — diameter D = 2·R, 3 — length L = 2·π·R of the circumference, 4 — area S = π·R². The order number of one element and its value (as a real number) are given. Output values of other elements in the same order. Use 3.14 for a value of π.
Expected output:
<< 2 D = 0.79 results: R = 0.40 L = 2.48 S = 0.49
Case15.
The suits of playing cards are numbered as: 1 — spades, 2 — clubs, 3 — diamonds, 4 — hearts. Card values "Jack", "Queen", "King", "Ace" are numbered as 11, 12, 13, 14 respectively. A card value N (as an integer in the range 6 to 14) and a suit M (as an integer in the range 1 to 4) are given. Output the card description as: "six of diamonds", "queen of spades", etc.
Expected output:
<< Card number N = 9, Card value M = 3 results: "diamonds nine"
Hometask
Complete this week's tasks that you didn't have time to do in class. The file names are specified in the tasks. You should upload your files to Microsoft Teams.