Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Say whether each of the following statements is true (“T”) or false (“F”). __ Wh

ID: 3927995 • Letter: S

Question

Say whether each of the following statements is true (“T”) or false (“F”).

__ When modifying existing software, changes should follow the style of the original code.

__ In software testing, “path coverage” is another name for “statement coverage”.

__ The file command can be used to assess the type of a file.

__ The “o” in a pattern o+rx that can be given as as argument to chmod(1) stands for “owner”.

__ A downside to operating systems like LINUX and UNIX is that they still use the concept of processes.

Other operating systems, such as Microsoft Windows, have done away with processes.

__ To send a signal to a process we use the >>> construct in the shell. For example, to send a SIGKILL to a process with PID 7476, we would give the command

__ A characteristic of TDD (test-driven development) is the extensive use of prototypes.

__ Most UNIX/LINUX (shell) commands are actually the names of programs.

__ A characteristic of iterative software development is that one breaks a problem into a small problem plus

a series of increments.

__ In a C/C++ program that includes the file <inttypes.h>, a data type of uint32_t is always 4 bytes in size.

B. (1 mark each, 6 marks total)

In each of the statements below, fill in the blank with the word or phrase which best fits the overall state- ment.

In the context of output from ps(1), the acronym PPID stands for _______________________________ .

The name of the environment variable which defines the list of paths searched by bash for commands is

_________________________ .

Every complete C/C++ program has a function called __________________ . It is the standard entry point

to the program.

UNIX/LINUX tools (commands) typically follow the convention of writing their output to

____________________________ and reading their input from __________________________ .

In UNIX/LINUX, a(n) _______________ is a named sequence of nonvolatile bytes.

A(n) _______________ is a a pair of streams, one for writing and one for reading, such that everything written on the output stream can be read from the input stream in order and with full fidelity.

C. (26 marks)

For each of the following multiple-choice1 questions, indicate the answer that is the best response to the question. Circle the label (e.g. “(a)”) of your intended response in each case.

1. Which of the following sentences describing “testing” and “debugging” is true?

(a) Testing finds bugs, debugging locates error messages.

(b) Testing finds coding faults, debugging locates execution failures.

(c) Testing finds execution failures, debugging locates coding faults.

(d) Testing generates error messages, debugging locates bugs.

(e) None of the above.

1. or, as Peppermint Patty from the Peanuts comic strip would say, “mystical guess”

page 2

Cmpt 214 Midterm Examination

October 21, 2014

Which of the following statements regarding good programming style is true?

(a) A user should preferentially use the layout

rather than

(b) A user should preferentially use the layout if (condition)

{ }

rather than

(c) Either of
if (condition)

{ }

or

can be used. What is more important, however, is that one format is chosen and then used consis- tently.

(d) Neither
if( condition ) {

}

nor

is an acceptable format.

What is the name of the type of testing that checks that features that were working before are still work- ing?

(a) White-box testing.

(b) Unit testing.

(c) Regression testing.

(d) Randomized testing.

(e) None of the above.

The “#ifdef” construct in C/C++ is an example of

(a) a preprocessor directive.

(b) bad programming style.

(c) TDD.

(d) defensive programming.

(e) None of the above.

page 3

Cmpt 214 Midterm Examination

October 21, 2014

What is the name of a special file in UNIX/LINUX to which one can redirect output and that output is simply discarded (by the operating system)?

(a) NULL

(b) /dev/null

(c) /root

(d) /usr/bin

(e) Any of the above.

page 4

Cmpt 214 Midterm Examination

October 21, 2014

Consider the following declaration in C:

Given the above, the address of student_records[2] will be the same as the value of which expression below?

(a) student_records[0]+2

(b) *student_records[2]

(c) *student_records+2

(d) rec_p+2

(e) None of the above.

In a C/C++ program, writing if( 7 == N )

rather than

if( N == 7 )

is an example of what?

(a) Defensive programming.

(b) Iterative software development.

(c) Use of prototypes.

(d) Test-driven development.

(e) All of the above.

It is the job of the shell (e.g. bash) to interpret various components of a command. Which of the following is(are) not interpreted by the shell?

(a) History references, such as !!.

(b) A command alias.

(c) Filename wildcards.

(d) Shell variable names preceded by $.

(e) Arguments enclosed within single quotes, ''.

(f) All of the above.

What is the function of the “>>” operator in the bash command cat foo >> bar

? Assume that the noclobber shell variable is set to its default value.

(a) Passes output of cat(1) to the program (command) bar.

(b) Indicates that data from the file bar should be considered (input) after the data from file foo.

(c) Overwrites file bar with the contents of file foo.

(d) Redirects error messages from the execution of cat into file foo.

(e) None of the above.

page 5

Cmpt 214 Midterm Examination
12. Consider the following sample of code from an in-class example.

October 21, 2014

}

The example was following the in-class programming guidelines and TDD. As such, it is an example of

(a) defensive programming.

(b) a prototype.

(c) a data definition.

(d) a module template.

(e) a stub.

(f) None of the above.

13. Consider again the following sample of code from an in-class example.

}

The example was following the in-class programming guidelines and TDD. As such, the

return 'F';

statement is an example of

(a) defensive programming.

(b) a prototype.

(c) a data definition.

(d) a module template.

(e) a stub.

(f) None of the above.

14. An early version of UNIX was

(a) System III.

(b) System V.

(c) SunOS.

(d) 4.3BSD.

(e) All of the above.

page 6

Cmpt 214 Midterm Examination

October 21, 2014

Consider the following pipelined command:
cat < /etc/passwd | cut -f 3 | wc -l

Which of the following statements is false regarding this complex command?

(a) cut(1) gets its input from a pipe

(b) cut(1) gets its input from its standard input

(c) cat(1) gets its input from its standard input

(d) cat(1) is invoked with one command-line argument

(e) All of the above.

Which of the following commands below can be used to determine what file systems have been mounted on a (running) LINUX/UNIX file system?

(a) df

(b) uname

(c) hostname

(d) whoami

(e) All of the above.

(f) None of the above.

Which of the following bash commands will produce the output $PATH

?

(a) echo $PATH

(b) echo "$PATH"

(c) echo $PATH

(d) cat $PATH

What is the role of “&” in the command sort foo.txt > bar.txt &

?

(a) It forces the overwriting of bar.txt, even if it already exists.

(b) It makes sure that the command completes.

(c) It directs the shell to run the sort process in the background.

(d) It forces the command to be run as a shell built-in.

(e) It tells the shell to execute the command without creating a child process.

(f) None of the above.

A co-worker suggests that worrying about permissions on a file-by-file basis is too much work, and sug- gests setting the permissions of all files using

chmod 777

Which of the below represents a legitimate response?

(a) This is fine.

(b) Everyone would be able to access my files!

(c) I won't be able to access my own files!

(d) None of the above.

page 7

Cmpt 214 Midterm Examination

October 21, 2014

When input to the shell, the file pathname . (as in ./ ) is used to denote

(a) the user's home directory.

(b) the root directory of the file system.

(c) the current working directory.

(d) None of the above.

What is the name of that portion of the operating system which provides only the minimum of services

necessary for implementing additional O/S services?

(a) X-Windows.

(b) The kernel.

(c) Root.

(d) A server.

(e) None of the above.

What type of entity can be organized according to “layers of abstraction”, where each layer defines an abstract machine?

(a) A GUI-based windowing system.

(b) An operating system.

(c) Software designed using TDD.

(d) A testing scaffold.

(e) None of the above.

How many processes in total are created by the shell to execute the following complex command? ls /etc/foobar ; date

(a) 1

(b) 2

(c) 3

(d) 4

(e) None of the above.

Which of the following commands can be used to search for all instances of the string “TESTING” in all files in the current working directory whose names start with the string “queen”, then contain a number between 0 and 99, and finally end with “.cc”.

(a) egrep TESTING 'queen[0-9][0-9]?.cc'

(b) egrep 'TESTING' queen[0-9].cc queen[0-9][0-9].cc

(c) egrep TESTING 'queen[0-9]{1,2}.cc'

(d) Any of the above.

What is the name of the “configuration file” for bash, a file of commands that are read and executed by bash when it starts and prior to prompting the user for input?

(a) .bashrc

(b) login

(c) .login

(d) /etc/config

(e) None of the above.

page 8

Cmpt 214 Midterm Examination October 21, 2014

26. What is the name of a program that you can use to obtain online documentation on tuxworld? (a) info

(b) man
(c) khelpcenter (d) All of the above.

D. (1 mark each, total 5 marks)

Consider the following LINUX commands (commands one could

give on a tuxworld machine via bash): ls
which whatis
whatis which

(a) ls -l

(b) ls -la

(c) df

(d) ps -u $USER

(e) du -s -m /usr/bin

(f) uptime

(g) (h) (i) (j) (k) (l)

Consider each portion of output below. Each was produced by one of the commands above. For each portion of output, write the letter label of the command which produced that output.

1. ____
15:50:15 up 7 days, 1:39, 20 users, load average: 0.02, 0.02, 0.05

____ which []

____
PID TTY

____ total 18

5. ____ /usr/bin/whatis

E. (1 mark each, total 12 marks)

Suppose that the file phone_directory.txt contains the following lines of information. Each line consists of 4 fields (columns) separated by single tab characters. The fields are obvious from viewing the layout of the file when it is printed on a terminal:

page 9

Cmpt 214 Midterm Examination

October 21, 2014

A Hacker B Ator
C Reasoner D BitDiddle E Fect

F Tweakit

We will refer to the above lines in phone_directory.txt by the letters A through F to the left of each line. For example, A refers the first line, while F refers to the final line. The labelling letters are not part of the lines of text in the file.
Below are commands (given to bash) that operate on phone_directory.txt. The commands may or may not produce any output. For each of the commands, enter the letter label (A–F) of the line in the file phone_directory.txt which originally contained the text which is output first. That is, for all the commands below, answer the question, “which of the above lines contains the text that first appears in response to the command?” For example, if a command first yields a line consisting of the text “Eva” from the second line in phone_directory.txt, you should enter “B” as the answer to the question (reflecting the fact that this text came from line “B” of phone_directory.txt). Additionally, if the command generates no output, enter “N”. Finally, if none of the answers A–F or N is correct, enter “X” as indicating “None of the above”.

grep 't' phone_directory.txt

grep 't>' phone_directory.txt

egrep '[0-9]{3}-[01]{3}-[01]{4}$' phone_directory.txt

egrep '.A?' phone_directory.txt

egrep '(^w).*' phone_directory.txt

egrep -v '^w+W+w+W+wW' phone_directory.txt

sort phone_directory.txt

cut -f 3 < phone_directory.txt | sort -r

cat <<< phone_directory.txt

rm -f a.txt; cat phone_directory.txt a.txt >b.txt 2>e.txt ; cat e.txt

rm -f a.txt; cat phone_directory.txt a.txt >b.txt 2>e.txt ; cat b.txt

sort phone_directory.txt > a.txt; date >> a.txt; cat a.txt

page 10

Cmpt 214 Midterm Examination October 21, 2014

F. (2+1+1+1+1+1+3 = 10 marks)

Answer each of the following questions with a technically-oriented answer. In some cases, a very short, pre- cise answer is in order. In others, a concise descriptive answer is required.

A programmer would like to make use of the system library function printf(3). The programmer knows that she will need to include a system “.h” file to be able to use printf(), but does not know ex- actly which one. What LINUX/UNIX command should the programmer use to obtain online information to determine the name of the system “.h” file to include? Give the complete command.

What is the (shell) filename wild-card character that will match one, and only one, arbitrary character?

What is the bash command involving the history buffer which causes the shell to repeat the immediately

previous command?

The following fragment of C/C++ exhibits poor programming style. Why? What is wrong with it?

The following fragment of C/C++ exhibits poor programming style. Why? What is wrong with it?

}

Consider the following piece of code. It is intended to declare the State datatype according to the pro- gramming guidelines given in class. Unfortunately, it does not in fact adhere to those guidelines. Why? What is wrong with it?

Explanation / Answer

1.Every complete C/C++ program has a function called main( ) function. It is the standard entry point

to the program.

2. Which of the following statements regarding good programming style is true?

(a) A user should preferentially use the layout

rather than

3..The “#ifdef” construct in C/C++ is an example of a preprocessor directive.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote