COS1512-24-Y Welcome Message Assessment 1
QUIZ
Started on Friday, 19 April 2024, 6:53 PM
State Finished
Completed on Friday, 19 April 2024, 7:56 PM
Time taken 1 hour 3 mins
Grade 7.00 out of 10.00 (70%)
Question 1
Incorrect
Mark 0.00 out of 1.00
The assert statement
Select one:
tests conditions or assumptions that should not occur in a program to prevent runtime errors
will display an error message when the condition in the statement is not true and abort the program.
All of the other options are valid.
can be turned on and off in a program
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort. The assert statement can be
turned on and off in a program using the #define NDEBUG directive.
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort. The assert statement can be
turned on and off in a program using the #define NDEBUG directive.
The correct answer is: All of the other options are valid.
, Question 2
Incorrect
Mark 0.00 out of 1.00
Base your answer to this question on the highlighted directives at the beginning of the program.
The program below will abort and display that the assertion has failed
#define NDEBUG
#include <cassert >
int main()
{
int x = 7;
/* Some big code in between and let's say x
is accidentally changed to 9 */
x = 9;
// Programmer assumes x to be 7 in rest of the code
assert(x==7);
/* Rest of the code */
return 0;
}
Select one:
True
False
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort. The assert statement can be
turned on and off in a program using the #define NDEBUG directive. In this program assert is turned off (NDEBUG is on) and
although the assertion will be false, the program will not abort.
The correct answer is 'False'.
Question 3
Correct
Mark 1.00 out of 1.00
To ensure that a test score score is valid, i.e. >= 0 and <= 100, we can use the following statement
Select one:
assert(!(0 <= score || score <= 100));
assert(score >= 0 && score <= 100);
assert(score >= 0 || score <= 100);
assert(!(0 <= score && score <= 100));
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort.
See Savitch Chapter 5 section 5.5 General Debugging Techniques, the assert macro
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort.
See Savitch Chapter 5 section 5.5 General Debugging Techniques, the assert macro
The correct answer is:
assert(score >= 0 && score <= 100);
QUIZ
Started on Friday, 19 April 2024, 6:53 PM
State Finished
Completed on Friday, 19 April 2024, 7:56 PM
Time taken 1 hour 3 mins
Grade 7.00 out of 10.00 (70%)
Question 1
Incorrect
Mark 0.00 out of 1.00
The assert statement
Select one:
tests conditions or assumptions that should not occur in a program to prevent runtime errors
will display an error message when the condition in the statement is not true and abort the program.
All of the other options are valid.
can be turned on and off in a program
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort. The assert statement can be
turned on and off in a program using the #define NDEBUG directive.
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort. The assert statement can be
turned on and off in a program using the #define NDEBUG directive.
The correct answer is: All of the other options are valid.
, Question 2
Incorrect
Mark 0.00 out of 1.00
Base your answer to this question on the highlighted directives at the beginning of the program.
The program below will abort and display that the assertion has failed
#define NDEBUG
#include <cassert >
int main()
{
int x = 7;
/* Some big code in between and let's say x
is accidentally changed to 9 */
x = 9;
// Programmer assumes x to be 7 in rest of the code
assert(x==7);
/* Rest of the code */
return 0;
}
Select one:
True
False
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort. The assert statement can be
turned on and off in a program using the #define NDEBUG directive. In this program assert is turned off (NDEBUG is on) and
although the assertion will be false, the program will not abort.
The correct answer is 'False'.
Question 3
Correct
Mark 1.00 out of 1.00
To ensure that a test score score is valid, i.e. >= 0 and <= 100, we can use the following statement
Select one:
assert(!(0 <= score || score <= 100));
assert(score >= 0 && score <= 100);
assert(score >= 0 || score <= 100);
assert(!(0 <= score && score <= 100));
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort.
See Savitch Chapter 5 section 5.5 General Debugging Techniques, the assert macro
The assert statement tests conditions or assumptions that should not occur in a program to prevent runtime errors using a
boolean expression. If the result of the boolean expression is not true, the program will abort.
See Savitch Chapter 5 section 5.5 General Debugging Techniques, the assert macro
The correct answer is:
assert(score >= 0 && score <= 100);