Logic Flashcards

1
Q

Question: What are the three classes of constructs required to complete a programming language according to the given text?

A

Answer: The three classes of constructs required to complete a programming language are sequential constructs, selection constructs, and iteration constructs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Question: Why is it important for software to be readable and easy to upgrade and maintain?

A

Answer: It is important for software to be readable and easy to upgrade and maintain because programmers who maintain application software are typically not those who develop the software originally, and the maintenance programmers may change throughout the lifetime of a software application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Question: What are the principles of structured programming, and when were they developed?

A

Answer: The principles of structured programming were developed in the 1960s and provide important coding guidelines that respect the objective of making software readable, easy to upgrade, and maintainable. A structured program consists of sets of simple constructs, each of which has one entry point and one exit point. Any programmer may replace one construct with an upgraded construct without affecting the other constructs in the program or introducing errors (“bugs”).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Question: What is a code block, and how is it different from a single statement in C programming?

A

Answer: A code block is a set of statements enclosed in a pair of curly braces to be executed sequentially. Unlike a single statement, a C code block does not require a terminating semi-colon of its own (after the closing brace).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Question: What does the chapter describe about implementing structured programming principles in coding iterations?

A

Answer: The chapter introduces the selection and iteration constructs supported by the C language and describes how to implement structured programming principles in coding iterations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Question: What are some techniques used during the design stage of a programming solution?

A

Answer: Some well-established techniques include pseudo-coding and flow charting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Question: What is pseudo-code?

A

Answer: Pseudo-code is a set of shorthand notes in a human (non-programming) language that itemizes the key steps in the sequence of instructions that produce a programming solution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Question: What is flow charting?

A

Answer: Flow charting is a set of conventional symbols connected by arrows that illustrate the flow of control through a programming solution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Question: What are the three selection constructs supported by the C language?

A

Answer: The three selection constructs supported by the C language are the optional path, alternative paths, and conditional expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Question: What is the binary selection construct?

A

Answer: The binary selection construct executes one of a set of alternative sequences and takes the form if (condition) sequence else sequence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Question: What is the suggested coding style for maximum readability and maintainability?

A

Answer: It is suggested to create a code block for single-line statements, including the placement of the opening and closing curly braces on their own dedicated lines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Question: What is the syntax for a multiple selection construct in C programming?

A

Answer: The syntax for a multiple selection construct in C programming is:

if (condition1)
sequence1
else if (condition2)
sequence2
else
sequence3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Question: What is the syntax for a case-by-case selection construct in C programming?

A

Answer: The syntax for a case-by-case selection construct in C programming is:
switch (condition)
{
case constant1:
sequence1
break;
case constant2:
sequence2
break;
default:
sequence3
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Question: What is the purpose of the conditional expression selection construct in C programming?

A

Answer: The purpose of the conditional expression selection construct in C programming is to provide shorthand for the alternative path construct, which allows for a more concise syntax for conditional statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Question: What are the three iteration constructs supported by the C language?

A

Answer: The three iteration constructs supported by the C language are while, do while, and for.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Question: What are the three instructions that control the execution of an iteration in C language?

A

Answer: The three instructions that control the execution of an iteration in C language are initialization, a test condition, and a change statement.

17
Q

Question: What happens if the change statement is missing or the test condition is always satisfied in an iteration?

A

Answer: If the change statement is missing or the test condition is always satisfied in an iteration, the iteration continues without terminating, and the program can never terminate. This is called an infinite loop.

18
Q

Question: How does the while construct work in C language?

A

Answer: The while construct in C language executes its sequence as long as the test condition is true. It takes the form:

while (condition) {
sequence
}

19
Q

Question: How does the do while construct work in C language?

A

Answer: The do while construct in C language executes its sequence at least once and continues executing it as long as the test condition is true. It takes the form:

do {
sequence
} while (condition);

20
Q

Question: How does the for construct work in C language?

A

Answer: The for construct in C language groups the initialization, test condition, and change together, separating them with semi-colons. It takes the form:

for (initialization; condition; change) {
sequence
}

21
Q

Question: What is flagging in structured programming and how does it improve the design of flow charts?

A

Answer: Flagging is a method of coding iteration constructs within the single-entry single-exit principle of structured programming. It involves using variables called flags that are either true or false to determine whether an iteration continues or stops. Flags help ensure that no paths cross one another and improve the design of flow charts by avoiding the jump and multiple exit.

22
Q

Question: What is the purpose of using a flag in the code example provided?

A

Answer: The purpose of using a flag in the code example provided is to terminate the iteration prematurely.

23
Q

Question: How is the test condition in the code example a compound logical expression?

A

Answer: The test condition in the code example is a compound logical expression because it involves the evaluation of both the iterator variable i and the flag done. The iteration stops if done == 1.

24
Q

Question: What are some cases to avoid when managing process flow in structured programming?

A

Answer: Some cases to avoid when managing process flow in structured programming include: break (except in the switch construct and only one per case), continue, exit, goto, return, and changing the iterator variable in more than one place.

25
Q

Question: What is nesting in programming?

A

Answer: Nesting is enclosing one logic construct within another in programming.

26
Q

Question: What is a nested selection?

A

Answer: A selection within another selection is called a nested selection.

27
Q

Question: Can a nested if-else construct cause ambiguity?

A

Answer: Yes, an ambiguity arises in a nested if-else construct that contains an optional sequence (if).

28
Q

Question: How can the ambiguity in the nested if-else construct be resolved?

A

Answer: The ambiguity in the nested if-else construct can be resolved by using code blocks (curly braces) to ensure the intended flow.

29
Q

Question: What is a nested iteration?

A

Answer: An iteration within another iteration is called a nested iteration.

30
Q

Question: Can you provide an example of nested iteration in C language?

A

Answer: An example of nested iteration in C language is as follows:
#include <stdio.h></stdio.h>

int main(void)
{
int i, j;

for (i = 0; i < 5; i++)
{
    for (j = 0; j < 5; j++)
    {
        printf("%d,%d  ", i, j);
    }

    printf("\n");
}

return 0; }