COMP(2041|9044) 22T2 — Week 05 Weekly Test Questions
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
COMP(2041|9044) 22T2 — Week 05 Weekly Test Questions
Week 05 Weekly Test Questions
Test Conditions
These questions must be completed under self-administered exam-like conditions. You must time the test yourself and ensure you comply with the conditions below.
You may complete this test in CSE labs or elsewhere using your own machine.
You may complete this test at any time before Week 7 Thursday 18º00º00.
Weekly tests are designed to act like a past paper - to give you an idea of how well you are progressing in the course, and what you need to work on. Many of the questions in weekly tests are from past final exams.
Once the first hour has finished, you must submit all questions you've worked on.
You should then take note of how far you got, which parts you didn't understand.
You may choose then to keep working and submit test question anytime up to Week 7 Thursday 18º00º00 However the maximum mark for any question you submit after the first hour will be 50%
You may access this language documentation while attempting this test:
manual entries, via the man command.
Texinfo pages, via the info command.
Bash documentation via the help command.
Python documentation via the python3 -c 'help()' command.
Any violation of the test conditions will results in a mark of zero for the entire weekly test component.
Set up for the test by creating a new directory called test05 and changing to this directory.
$ mkdir test05 $ cd test05 |
There are some provided files for this test which you can fetch with this command:
$ 2041 fetch test05 |
If you're not working at CSE, you can download the provided files as a zip file or a tar file.
Test Complete! Your time for this test has finished. You must submit your work now. You should reflect on how you went in this hour, and discuss with your tutor if you have concerns. You may choose to keep working, but the maximum mark for any questions you submit later will be 50%. |
Write a POSIX-compatible shell script, hello_files.sh which takes 2 arguments.
The first argument will be positive integer, n.
The second argument will be a string, name.
2022/7/12 15:57
COMP(2041|9044) 22T2 — Week 05 Weekly Test Questions
Your program should create n files.
The names of these files should be hello1.txt .. hello n .txt .
Each file should have the same contents, a single line: hello name
For example:
$ ls hello*.txt ls: cannot access 'hello*.txt': No such file or directory $ ./hello_files.sh 3 Andrew $ ls hello*.txt hello1.txt hello2.txt hello3.txt $ wc hello*.txt 1 2 13 hello1.txt 1 2 13 hello2.txt 1 2 13 hello3.txt 3 6 39 total $ cat hello1.txt hello Andrew $ cat hello2.txt hello Andrew $ cat hello3.txt hello Andrew $ ./hello_files.sh 100 Brittany $ ls hello*.txt|wc -l 100 $ cat hello100.txt hello Brittany $ cat hello42.txt hello Brittany $ cat hello1.txt hello Brittany |
are not permitted to use external programs such as grep , sort , uniq , .... In particular you are not permitted to use the external program: seq. You are permitted to use built-in shell arithmetic and other built-in shell features including: test while [ |
When you think your program is working you can autotest to run some simple automated tests:
$ 2041 autotest hello_files |
When you are finished working on this exercise you must submit your work by running give:
$ give cs2041 test05_hello_files hello_files.sh |
We what to know which of a set of files has the most lines.
Write a POSIX-compatible shell script most_lines.sh which given one of more filenames as argument, prints which file has the most lines.
For example
$ seq 1 5 >five_lines.txt $ cat five_lines.txt 1 2 3 4 5 $ seq 1 10 >ten_lines.txt $ seq 1 100 >hundred_lines.txt $ ./most_lines.sh ten_lines.txt hundred_lines.txt five_lines.txt hundred_lines.txt |
2022-07-13