This is the program requirements and the attached file is the java file they provided. I copy pasted it in docx. PROGRAM REQUIREMENTS The program will read all lines from a text (ascii) file using the facilities of fgets for C (see "man fgets"). The program should do exactly what graph.java does in the text appendix, except that you may (optionally) improve the appearance of the output. You should be able to get the entire java program, including all ADTs, libraries, whatever, from AppendixCode.tar in Handouts. Probably the Java program will run correctly with no changes. The above READING section tells you where to find documentation on what graph.java does. Trying to figure it out from the code only is not recommended. This assigned program will use data structures that are different from graph.java. Only the observable behavior is to be mimicked. Most of this handout is about how to go about the assignment. It does not repeat what is in the text appendix and other sections mentioned in READING above. It does not teach C. We recommend that you work directly on your C program, using the text and possibly the Java code as a guide to expected behavior. Do not try to convert from java line by line. We'll follow the C convention of lowercase file names, but type names will remain capitalized. Give your binary compiled C program the name graph01. Your main source file should be named graph01.c. Your source file that IMPLEMENTS the IntVec ADT should be named intVec.c. The ADT header file is intVec.h, supplied in the class locker, a directory named cmps101-avg. The complete path is given in the syllabus and on the class web page and later in this handout. The file standardVec.txt in Handouts/ and in the course locker describes how "vector" ADTs are usually implemented in C. (graph.java uses an IntList ADT, which is more flexible and simpler to implement, compared to the "vector" idea, but experience shows that the IntList approach is less efficient on modern hardware.) Reading input in C is trickier than it sounds, so don't wait too long to get started. As a C program, this is a pretty simple warm-up to get some routines in place that you will need later. Also, there is a lot to do besides write C code. ========================================================================== COMMAND-LINE ARGUMENTS If your program receives no command-line arguments, it should print a usage message on stderr using fprintf() and exit 0. Note that the Unix convention is that an exit code of 0 means "normal completion" and non-zero exit codes denote various errors. The exit code of 0 is established by "return 0" from main() or by calling exit(0) anywhere. Similarly, non-zero codes may be established. Command-line arguments of the form "-something" are often called "flags", and provide the means for varying the way the program runs, or varying the form of the output. ("-" by itself denotes stdin.) This assignment does not require flags. The final command-line argument is the name of the input file, and this name will not begin with a "-" unless it is "-" by itself. If the program has command-line arguments but cannot get the file name from the command line or cannot open the input file, then a non-zero exit code should be returned. ========================================================================== INPUT FORMAT Input consists of a sequence of lines on ``standard input'' or in an ascii file (also called text file). The line formats are as described in the text appendix for graph.java. Standard input is called stdin for C. stdin is of type FILE *. End-of-file signals the end of input, and is typed on the keyboard as cntl-D in Unix (Linux is Unix; maybe cntl-Z in DOS, Windows, etc.). Disk files do not need an End-of-file character, though. Part of the assignment is to create a set of useful test files on disk. We do NOT supply a thorough set of test files. In the course locker (see below) gr01_test1.in is an example input. It contains: 8 6 1 2.2 1 2 1.0 4 3 1 3 4 5 1.2 2 4 0.0 5 2 6 6 3 4 Line 1 has a single positive int (8 in this case) that tells you the input may contain vertices in the range 1-8 (not 0). Each subsequent line defines one directed edge. The first two ints are vertices usually named "from" and "to". The third number, if present, states the weight or cost of that edge. If there is no third number, the edge weight is 0.0. weights are doubles. ========================================================================== OUTPUT FORMAT Running graph.java on example inputs is the easiest way to see the expected output format. What is most important is that the correct NUMBERs in the correct sequence appear on each line. The punctuation like commas and brackets is for human readability. A common convention in programming languages is that lists print as [4, 5, 1] for a list whose first element is 4, etc. [] is the empty list. For this assignment the entire list should print on a single line. When you run graph.java you will notice that a number appears on each line BEFORE the list. That is explained in the reading material. When you run graph.java you will notice that weights do not appear in the output. For this assignment the weights are read if present, and stored temporarily, but are not stored in the permanent graph data structure. Later assignments will use weights. PRINT AN INFORMATIVE ERROR MESSAGE on stderr if the input contains a bad vertex number, outside 1,...,n, or has the wrong number of words on a line. This is for your own protection. It is not a grading issue and submitting a lot of tests to check bad input is not asked or desired,
and does not gain credit.
PROGRAM REQUIREMENTS This program (named graph02) will perform the same functions as pa01, plus some new functions, once the input graph is loaded. Give your binary compiled C program the name graph02. Your main source file should be named graph02.c. Your source file that IMPLEMENTS the IntVec ADT should be named intVec.c. The ADT header file is intVec.h, supplied in the class locker, a directory named cmps101-avg. The complete path is given in the syllabus and on the class web page and in ho04.txt. In this assignment, your intVec.o will be tested with other students' programs and their intVec.o will be tested with yours. So use the standard names in this class. A starter intVec.h is in the course locker, but you should replace the questions with your own comments. It is unchanged from pa01. graph01.c, etc., can be used right from pa01, except that the "main" procedure will be changed to check for some command-line flags and call different procedures depending on whether the input file is to be interpreted as a directed or undirected graph. Thus, the loadGraph functionality will be separated if it has not been separated in an earlier assignment. See HOW TO PROCEED below for more details. Allocating all the arrays in graph02.c makes it easier to pass them as arguments to functions in other files, without making any global arrays. However, if you already have working code that allocates and returns an array from a different file (such as loadGraph.c), it is okay to use and build upon that code. Aside from intVec.h, intVec.c, graph02.c and graph02, the names of files, functions and arrays should be understandable but
do not need to be strictly the same as this handout.


0 comments