Homework 1, Let's get this straightened out.

Short Description:

Make sure you know how to download, compile and submit homework. Oh and by the way, find my bug.

Goals

When you finish this homework, you should have:

Formal Description

Download the following files to your work environment. The files 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.

Downloading the files

Download the files as you normally would. (Any of the following or more)

Uploading the files

On the linux side, create a directory to store these files. Further instructions will assume that this directory is called homework1. If you are not sure how to do this, check with your instructor. Upload the files to the directory you created.

Please note that downloading then uploading the files through a windows computer will potentially cause two problems.

  1. Makefile has no extension,
    1. Windows will make this Makefile.txt.
    2. This is not the valid name for this file on the linux side.
  2. Some download software will convert the text files (test*) from linux to windows format.
    1. This will also happen with files created on the windows side.
    2. Once again, this is not what you want on the linux side.

Fixing the Makefile problem

On the linux side, run the ls command. The output should look something like:
$ ls
Makefile.txt  student1.cpp  student2.cpp  test1  test2  test3  test4
Note 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

After the move ls should produce:
$ ls
Makefile student1.cpp  student2.cpp  test1  test2  test3  test4
Experiment with make to assure yourself that you are using the Makefile. Do the following, capture a screen shot of this activity.
  1. mv Makefile Makefile.txt
  2. ls
  3. make
  4. mv Makefile.txt Makefile
  5. ls
  6. make
You only need to do step 1 if the file is not named Makefile.txt.

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 student2
Note 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.

The assignment the programs answer.

The assignment is to read a file from standard input and count the number of letters, spaces, words and lines. While processing the file, the program should print out any time a completely blank line occurs. Finally, the program should print out a line equivalent to the output for wc from that file. To run the program, you need to use I/O redirection. See the example below:
$student1 < test1
There were 5 letters.
There were 1 spaces.
There were 1 words.
There were 1 lines.

WC output: 1 1 6
You can check the output from wc the same way:
$ wc < test1
1 1 6
Make sure that you can run both programs with any input.

The file format problem

Text files in *nix have each line end with a \n. In windows lines end with a \r\n. This is just one basic difference in how the operating systems work.

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
0000053
Note, 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

  1. make dosFiles
  2. od -c test4
  3. student1 < test4
  4. make unixFiles
  5. od -c test4
  6. student1 < test4
Add this screen shot to your word document. It should look something like:

One more programming task.

Note that student2 has a bug: Find this bug, fix it and note in your document what you did to accomplish this. Raid, which kills bugs dead dead, might be helpful. (This is an attempt at a hint with some humor, there is no helpful program raid in this case, it is a product which kills bugs dead dead.)

Creating a .tar file

Tar files are the standard *nix way of sending multiple files as one. There are several ways to make a tar file. You may use any method you wish, but you must be able to create a tar file.

You can check the contents of a tar file by:

tar tf homework1.tgz.

This should show the contents of the file.

If you would like to extract the contents

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

Finishing up

Make sure that your word document contains
  1. Your identifying information
  2. The three screen shots, appropriately labeled
    1. Renaming and using the Makefile
    2. Converting files between dos and unix formats
    3. Creating a tar file.
  3. The answer to why student1's code does not work with files in dos format.
  4. The answer to why student2's code is wrong.
  5. Any questions, comments, or concerned relating to this homework.
Put your word document in your homework directory and recreate the tar file.

Required Files

A single tar file containing the source code, makefile, and word documentation for this program.

Submission

Submit the assignment to the D2L folder Homework 1 by the due date.