You are on page 1of 5

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.

An expression is a construct of variables , method invocations and


operators that evaluate to a single value. The expression ‘Shredder -2’ is an
integer expression since it only uses values of type integer. In the fragment
of code above, “Shred! Shred!” and ‘Shredder > 10’ are expressions.
Commentary:
In the new version I split the answer into two parts. The first part describes
statements and the second part describes expressions. I did this because it
makes the answer easier to read and follow. I believe the rewritten answer
is an improved version of the original since it’s more concise and is less
repetitive. For instance, in the original version I overused the word ‘also’
in the last paragraph which was used 3 times in the last two sentences
whereas in the rewritten version, I simply condensed the two sentences
into one. In the future, I should aim to organise my points into distinct
sections to avoid confusion. I believe this would bring greater clarity to
myself and the reader.
ECS404U Computer Systems and Networks: Midterm Test 2018

Question 2 (d)


ii) Describe how these transistors (nmos and pmos) function as


switches. What is the role of each part of the transistor? Under what
circumstances are the switches open or closed.

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.
//

You might also like