ECS401U Procedural Programming Autumn 2018 Mid Term Test A
ECS401U Procedural Programming Autumn 2018 Mid Term Test A
Part 1
Question 1
Explain what is meant by
i) a statement
ii) An expression
Illustrate your answer using the following fragment of code:
if(shredder >10)
{
shredder = shredder -2;
}
else
{
System.out.println(“Shred! Shred!”);
}
Original Answer:
A statement is a unit of execution. For instance
“Shredder = shredder -2;” is a statement. Statements are usually identified
if they end with a ‘;’.
An expression is a construct of variables, method invocations and tests.
Expressions also use addition, multiplication , subtraction etc.
‘Shredder -2’ is an expression.
In the fragment of code above “Shred!Shred!” and “Shredder>10” are also
expressions. Also, the if-else code is also a statement (called an if-
statement)
Rewritten answer:
A statement is a complete unit of execution and in Java, statements
terminate with a semi-colon. In the code above,
“Shredder = shredder -2;” is a statement. Control structures are blocks of
code which dictate the flow of control. The if-then-else structure is also
considered a statement.
Original answer:
The nMOS transistor returns the same value given. For instance, if an
input of 1 is given, the transistor is turned on and the gate will be closed -
this allows the voltage from the ground flow to the drain. When the input is
0 the transistor is turned off and gate will be open.
A PMOS transistor inverts the input value. If the input value is 1, the
pMOS inverts thir value into a 0 and the gate will be open. Conversely, if
the input value is 0 the pMOS inverts this into a 1 and the gate will be
closed since the transistor is turned on. Combined they form an inverter.
Rewritten answer:
The nMOS transistor returns the same value given. For instance, if an
input of 1 is given, the transistor is turned on and the gate will be closed -
this allows the voltage from the ground to flow to the drain. When the
input is 0 the transistor is turned off and the gate will be open.
A PMOS transistor inverts the input value. If the input value is 1, the
pMOS inverts the value into a 0 and the gate will be open. Conversely, if
the input value is 0 the pMOS inverts this value into a 1 and the gate will
be closed since the transistor is turned on. Combined they form an inverter.
Commentary:
Having revised over the original answer I realised I was making simple
grammatical errors. In addition, I was unable to read a particular word
from the original answer. Naturally, I corrected these errors in the rewritten
answer. From this I’ve realised that I tend to overlook my work and miss
out on simple errors which could’ve been corrected. In the future, I will
make an effort to become more thorough when checking my answers.
//