student1.cpp
and student2.cpp
contain solutions to an assignment. You are provided with these solutions, a Makefile
to build the solutions and four test files test?
to check the correctness of the solutions. More information on running the program appears later in this assignment.
wget
on the linux side.
$ wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc2040/fall2023/assign/one/Makefile --2023-08-15 09:04:21-- https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc2040/fall2023/assign/one/Makefile Resolving mirkwood.cs.edinboro.edu (mirkwood.cs.edinboro.edu)... fe80::1132:c82c:e95e:5a8a, 147.64.242.52 Connecting to mirkwood.cs.edinboro.edu (mirkwood.cs.edinboro.edu)|fe80::1132:c82c:e95e:5a8a|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 406 [text/plain] Saving to: 'Makefile' Makefile 100%[===================>] 406 --.-KB/s in 0s 2023-08-15 09:04:22 (24.4 MB/s) - 'Makefile' saved [406/406]
Please note that downloading then uploading the files through a windows computer will potentially cause two problems.
ls
command. The output should look something like:
$ ls Makefile.txt student1.cpp student2.cpp test1 test2 test3 test4Note that Makefile has a .txt extension. If this is the case, you will want to rename the makefile. To do this:
mv Makefile.txt Makefile
mv
is the *nix command to rename a file, it is actually a move command.
mv oldfile newfile
man mv
for full details.
$ ls Makefile student1.cpp student2.cpp test1 test2 test3 test4Experiment with make to assure yourself that you are using the Makefile. Do the following, capture a screen shot of this activity.
mv Makefile Makefile.txt
ls
make
mv Makefile.txt Makefile
ls
make
Your output should look something like
[bennett@mirkwood work]$ mv Makefile Makefile.txt [bennett@mirkwood work]$ ls Makefile.txt student1.cpp student2.cpp test1 test2 test3 test4 [bennett@mirkwood work]$ make make: *** No targets specified and no makefile found. Stop. [bennett@mirkwood work]$ mv Makefile.txt Makefile [bennett@mirkwood work]$ ls Makefile student1.cpp student2.cpp test1 test2 test3 test4 [bennett@mirkwood work]$ make g++ -g -O2 -Wall -Wextra -Wpedantic -Werror --std=c++23 -Wnon-virtual-dtor -Wold-style-cast -Wunused-parameter -Wuninitialized -Winit-self -Wshadow -Wparentheses -Wdangling-else student1.cpp -o student1 g++ -g -O2 -Wall -Wextra -Wpedantic -Werror --std=c++23 -Wnon-virtual-dtor -Wold-style-cast -Wunused-parameter -Wuninitialized -Winit-self -Wshadow -Wparentheses -Wdangling-else student2.cpp -o student2Note that when Makefile.tex is present, it does not know how to build the executables. When Makefile is present, it builds the executables using a set of compiler flags.
Remember to take a screen shot of this, it should look something like:
Add this screen shot to a word document and label it appropriately.
Once you have completed this step, you should have executables student1
and student2
in your directory.
$student1 < test1 There were 5 letters. There were 1 spaces. There were 1 words. There were 1 lines. WC output: 1 1 6You can check the output from wc the same way:
$ wc < test1 1 1 6Make sure that you can run both programs with any input.
The makefile is set up to help you convert files between different os formats. Typing make dosFiles
will put the files in windows format.
[bennett@mirkwood work]$ make dosFiles unix2dos test1 unix2dos: converting file test1 to DOS format... unix2dos test2 unix2dos: converting file test2 to DOS format... unix2dos test3 unix2dos: converting file test3 to DOS format... unix2dos test4 unix2dos: converting file test4 to DOS format... [bennett@mirkwood work]$This runs the command
unix2dos
. See man unix2dos
for more details.
The easiest way to see the difference is via the od
command. od stands for octal dump, and this will print the octal values of the data stored in the file. od takes a command line argument -c which says to interpret the output as a character if possible. See man od
for full details.
After you have converted the files to dos format, run od on test2. (od -c test2
. Note the \r\n at the end of each line.
[bennett@mirkwood work]$ cat test2 hello world this is a test! [bennett@mirkwood work]$ od -c test2 0000000 h e l l o w o r l d \r 0000020 \n \r \n t h i s i 0000040 s a t e s t ! \r \n 0000053Note, the number at the beginning is the offset into the file, in hex.
After you have done this, run student1 with test2 as the input. (student1 < test2
. Note no blank lines were detected. Why was this? Add an entry to your word document that describes what happened to cause the blank line identification to fail. (IE is the input really an empty string on line 22?).
Convert the files back to unix format by running make unixFiles
. You could also run dos2unix one each file by hand ( dos2unix test2
). Use od to look at the file and assure yourself that \r has been removed from the end of each line. Run student1 on test2 and notice that it correctly identifies the blank line.
Add a screen shot of the following steps
make dosFiles
od -c test4
student1 < test4
make unixFiles
od -c test4
student1 < test4
make clean
to remove all executables and object files.
tar cvzf homework1.tgz homework1
.
homework1.tgz
follows the f. This is somewhat backwards from other unix commands.
homework1
is the name of the directory you wish to compress.
You can also do this with winscp, and probably with visual studio code. I am not covering these methods. However any method is acceptable that produces a proper .tgz file.
Do the following, make a screen shot of the result. Add the screen shot to your word document.
ls
tar cvzf homework1.tgz homework1
ls
tar tf homework1.tgz
.
This should show the contents of the file.
If you would like to extract the contents
tar xvzf homework1.tgz
homework1
, which contains your files.
If you do not include the 'g' argument, just name your file homework1.tar, .tgz indicates that the archive has been compressed with gzip.
If you want more information about tar, try man tar