Starting from:

$30

CSE102-Assignment 5 Solved

This is a C programming assignment. You will write a C program according to the following description.


•     Files to read: input.txt

•     Files to create: output.txt

•     stdout: Do not print anything.

•     Your program will read a file named input.txt

•     input.txt contains single line text. The text describes a tree structure. It follows the Newick format rules.

–    Each node is represented by a string (A string which does not include these chars: (, ), , ). They are separated by comma. Branching is described by matching parentheses.

–    The length of the text will not be greater than 250. – A string representing a node may have spaces in it.

–    A string representing a node cannot be an empty string.

–    You don’t have to check for any errors. The given string will be a true Newick format description of a tree.

–    There may be repetitions.

–    Ignore spaces at the beginning and at the end of the input string. (Do not ignore spaces at any other places).

–    The maximum length of a node name is 10 chars.

•     output.txt contains the visualization of the tree.

•     Below is an example of a tree description:

(Ali,(c,Beee,ec ee),K,Dayi,e,(f,(d,Ali)))

•     This tree can be visualized as follows:

-Ali --c

--Beee

--ec ee

-K

-Dayi -e

--f

---d

---Ali

•     Another example:

            (A,(A        ,           A,(A),           A ),         A)

•     Visualization (Do not print the explanations which are in ""):

-A

--A  "This node name has 3 spaces at the end." --               A      "This node name has 4 spaces before `A`."

---A

          --       A                                               "This node name has 3 spaces before `A`, and 2 spaces after."

          -       A                                                  "This node name has 3 spaces before `A`."

•     Another example:

A,(A,A,(A),A),A

•     Visualization:

A

-A -A

--A

-A A

•     Your program will read the simplified Newick formatted tree description from a file and write the visualization of the described tree to output.txt.

•     Core part of your implementation (parsing and printing) should utilize recursion otherwise you will get 0pts.

•     Pay attention to the structure of the output. Don’t print any debug messages or greeting texts. Don’t add extra spaces, newlines, line numbers, commas etc...

Remarks:

•     Please test your code extensively. Try limit values, extreme cases. For example:

– What happens if the input file has this: A ? This tree has a single node. The output should be A. – What about this input?: (((A))) The visualization should be ---A.

•     You don’t have to do error checking on the input file. You can safely assume that you will be given a proper input file which doesn’t violate the described format.

•     Be careful with the size of the array you allocate in program stack. Large arrays may not fit in program stack(stack size may be smaller on the test machine) and your program crashes.

•     Make sure you can read input files with or without a tailing newline at the end. (If you are using a windows machine, newline is CRLF, on unix it is LF). You can alter this using advanced editors (i.e. Visual Studio Code). Test your code for every possible combination.

More products