Sale!

CMPT 214 Lab 3 – Programming style and even more UNIX

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (4 votes)

Before starting this lab exercise, pay attention to the presentation by the lab instructor explaining the
operation of the cut(1), tr(1), and tar(1) commands, and giving some usage examples. Operation of these
commands is also discussed in the textbook by Sobell; see pages 766–768, 987–989, and 968–972, respectively.
Perform tasks 1 – 4 below in a virtual terminal window. For each task, copy-and-paste the contents of your
terminal window (including the commands that you typed, and any output produced by the commands
you gave) into a text file called lab3.txt. However, do not include extraneous or superfluous commands
or output; only include content relevant and essential to the specified task. Unless otherwise specified, all
commands should be run on tuxworld using the bash shell. Additionally, with a text editor, add to lab3.txt
your solution to questions 5 and 6 as well as text and identifying information to clearly distinguish
which commands/output/code correspond to each task or question. Submit lab3.txt through
moodle when done. This lab is out of a total of 11 marks, with each question (1, 2a, etc.) being worth one
mark. Marks may be docked for extraneous, irrelevant, or superfluous content. The submission is due at
11:55 p.m. on Thursday, September 29.
1. Use a UNIX command to find out the name of the server on which the files in /student are physically
stored. In your submission, also explicitly give what you think the name of that server is.
2. Create a subdirectory called 214lab3 in your home directory. Change your current working directory
to this new subdirectory. Use this directory when completing steps 2, 3, and 4.
(a) Create a directory called dir1 and a directory called dir2, both within 214lab3. Change your
current working directory to dir1. Then use a UNIX command to copy the file /etc/passwd to
dir2. In doing so, you must use a relative path, not an absolute path, to specify the destination
directory.
(b) Change your current working directory to be the 214lab3 directory you created at the outset.
Use a UNIX command to create a compressed tar saveset called dirs.tar.gz containing dir1
and dir2 (and all the files in those directories). Finally, using the echo command and output
redirection, create a text file in 214lab3 called favourite_movie.tar.gz containing the name of
a favourite movie. Do not be concerned that the filename does not end in .txt.
(c) Use a UNIX command to find out the file type of both dirs.tar.gz and favourite_movie.tar.gz.
3. (a) Place the output of the w command in the file wtemp.txt using output redirection. Then use a
UNIX command to put all but the first two lines of wtemp.txt into the file w.txt. Finally, output
the content of wtemp.txt and w.txt to your display.
(b) Use the UNIX/LINUX cut(1) command to show just the username column of w.txt. Since the
input file is space-delimited rather than tab-delimited, specify to cut(1) that it must use a space
1
character as its delimiter. You can specify a space character on the command line by enclosing it
in quotes.
(c) Use the tr command to read w.txt and replace all instances of multiple, consecutive space
characters by just one space. Have the output of this command go to the file w1.txt. Again, you
can specify a space character as an argument to tr by enclosing it in quotes on the command line.
(d) Use a UNIX command to display the contents of w1.txt with the lines sorted in decreasing
lexicographic order of the 5th column. You can assume that the default sorting criterion for
sort(1) is lexicographic.
4. Download the ancillary file for this lab named usernames.txt from the moodle pages for this lab.
Suppose that you wish to find out whether this file is already sorted in alphabetical order. The sort
command’s -c option allows you to check whether a file is already sorted; however, pretend for this
question that this option does not exist. Use some combination of sort (with no options) and diff to
find out whether the usernames in this file are already in alphabetical order. You will need to use more
than one command. You can also make use of a temporary file. However, try to use as few commands
as possible. Stop when you have sufficient information to make the decision and explicitly state that
decision in your lab3.txt file.
5. Rewrite the following code using better programming style as per the guidelines given in lecture.
char *line;
bool is_quote;

is_quote = ( *line == ’”’) ? true : false;
6. Rewrite the following code in a more idiomatic form.
i = 0;
while (i <= arraySize - 1) { array[i++] = 1; }