11.1 Programming Basics (3)
Resources |
Revision Questions |
Computer Science
Login to see all questions
Click on a question to view the answer
1.
Write pseudo-code statements to demonstrate the declaration and initialization of a constant named MAX_STUDENTS with a value of 30. Include a brief explanation of what a constant is and why it is useful.
Explanation: A constant is a named value that cannot be changed during the execution of a program. They are useful for representing fixed values, improving code readability, and preventing accidental modification of important parameters. Using constants makes code easier to maintain and understand.
Pseudo-code:
- Declaration:
DECLARE MAX_STUDENTS AS CONSTANT
- Initialization:
MAX_STUDENTS = 30
2.
Question 2
Write pseudo-code statements for a program that takes a positive real number as input from the keyboard. The program should then check if the number is greater than 100. If it is, output "Greater than 100". Otherwise, output "Less than or equal to 100".
Pseudo-code:
- Begin
- Declare a real variable,
number
. - Prompt the user to enter a positive real number and store it in
number
. - Check if
number
is greater than 100. - If
number > 100
then - Output "Greater than 100"
- Else
- Output "Less than or equal to 100"
- End If
- End
3.
Write pseudo-code statements to declare three integer variables: age, score, and attempts. Each variable should be assigned an initial value of 0.
Pseudo-code:
- Declare a variable named age with the data type integer and assign it the value 0.
- Declare a variable named score with the data type integer and assign it the value 0.
- Declare a variable named attempts with the data type integer and assign it the value 0.
Example:
Variable Name | Data Type | Initial Value |
age | integer | 0 |
score | integer | 0 |
attempts | integer | 0 |