COSC 4377 - Introduction to Computer Networks

Spring 2012

MW 1:00-2:30pm at PGH347

InstructorOmprakash Gnawali

Pre-requisites

The course description lists COSC 2320 and COSC 2410 as the pre-requisites for this course. If you did well in these courses, you are ready for this course. It is still helpful if you have taken one or two other courses in which you had to spend some time programming the assignments or projects. If you are still struggling with basic programming concepts, it might be best to wait until next time this course is offered. COSC 4377 is not a software engineering course but we will write a lot of code because many networking concepts are best explored and understood by designing and writing programs.

How to prepare for the course?

Here are some advice that will help you prepare as well as decide if you should take this course.
  • We will use the C programming language for most of our programming assignments. If you are familiar with C, you are all set. It is possible that some of us do not have prior C programming experience. That is fine as long as you are familiar with another programming language and willing to learn C quickly. We will provide enough resources and help to get you started.
  • We will use the Linux operating system as the platform on which we will do our assignments and projects. Most of us might not be familiar with Linux. There will be adequate resources and tips to get you setup but if you feel brave, you can install Ubuntu on your machine or set it up using a virtual machine tool to get a head start. We will also set you up with an account on a Linux machine maintained by the department.
  • We will write several small programs and 1-2 large projects in this course. If you are taking other courses with a lot of programming assignments or projects, you should make sure you have allocated sufficient time for this course. You will spend a non-trivial fraction of your time writing code.
  • Programming proficiency: We do not expect you to be expert programmers. But it is essential that you are comfortable writing basic programs, debugging them, and compiling and running them. Best way to determine if you have sufficient programming experience is by doing homework 0. If you don't already have the experience, and are still motivated to take this course, it will give you a good idea of where you need to be in terms of programming skills by the end of the first week of classes. If HW0 takes more than three hours to complete, you should spend the time between now and the first week of classes brushing up your programming skills and are still unsure by the beginning of the semester, please talk to the instructor.

Homework 0

Due: January 18, 2012

Write a C or C++ program (lets call it combine-files) that accepts three command line arguments: file1, file2, and file3. The program will merge the contents of file1 and file2 and outputs the merged content to file3. Here is how the merge works. The program reads the content of file1 and file2. File1 and file2 are text files with one integer per line. If the sum of all the integers in file1 is smaller than the sum of all the integers in file2, the program should output the content of file1 followed by the content of file2 to file3. If the sum of all the integers in file2 is smaller than the sum of all the integers in file1, the program should output the content of file2 followed by the content of file1 to file3. The following example will make it more clear what we are trying to do.

Lets say, this is the content of the file called myfilea.txt:

10
20
10
10
and here is the content of the file anotherfile.txt:
5
3
2
12
8
10
1
1
4
If we run your program like this:
./combine-files myfilea.txt anotherfile.txt myoutput.txt
your program should first read myfilea.txt, and compute the sum of all the integers in that file. For this file, the sum is 50. It will read the content of the second file (anotherfile.txt) and compute the sum of all the integers in that file, which is 46. Then, the program will create a file called myoutput.txt and output the following content to that file:
5
3
2
12
8
10
1
1
4
10
20
10
10
You will notice that the content of the output file starts with the content of the second input file followed by the content of the first input file. This is because the sum of all the numbers in the second file (46) is smaller than the sum of all the numbers in the first file (50).

There are many ways to write this program and we do not require a specific style or algorithm as long as you write your program in C or C++. We do require that you read the input files just once. That means your program should not open a file, read the content, close it, open the same file later, read it, etc. Then you might ask, what to do if you need the content of a file after closing it? In that case, you might consider storing the content in memory (array, etc.) so that you have the content without having to re-read from the file.

HW0 Submission

You should submit a single file, the source code. No need to submit the binary. Please submit your source code through Blackboard. Please include a few lines of comments at the top of your file describing how to compile your file and if there is anything unusual about your implementation (e.g., it does not work with certain inputs).