Podcast
Questions and Answers
Explain the difference between a constant
and a variable
in programming, and provide an example of when you might use each.
Explain the difference between a constant
and a variable
in programming, and provide an example of when you might use each.
A constant is a named value that cannot change during the execution of a program, such as pi
. A variable is a named value that can change during execution, such as a user's score
in a game.
Describe the purpose of declaring variables before using them in a program. What advantages does this practice offer?
Describe the purpose of declaring variables before using them in a program. What advantages does this practice offer?
Declaring variables before use helps ensure that the program allocates the correct memory and data type for the variable. It improves code readability and helps prevent errors caused by using undeclared or mistyped variables.
Explain the concept of an identifier list
in programming and why it's considered good practice to create one.
Explain the concept of an identifier list
in programming and why it's considered good practice to create one.
An identifier list
is a comprehensive record of all variables and constants used in a program. Creating one ensures that all identifiers are declared and assigned values before manipulation, improving code organization and reducing errors.
How does pseudocode help in the initial stages of programming? Give an example of how pseudocode can be used to describe a simple task.
How does pseudocode help in the initial stages of programming? Give an example of how pseudocode can be used to describe a simple task.
Describe the different input methods shown, with the programming languages that use the specific method.
Describe the different input methods shown, with the programming languages that use the specific method.
Explain the purpose of using a WHILE
loop to validate user input, and provide a pseudocode example of how it could be implemented.
Explain the purpose of using a WHILE
loop to validate user input, and provide a pseudocode example of how it could be implemented.
Describe the primary difference between a CASE
statement and a nested IF
statement in programming. When is it more appropriate to use a CASE
statement?
Describe the primary difference between a CASE
statement and a nested IF
statement in programming. When is it more appropriate to use a CASE
statement?
Explain the use of the OTHERWISE
or ELSE
or DEFAULT
condition in a CASE
statement, and provide a scenario where it would be particularly useful.
Explain the use of the OTHERWISE
or ELSE
or DEFAULT
condition in a CASE
statement, and provide a scenario where it would be particularly useful.
Explain the difference between pre-condition and post-condition loops. What programming languages use them?
Explain the difference between pre-condition and post-condition loops. What programming languages use them?
Explain the difference between a count-controlled loop, a post-condition loop and a pre-condition loop. Give an example of situations for each type.
Explain the difference between a count-controlled loop, a post-condition loop and a pre-condition loop. Give an example of situations for each type.
Explain why a REPEAT...UNTIL
loop might be preferred over a WHILE...DO
loop for input validation. What key characteristic makes it suitable for this purpose?
Explain why a REPEAT...UNTIL
loop might be preferred over a WHILE...DO
loop for input validation. What key characteristic makes it suitable for this purpose?
Explain the purpose of loops in programming and describe a scenario where using a loop can significantly simplify a programming task.
Explain the purpose of loops in programming and describe a scenario where using a loop can significantly simplify a programming task.
Define what is meant by structured programming
and explain the advantages of using this approach.
Define what is meant by structured programming
and explain the advantages of using this approach.
Explain the role of procedures in structured programming. How do procedures contribute to code organization and reusability?
Explain the role of procedures in structured programming. How do procedures contribute to code organization and reusability?
Explain why using procedures is advantageous when the same set of statements needs to be used throughout the program.
Explain why using procedures is advantageous when the same set of statements needs to be used throughout the program.
In the context of procedures, what is a parameter
Explain the purpose of using parameters in procedures.
In the context of procedures, what is a parameter
Explain the purpose of using parameters in procedures.
Describe what is meant by passing a parameter by value
versus passing a parameter by reference
. What are the implications of each method?
Describe what is meant by passing a parameter by value
versus passing a parameter by reference
. What are the implications of each method?
What are the key components of a procedure or function header? What information does the header convey?
What are the key components of a procedure or function header? What information does the header convey?
What is the key difference between a procedure
and a function
in programming? How does this difference affect how they are used?
What is the key difference between a procedure
and a function
in programming? How does this difference affect how they are used?
Explain what is meant by a library routine
in programming, and provide two examples of common library routines.
Explain what is meant by a library routine
in programming, and provide two examples of common library routines.
What does the term header
mean in the context of defining procedures and functions? What pieces of information are stored in headers?
What does the term header
mean in the context of defining procedures and functions? What pieces of information are stored in headers?
Explain what is meant by argument
.
Explain what is meant by argument
.
What is the purpose of a RETURN
statement in a function definition, and when might a function have more than one RETURN
statement?
What is the purpose of a RETURN
statement in a function definition, and when might a function have more than one RETURN
statement?
What's the difference in Python with passing parameters?
What's the difference in Python with passing parameters?
In the context of functions and procedures, what does the term ByRef
mean?
In the context of functions and procedures, what does the term ByRef
mean?
Give three different variable name examples, with the following rules. One must be camel case, one must be snake case, and one must be pascal case.
Give three different variable name examples, with the following rules. One must be camel case, one must be snake case, and one must be pascal case.
In the pseudocode FUNCTION substring (myString: STRING, start: INTEGER, length: INTEGER) RETURNS STRING
, what purpose do STRING
and INTEGER
serve?
In the pseudocode FUNCTION substring (myString: STRING, start: INTEGER, length: INTEGER) RETURNS STRING
, what purpose do STRING
and INTEGER
serve?
Explain what is the name of a procedure called, and what should be used instead?
Explain what is the name of a procedure called, and what should be used instead?
What are Library routines fully tested for?
What are Library routines fully tested for?
Why is the keyword RETURN
used in functions?
Why is the keyword RETURN
used in functions?
Rewrite the pseudocode to ensure a function can only return a positive integer:
Rewrite the pseudocode to ensure a function can only return a positive integer:
In terms of coding algorithms, sometimes tasks can be very similar, explain how we still get the correct answer, and what is done to the algorithm?
In terms of coding algorithms, sometimes tasks can be very similar, explain how we still get the correct answer, and what is done to the algorithm?
For variables, what is important to do before any data manipulation?
For variables, what is important to do before any data manipulation?
What loop is best to use when the loop counter does not have to be managed by the programmer?
What loop is best to use when the loop counter does not have to be managed by the programmer?
Explain what is means by library routines?
Explain what is means by library routines?
Explain how the interface between a procedure and a program must relate?
Explain how the interface between a procedure and a program must relate?
How can multiple RETURN
statements be used in the same function?
How can multiple RETURN
statements be used in the same function?
Explain three benefits of using structured programing?
Explain three benefits of using structured programing?
Flashcards
Constant
Constant
A named value that cannot change during the execution of a program.
Variable
Variable
A named location in memory that stores a value that can be changed during program execution.
Procedure
Procedure
A set of statements grouped together to perform a specific task, but does not return a value.
Function
Function
Signup and view all the flashcards
Library Routine
Library Routine
Signup and view all the flashcards
Looping
Looping
Signup and view all the flashcards
Header
Header
Signup and view all the flashcards
Parameter
Parameter
Signup and view all the flashcards
Argument
Argument
Signup and view all the flashcards
Pass by Value
Pass by Value
Signup and view all the flashcards
Pass by Reference
Pass by Reference
Signup and view all the flashcards
Study Notes
- This chapter discusses programming concepts, including variables, constants, programming structures, and subroutines
What you should already know
- Write an algorithm using pseudocode to sort a list of 10 numbers
- The numbers should be input with prompts, placed in an array, sorted, and then searched for the number 27
- Output the sorted list and a message stating whether 27 was found
Programming Basics
- A constant is a named value that cannot change during program execution
- A variable is a named value that can change during program execution
- A function is a set of statements grouped together, called when required, and always returns a value
- Library routines are tested, ready-to-use routines available in the development system
- A procedure is a set of statements grouped together, called when required
Constants and Variables
- All variables and constants should be declared before use
- Constants are assigned a value when declared
- It is good practice to assign a value to any variables that are used
- Create an identifier list to ensure every variable is declared and assigned before data manipulation
- Some programming languages do not support the declaration of variables
- In languages like Python, assignment of a value ensures the correct data type is used
Programming Constructs
CASE and IF
- Nested IF statements are used when there are two different choices
- CASE statements are used for clarity when there are several different choices
- Choices can be: value of an identifier, a range of values, or exact value
- All conditions should conclude with an OTHERWISE case if no conditions are met
Loops
- Loops enable sections of code to be repeated as required
- Three types of loops include:
- Count-controlled loop (
FOR ... NEXT
) - Post-condition loop (
REPEAT ... UNTIL
) - Pre-condition loop (
WHILE ... DO ... ENDWHILE
)
- Count-controlled loop (
- Select the appropriate loop structure to efficiently solve the problem
- Use a REPEAT UNTIL loop rather than a WHILE DO ENDWHILE loop for a validation check
Structured Programming
- Use procedures and functions
- Procedures are subroutines or named procedures
- Procedures are defined once and can be called multiple times within a program
Procedures
- Procedures are called "void functions" in Python, "subroutines" in VB, and "methods" in Java
- A procedure can be defined in pseudocode as:
- PROCEDURE
-
- ENDPROCEDURE
- PROCEDURE
- The procedure is called using:
CALL <identifier>
- It is often useful to pass a parameter to a procedure to modify the actions
- This is done by passing a parameter when the procedure is called in the procedure definition
- A procedure with parameters can be defined in pseudocode, as follows:
- PROCEDURE
( : , : ...) -
- ENDPROCEDURE
- PROCEDURE
- The procedure can then be called many times:
CALL <identifier> (Valuel, Value2...)
- There are two methods of passing a parameter to a procedure:
- By value: the value of the variable cannot be changed within the procedure
- By reference: the value of the variable passed as the parameter can be changed by the procedure
- A procedure with parameters passed by reference can be defined in pseudocode as follows:
- PROCEDURE
(BYREF : , : ...) -
- ENDPROCEDURE
- PROCEDURE
Functions
- Used for calculations or tasks that produce an answer
- A function always returns a value
- Defined once and called many times within a program
- Functions are "fruitful functions" in Python that return values, "functions" in Visual Basic, and "methods with returns" in Java
- Functions can be used on the right-hand side of expressions
- A function without parameters is defined in pseudocode as follows:
- FUNCTION
RETURNS -
- ENDFUNCTION
- FUNCTION
- A function with parameters is defined in pseudocode as follows:
- FUNCTION
( : , : ...) RETURNS -
- ENDFUNCTION
- FUNCTION
- The keyword
RETURN
specifies the value returned and is usually the last statement in the function - Functions are used as part of an expression
- The returned value is the value the function outputs
- The interface between a function and a program must match the function definition
- When a function is defined with parameters, the parameters in the function call must match those in the function definition
- When procedures or functions are defined, the first statement in the definition is a header
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.