COSC 4377 - Introduction to Computer NetworksSpring 2012MW 1:00-2:30pm at PGH347
Pre-requisitesThe 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.
Homework 0Due: January 18, 2012Write 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 10and here is the content of the file anotherfile.txt: 5 3 2 12 8 10 1 1 4If we run your program like this: ./combine-files myfilea.txt anotherfile.txt myoutput.txtyour 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 10You 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 SubmissionYou 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). |