COS1511 core Concepts
COS1511 core Concepts
Below are a list of questions with location of the related concepts in the course material.
(ii) The only other character that may be used in a name is the underscore character “_”. Names
may also
start with “_”.
(iii) Certain words like int and return can’t be used. However, a variable can be declared with the
name
cout, cin or endl.
Page in study guide: Page 21-22
1
It help get an insight into the inner working of a program. Mainly, the steps the variables go
through. They help track difficult bugs.
Page in study guide: 43
Answer:
It's when a value of a certain type gets converted into a value of another type.
Question 11: What is explicit type conversion ?
Answer: You use the wanted type in parenthese before the value to be converted to get a value of
the wanted type.
Page in study guide: 54
Question 12: What are the C++ type for String & Character?
Answer:
They are respectively string & char
Question 13: What is the difference between string and character?
Answer: Character is a one letter value; while string is a multiple letter value. It's truue a string can
also be a one letter value
Question 14: What are '\t' and '\n'?
Answer: The represent tabular space and newline characters
Page in study guide: 72
Answer:
<, >, <=, >=, ==, !=
Page in study guide: 86
2
Location: Debugging ---Lesson #10
Question 19: What are the boolean operators corresponding to the logical AND, OR and NOT
Answer: They are respectively: &&, || and !
Question 20: Why is “if (10 < n < 20)” a logical error?
Answer: The program gets evaluated differently from what the condition suggest. See Page 119 for
detailed walkthrough.
Question 21: Why is it better to use “y % x” rather than “y/x” in some instance?
Answer: When x = 0, the former won't throw an error; while the latter will throw an error.
Page in study guide: 117; 119
1. The variable(s) that appear in the loop condition (i.e. the loop control variable(s)) must be
initialised when the while loop is first encountered.
2. Test the loop control variable(s) in the condition of the loop. The condition must specify the
values of the control variable(s) for which the loop must continue repeating, and hence
(implicitly) the values for which the loop must terminate.
3. Inside the body of the loop, the value of the loop control variable(s) should be changed to
ensure that the loop condition becomes false at some stage.
Question 26: What is a a counter-driven loop?
Answer: A loop whose iteration is determined by a variable that keeps count of the number of times
the loop is executed.
Question 27: What is an accumulator?
Answer: When a loop is used to accumulate the sum of a sequence of values, the variable where the
3
sum is stored is an accumulator.
Question 28: What is a sentinel-driven loop?
Answer: A while loop that executes until a sentinel value is input
Question 29: What is a block?
Answer: A block is another name for a statement sequence, i.e. a series of statements enclosed by
braces { and }.
Page in study guide: 155; 156; 157
Question 32: What is structure nesting? What programming structure can be nested?
Answer: Structure nesting is when a programming structure appears in another one. If, switch,
while, “do ...while” and “for” can all be nested.
Question 33: What does the operator “%” do?
Answer: The % operator gives the remainder when one number is divided by another number.
Page in study guide:
Question 34: What is the difference between local and global variables?
Answer: Local variables are variables defined within a function; while global variables are variables
that are not declared in a function, but are accessible within it.
Question 35: What is the difference between parameters & local variables?
Answer: Parameters have their value passed to the function when the function is called; while local
variables are variables defined within a function. Moreover, locally declared variable is inaccessible
to other functions.
Question 36: When do you use global variables instead of local variables?
Answer: We should use local rather than global variables when variables belong to specific
functions. This prevents functions from inadvertently changing the values of variables needed in
other functions.
Question 37: When do you use parameters rather than global variables?
Answer: We should use parameters rather than global variables when more than one function needs
access to the same variables.
Page in study guide: 224
4
Location: Reference parameters---Lesson 21
5
Question 49: When do you use a struct?
Answer: Use a struct if you have related data (probably not of the same type), especially if you
would otherwise have to pass a lot of separate data values to a function.
Page in study guide: 343