Starting from:

$24.99

COMP9044 Final Exam Questions Solution

Exam Conditions
You are not permitted to communicate (email, phone, message, talk, …) with anyone during this exam, except COMP(2041|9044) staff via cs2041.exam@cse.unsw.edu.au
You are not permitted to get help from anyone but COMP(2041|9044) staff during this exam.
This is a closed book exam.
You are not permitted to access papers or books.
You are not permitted to access files on your computer or other computers, except the files for the exam.
You are not permitted to access web pages or other internet resources, except the web pages for the exam and the online language cheatsheets & documentation linked below
Even after you finish the exam, on the day of the exam,on the day of the exam do not communicate your exam answers to anyone . Some students have extended time to complete the exam.
Do not place your exam work in any location, including file sharing services such as Dropbox or GitHub, accessible to any other person.
Ensure during the exam no other person in your household can access your work.
Your zpass should not be disclosed to any other person. If you have disclosed your zpass, you should change it immediately.
Deliberate violation of exam conditions will be referred to Student Integrity as serious misconduct
Exam Structure
There are 12 questions on this exam.
Total mark of questions on this exam is 100.
Questions are NOT worth equal marks.
All 12 questions are practical (programming) questions.
Answer each question in a SEPARATE file. Each question specifies the name of the file to use. These are named after the corresponding question number, Make sure you use EXACTLY this file name.
You can verify what submissions you have made with 2041 classrun -check final_q<N>
Language Documentation
manual entries via the man command
Texinfo pages via the info command
Perl documentation via the perldoc command
Bash documentation via the help command
Marking
No marks are awarded for style - but use reasonable formatting so the marker can read your answer.
No marks awarded are awarded for commenting - but you can leave comments for the marker.
Passing autotests does not guarantee marks. Your code will be run on tests you haven't seen - do you own testing. Failing autotests does not prevent marks - a human marker will read your code and give marks based on how much of the problem you have solved.
Troubleshooting
If you are having issues working on the exam at CSE, please follow these steps
If the problem persists, try using SSH instead: instructions here or here
If you're using VSCode: Try disconnecting from VSCode, then changing the URL from vscode.cse.unsw.edu.au to vscode2.cse.unsw.edu.au.
If you're using SSH: try disconnecting and reconnecting.
If the problem persists, try using vlab instead: instructions here
If things continue to not work, contact the exam email: cs2041.exam@cse.unsw.edu.au.
If you have a problem that can't be fixed and you can't complete the exam, you should apply for special consideration.
This will require evidence of the problem. Take screenshots documenting the problem, for example:
error messages screen not loading timestamped speed tests power outage maps messages or information from your internet provider regarding the issues experienced
But you must also still get in touch with course staff via cs2041.exam@cse.unsw.edu.au as soon as it is clear the issue can not be fixed.
Special Considerations
This exam is covered by UNSW's Fit-to-Sit policy. That means that by sitting this exam, you are declaring yourself well enough to do so. You will be unable to apply for special consideration after the exam for circumstances affecting you before it began. If you have questions, or you feel unable to complete the exam, contact cs2041.exam@cse.unsw.edu.au
Getting Started
Set up for the exam by creating a new directory called exam_final, changing to this directory, and fetching the provided code by running these commands:
$ mkdir -m 700 exam_final
$ cd exam_final
$ 2041 fetch exam_final
Or you can download the provided code as a zip file or a tar file.
If you make a mistake and need a new copy of a particular file you can do the following:
$ rm broken-file
$ 2041 fetch exam_final
Only files that don't exist will be recreated, all other files will remain untouched

We have student enrolment data in this familiar format:
$ cat enrollments.txt
COMP1917|3360379|Costner, Kevin Augustus |3978/1|M
COMP1917|3364562|Carey, Mary |3711/1|M
COMP3311|3383025|Thorpe, Ian Augustus |3978/3|M
COMP2920|3860448|Steenburgen, Mary Nell |3978/3|F
COMP1927|3360582|Neeson, Liam |3711/2|M
COMP3141|3383025|Thorpe, Ian Augustus |3978/3|M
COMP3331|3383025|Thorpe, Ian Augustus |3978/3|M
COMP2041|3860448|Steenburgen, Mary Nell |3978/3|F
COMP2041|3360582|Neeson, Liam |3711/2|M
COMP3311|3711611|Klum, Mary |3978/3|F
COMP3311|3371161|Thorpe, Ian Fredrick |3711/3|M
COMP3331|5122456|Wang, Wei |3978/2|M
COMP3331|5456732|Wang, Wei |3648/3|M
COMP4920|5456732|Wang, Wei |3648/3|M

You should find a copy of the above data in the provided file enrollments.txt.
In final_q1.sh, write a shell pipeline that, given student enrollment data in the above format, will output the number of course enrollments by students in the program 3711.

Only one line, the number of course enrollments by 3711 students, should be printed.
For example, given the above data, your pipeline should output this:
$ ./final_q1.sh < enrollments.txt
4
Using the aditional data file provided, your pipeline should output this:
$ ./final_q1.sh < more_enrollments.txt
18

No error checking is necessary.



Write a Perl program final_q2.pl that performs the same task as the Shell pipeline in the previous question.
In other words:
Given data in the same format as the last questions,
Outputs the number of course enrollments by students in the program 3711.

Only one line, the number of course enrollments by 3711 students, should be printed.
For example final_q2.pl should output this:
$ ./final_q2.pl < enrollments.txt
4
$ ./final_q2.pl < more_enrollments.txt



Write a POSIX-compatible Shell script final_q3.sh that lists all the happy directories in the currect directory.
A happy directory is a directory that itself contains 2 or more files or directories.
For example:
$ mkdir empty hello goodbye numbers
$ echo "hi there" > hello/file
$ echo "bye" > goodbye/english
$ echo "adios" > goodbye/spanish
$ touch numbers/1 numbers/2 numbers/3 numbers/4
$ ls empty $ ls hello file
$ ls goodbye english spanish
$ ls numbers
1 2 3 4 $ ./final_q3.sh goodbye numbers

A directory is only happy if it in and of itself contains 2 or more files or directories.
For example (continuing from the previous example):
$ mkdir d
$ mkdir d/e
$ touch d/e/file1 d/e/file2 d/e/file3
$ ls d e $ ls d/e file1 file2 file3 $ ./final_q3.sh goodbye numbers $ mkdir d/f $ ls d e f
$ ./final_q3.sh d goodbye numbers





Write a POSIX-compatible Shell script final_q4.sh which takes 2 arguments.
The first argument will contain exactly one positive integer n as a substring of a larger string.
Your program should print the equivalent strings, one per line, containing the integers n .. m.
You can assume n ≤ m.
Your program must produce exactly the same output as below.
$ ./final_q4.sh aaa723bbb aaa727bbb aaa723bbb aaa724bbb aaa725bbb aaa726bbb aaa727bbb
$ ./final_q4.sh bell11 bell15 bell11 bell12 bell13 bell14 bell15
$ ./final_q4.sh 6th 9th
6th
7th
8th
9th
$ ./final_q4.sh 13 14
13
14
$ ./final_q4.sh ans42er ans42er ans42er





Write a POSIX-compatible Shell script final_q5.sh that can be used to make daily copies of the logging output of a server.
Assume that the script is run in a directory possibly containing files with the names:
log, log.1, log.2, log.3, log.4, log.5, log.6 And possibly a sub-directory called archive
The file log contains server logging output from the past 24 hours.
The file log.1 contains server access information from yesterday (if it exists).
The file log.2 contains server access information from two days ago (if it exists).
...
The file log.6 contains server access information from six days ago (if it exists).
When your program is executed it should do the following:
If the file log.6 exists, it should be compressed using the gzip command.
If the sub-directory archive does not exist, it should be created.
All the other log files, if they exist, should have the names updated (shifted):
If log.5 exists, it should be renamed log.6
If log.4 exists, it should be renamed log.5
...
If log exists, it should be renamed log.1 For example:
$ rm -rf archive
$ rm -f log*
$ ls log*
$ echo "selamat" > log
$ ls log* log $ cat log selamat
$ ./final_q5.sh $ ls log* log.1 $ cat log.1 selamat
$ echo "hello" > log
$ ./final_q5.sh $ cat log.2 selamat $ cat log.1 hello
$ echo "namaste" > log
$ ./final_q5.sh
$ echo "hola" > log
$ ./final_q5.sh
$ echo "bonjour" > log
$ ./final_q5.sh
$ echo "guten tag" > log
$ ./final_q5.sh $ ls log* log.1 log.2 log.3 log.4 log.5 log.6
$ echo "ni hao" > log
$ ./final_q5.sh
$ zcat archive/log.2021_05_06.gz selamat $ cat log.1 ni hao $ cat log.6 hello





We have student enrolment data in this familiar format:
$ cat final_q6.0.txt
COMP2511|3713452|Ahmad, Warren |3645/2|M
COMP1711|3819596|Hernando, Justin Yeong |3979/1|M
COMP1511|3953441|Noble, Albert Ka Chuen |4075/3|F
COMP1521|3487324|Goolam, Mohammad |3643/2|M
COMP9901|3857456|Tinoco, Ling Ling Rachel |2665|F
COMP9902|3407207|Rhee, Paul Myung-Won |1650|F
COMP4001|3916726|Kota, Tsz Kin |8685/1|M
Names in this data are in the form: Last Name, First Names
We need to translate names to the form: First Names Last Name Any trailing whitespace after the Names should be preserved.
Write a Perl program final_q6.pl thatgiven student enrollment data in the above format from standard input, writes to standard output with the names changed to the form: First Names Last Name Your program must produce exactly the same output as below.
$ ./final_q6.pl <final_q6.0.txt
COMP2511|3713452|Warren Ahmad |3645/2|M
COMP1711|3819596|Justin Yeong Hernando |3979/1|M
COMP1511|3953441|Albert Ka Chuen Noble |4075/3|F
COMP1521|3487324|Mohammad Goolam |3643/2|M
COMP9901|3857456|Ling Ling Rachel Tinoco |2665|F
COMP9902|3407207|Paul Myung-Won Rhee |1650|F
COMP4001|3916726|Tsz Kin Kota |8685/1|M





We need a summary of commits that have been to made to a git repository.
The authors should be listed in decreasing order of numbers of commits.
If authors have made an equal number of commits they should be listed in reverse alphabetical order.
Your program must produce exactly the same output as below.
$ ./final_q7.sh
./final_q7.sh: Not a git repository
$ unzip small_repo.zip ...
$ cd small_repo
$ ../final_q7.sh
1 Linus Torvalds
1 Dylan Brotherston
1 Alan Turing $ cd ..
$ unzip large_repo.zip ...
$ cd large_repo
$ ../final_q7.sh
114 John von Neumann
110 Dennis Ritchie
106 Linus Torvalds
105 Joseph Carl Robnett Licklider
103 James Gosling
102 Brian Kernighan
98 Tim Berners-Lee
93 Alan Turing
91 Woz
78 John McCarthy $ cd ..
$ unzip empty_repo.zip ...
$ cd empty_repo
$ ../final_q7.sh
../final_q7.sh: No Commits





We have a download of Triple J Hottest 100 data in this format
poll|position|artist|track
We wish to extract the top 10 songs of each year, along with the artist.
Write a sed script final_q8.sed that given input in above format: prints top 10 songs in the format below.
Note, the first and last lines of the data are a header and a footer and should be ignored.
Note, we only want top 10 songs of each year. If the poll field is not a year, the song should be ignored. i.e. polls that are not 4 digits should be ignored.
If the position field is not 1..10, the song should be ignored. i.e. positions that are greater than 10 should be ignored.
Your script will be run with sed -r.
This provides extended regular expressions, and is what we used in assignment 2.
Your script must produce exactly the same output as below.
$ sed -r -f final_q8.sed 2020_only.txt
Heat Waves - Glass Animals
Booster Seat - Spacey Jane
The Difference [Ft. Toro y Moi] - Flume
Cherub - Ball Park Music
Lost In Yesterday - Tame Impala
WAP [Ft. Megan Thee Stallion] - Cardi B
Hyperfine - G Flip
Sending Me Ur Loving - The Jungle Giants
I'm Good? - Hilltop Hoods
Therefore I Am - Billie Eilish
$ sed -r -f final_q8.sed top_decade_list.txt | tail
Big Jet Plane - Angus & Julia Stone
Rock It - Little Red
Dance the Way I Feel - Ou Est Le Swimming Pool
Plans - Birds of Tokyo
Fall at Your Feet - Boy & Bear
Teenage Crime - Adrian Lux
Fuck You! - Cee-Lo Green
Tokyo (Vampires & Wolves) - The Wombats
Magic Fountain - Art vs Science
Somebody to Love Me {ft. Boy George & Andrew Wyatt} - Mark Ronson & The Business Intl.
$ sed -r -f final_q8.sed top20_list.txt | tail
Asshole - Denis Leary
Creep - Radiohead
Linger - The Cranberries
No Rain - Blind Melon
Cannonball - The Breeders
Killing in the Name - Rage Against the Machine
Lemon - U2
Go - Pearl Jam
The Honeymoon Is Over - The Cruel Sea
Stone Me into the Groove - Atomic Swing
$ sed -r -f final_q8.sed master_list.txt | tail
Asshole - Denis Leary
Creep - Radiohead
Linger - The Cranberries
No Rain - Blind Melon
Cannonball - The Breeders
Killing in the Name - Rage Against the Machine
Lemon - U2
Go - Pearl Jam
The Honeymoon Is Over - The Cruel Sea
Stone Me into the Groove - Atomic Swing




Write a program final_q9.pl that copies its standard input to its standard output processing embedded commands as described below.
Strings of the form <pathname> should be replaced with the contents of the file named pathname.
Strings of the form <!command> should be replaced by the output of running command as a shell command.

$ cat final_q9.0.txt contents of an example file
$ ./final_q9.pl < final_q9.0.txt contents of an example file $ pwd
/home/andrewt
$ echo '<!pwd>' | ./final_q9.pl
/home/andrewt
$ echo '<final_q9.0.txt>' | ./final_q9.pl contents of an example file
$ cat final_q9.1.txt
Hello, <!whoami> You are in the </etc/timezone>timezone.
$ ./final_q9.pl < final_q9.1.txt
Hello, andrewt
You are in the Australia/Sydney timezone.
Tue Jan 16:14:07 2038 AEDT
$ cat final_q9.2.txt
1 empty file's contents: </dev/null> 3 empty files:
</dev/null> </dev/null> </dev/null> /bin/true prints nothing:
<!/bin/true> Some commands print <!echo -n no> newlines.
Here is <!echo final_q9.1.txt>
<final_q9.1.txt>
>>> The end. <<<<
Tue Jan 16:14:07 2038 AEDT
Tue Jan 16:14:07 2038 AEDT
1 empty file's contents:
3 empty files:
/bin/true prints nothing:
Some commands print no newlines.
Here is final_q9.1.txt
Hello, <!whoami> You are in the </etc/timezone>timezone.
>>> The end. <<<<





An equi-group is a set of words, each containing exactly the same letters.
The words in an equi-group must contain exactly the same letters occurring the same number of times.
Note: all the words in an equi-group must be exactly the same length.
For example:
danger and garden are in the same equi-group but reset belongs in a different equi-group to rests.
Write a Perl program final_q10.pl which reads lines from standard input until it reaches end-of-input.
Your program will be given lowercase words (only the characters [a-z]), one per line, as input. The words will be in alphabetical order.
Your program should print all the equi-groups for these words. Each equi-group should be printed on a separate line.
The line should start with the number of words in the equi-group,
Then the words in the equi-group should be printed in alphabetic order, space-separated.
The equi-groups should be printed in descending order of size (the number of words in the group).
If two or more equi-groups have the same number of words in the group then order them alphabetically.
Note every word in the file will be printed exactly once.
You have been given 3 test data files containing words: words.tiny.txt, words.small.txt and words.medium.txt.
They contain respectively 16, 73 & 10000 words.
Your program must print all equi-groups in under 30 seconds for words.medium.txt.
Make your program behave exactly as indicated by the examples below.

$ ./final_q10.pl < words.tiny.txt
5 caret carte cater crate trace
4 abet bate beat beta
4 ate eat eta tea
1 booster
1 coastal
1 coasted
1 displayed
1 posting
1 roasted
1 roaster
1 rooster
1 singleton
1 undisplayed
$ ./final_q10.pl < words.small.txt
7 pares parse pears rapes reaps spare spear
6 caret cater crate react recta trace
5 bares baser bears braes saber
5 lapse leaps pales peals pleas
5 least slate stale steal tales
5 mates meats steam tames teams
4 abets baste beast beats
4 abler baler blare blear
4 acres cares races scare
4 arced cared cedar raced
3 adder dared dread
3 agers gears rages
3 aimed amide media
3 alert alter later
2 abode adobe
2 abuse beaus
2 aches chase
2 adept taped
1 aback
1 abaft
1 abase
1 abash
$ ./final_q10.pl < words.medium.txt | head
7 pares parse pears rapes reaps spare spear 6 caret cater crate react recta trace
6 caster caters crates reacts recast traces
6 opts post pots spot stop tops
5 alerting altering integral relating triangle
5 arrest rarest raster raters starer 5 bares baser bears braes saber
5 drapes parsed rasped spared spread
5 drawer redraw reward warder warred
5 east eats sate seat teas
$ ./final_q10.pl < words.medium.txt | tail
1 yardstick
1 yearning
1 yell
1 yields
1 yon
1 you
1 youngest
1 yourself
1 zone 1 zones
$





A onesie is a pair of words that differ in exactly one letter; for example, "toast" and "roast" or "pink" and "punk" or "shell" and "shelf".
Write a Perl program final_q11.pl which takes three arguments.
The first argument will be the name of a file containing lowercase words (only the characters [a-z]), one per line.
The second and third arguments will be two words of equal length.
Both words will occur in the file.
Your program should then print the shortest sequence of onesies connecting the first word to the second, such that all words are found in the file.
You have been given a file named words.large.txt containing about 30000 words.
Your program must be able to find the shortest sequences of onesies in under 60 seconds in words.large.txt.
To assist your debugging, you have three shorter files of words, words.tiny.txt, words.small.txt and words.medium.txt.
Match the output format below exactly.

$ ./final_q11.pl words.tiny.txt booster roasted booster rooster roaster roasted
$ ./final_q11.pl words.tiny.txt coastal posting
No solution
$ ./final_q11.pl words.small.txt bears meats bears beats meats
$ ./final_q11.pl words.medium.txt cat dog cat car tar tan ton don dog
$ ./final_q11.pl words.large.txt ape man ape apt opt oat mat man
$ ./final_q11.pl words.large.txt live dead live rive ride rede redd read dead
$ ./final_q11.pl words.large.txt shell files shell spell spill spiel spied shied shred sired fired filed files




Votes can now vote for prime minister by email.
Write a POSIX-compatible Shell script final_q12.sh which given the emails from voters prints which candidate has won the election.
Your program will be given as its first argument, a file containing the names of the candidates one per line. This file will contain no other lines and there will be no leading or trailing white space.
The remaining arguments to your program will be the names of files each containg a single email from a voter.
For example, the candidates file might have these contents:
Adam Bandt
Anthony Albanese
Penny Wong
Scott Morrison
And the email from a voter might contain:
From: Andrew Taylor <andrewt@unsw.edu.au>
To: votes@elections.gov.au
Subject: vote
Anthony Albanese
Adam Bandt
Penny Wong
Scott Morrison
Thanks for counting my vote, Andrew
Or:
From: Andrew Taylor <andrewt@cse.unsw.edu.au> To: votes@elections.gov.au
Subject: vote My first choice is
scott MORRISON adambandt anthony albanese # I don't like Penny!
PeNNy WonG
:wq
For an email to be a valid vote:
The email must contain the names of all candidates, listed in the order of the voter's choice.
Every candidate's name must be listed once, and only once, in the email. A vote is not valid if any candidate's name is missing, or if any candidate's name is listed more than once.
Each candidate's name must appear on line by itself in the email with no other characters except for white space.
Candidate names must be spelt in the email exactly as spelt in the candidates files, except for differences in case and white space.
For example, if the candidates file contains "Malcolm Turnbull", a valid vote might contain " malcolmturnBULL ".
Your program should print a message, following the format in the example below exactly, for each invalid vote. It should otherwise ignore invalid votes. Invalid votes are not counted in any way.
The voting system requires that voters rank all the candidates in order of choice. Initially the first choices are counted, and if one candidate receives more than 50% of the first choices on valid votes, then that candidate is elected.
If no candidate receives more than 50% of the votes, instead the candidate who received fewest votes is eliminated from the election.
If several candidates are tied for the lowest number of votes, they are all eliminated.
After candidate(s) is/are eliminated, any votes for these candidate(s) go instead to the voter's next choice - the next candidate listed in their email who has not already been eliminated .
This process of eliminating the weakest candidate(s) and recounting the votes continues until one candidate receives more than 50% of the vote, or until all remaining candidates are tied.
Your program should print a single line containing the name of the winning candidate. If there is a tie for winner, the names of all candidates who are tied shoudl be printed in alphabetic order.
Your program should produce no other output.
For example:
$ ./final_q12.sh candidates.txt email01.txt
Anthony Albanese
$ ./final_q12.sh candidates.txt email01.txt email02.txt email03.txt email04.txt email02.txt is not a valid vote
Scott Morrison
$ ./final_q12.sh candidates.txt email01.txt email02.txt email03.txt email04.txt email05.txt email06.txt email07.txt email02.txt is not a valid vote email07.txt is not a valid vote
Scott Morrison
$ ./final_q12.sh candidates.txt email05.txt email06.txt email07.txt email08.txt email09.txt email07.txt is not a valid vote
Adam Bandt
Anthony Albanese
Penny Wong
Scott Morrison
$ ./final_q12.sh candidates.txt email01.txt email02.txt email03.txt email04.txt email05.txt email06.txt email07.txt email08.txt email09.txt email02.txt is not a valid vote email07.txt is not a valid vote
Anthony Albanese
$ ./final_q12.sh candidates.txt candidates.txt email01.txt email02.txt email03.txt email04.txt email05.txt email06.txt email07.txt email08.txt email09.txt email10.txt email02.txt is not a valid vote email07.txt is not a valid vote
Adam Bandt
Anthony Albanese
Scott Morrison





When you are finished working on a question, submit your work by running give.
You can run give multiple times. Only your last submission will be marked.
Don't submit any questions you haven't attempted.
You can check if you have made a submission with 2041 classrun -check final_q<N>:
$ 2041 classrun -check final_q1
$ 2041 classrun -check final_q2 ...
$ 2041 classrun -check final_q12
Do your own testing as well as running autotest

For all enquiries, please email the class account at cs2041@cse.unsw.edu.au
CRICOS Provider 00098G

More products