[Solved] COMP206 Assignment 1-C strings, reading text files and structured output to standard output

$25

File Name: COMP206_Assignment_1-C_strings,_reading_text_files_and_structured_output_to_standard_output.zip
File Size: 857.22 KB

SKU: [Solved] COMP206 Assignment 1-C strings, reading text files and structured output to standard output Category: Tag:
5/5 - (1 vote)

Gain our first hands-on experience with coding software system specifications in C. Specific focus on working with C strings, reading text files and structured output to standard output.

Instructions:

Write the two C programs specified in the following questions. Test them very carefully and pay careful attention to detail, as marking will ensure that you program meets the specifications very precisely. Every program you submit must compile with gcc program_name on mimi.cs.mcgill.ca without errors or warnings. When run with the examples shown here, as well as additional correct inputs, the corresponding correct output must be generated. If run with incorrect inputs, the program must never crash (segfault, bus error, etc),but rather print informative errors and exit cleanly.

Automated Testing:

The eval.py script contained in the assignment folder can be used to ensure your program works well with our automated grading. It will compile run several of the basic tests and report the results. To run it, place your C files in a folder, and run $ python <folder_name>. You will see a fairly long report generated. When everything works, you should see the string Your programs output is the same as expected output: True for both questions. This is similar to the process well use for real grading, but that will include a wider range of test cases, so do run your program directly yourself and ensure it always works!

Handing In:

Upon completion, create an archive file with both your C programs using the command:

$ tar czf A1_submission.tar.gz q1_julia_explorer.c q2_calendar.c

Submit the resulting archive on My Courses.

Due Date:

  1. For full marks: Friday Feb 9th
  2. Final deadline (with 10% penalty): Tuesday Feb 13th

Question #1 Explore the Julia Sets (40 marks)

A Julia Set is a construction from complex math that can be used to generate a wide range of fractal patterns, with the chaotic property: very small changes in the initial conditions lead to dramatic changes in the generated shape. A standard Linux tool, gnuplot, is capable of plotting a Julia Set from a simple text script and we have provided you with the basis of this script as the attached file shape_template.txt.

You will create a C program to automate the process of inserting the initial conditions, two floating point numbers, into the correct place in the script, a simple token replacement. In case you try this on your own computer, the command sudo apt-get install gnuplot-x11 is likely to be helpful.

Write a program q1_julia_explorer.c that allows the user to produce Julia Set plots interactively:

  1. Accept exactly three command-line arguments <file_path> <a> <b>:
  2. <file_path>: A path to the provided shape_template.txt gnuplot script
    1. Identify a correct shape_template.txt file as one your program can open for reading, and which contains two tags: #A# and #B#. For any incorrect file, output Error: bad file and return with code 1.
  3. <a>: A floating point value a (which has meaning in the construction of the Juliaset)
  4. <b>: A floating point value b (which has meaning in the construction of the Juliaset)
  5. For any problem with the a or b arguments, output Error: bad float arg and return 1 2. Produce a modified gnuplot script on standard out, where the modifications are exactly:
  1. The #A# tag text is replaced with a, printed with 6 decimals (use %.6f)
  2. The #B# tag text is replaced with b, printed with 6 decimals (use %.6f)
  3. Note that the provided shape_template.txt is only an example. Your code should definitely handle the tags in this file, but hardcode as little about it as possible, such that any other file with the same tags can also be used for testing.

Examples test runs:

Question #2 Formatting the year (60 marks)

Write a C program named q2_calendar.c that prints one years full calendar to standard output.

  1. Accept exactly 2 command-line arguments that control the calendar details:
  2. Maximum number of characters DAYSIZE to print for the day-of-week labels, which must be 2 or greater
  3. The day-of-week that starts the year FIRSTDAY as an integer from 1 to 7 (1 is Sunday in English)
  1. Your output must precisely follow the format specification given by the following examples, so you should make sure you can replicate them precisely. Note that the examples were cut off at April only because we ran out of space on the page. The output must continue until Dec 30th. The full text specification of this format is on the next page.

Detailed calendar specification:

  1. Accept exactly 2 command-line arguments:
    1. Maximum number of characters DAYSIZE to print for the day-of-week labels, which must be 2 or greater
    2. The day-of-week that starts the year FIRSTDAY as an integer from 1 to 7 (1 is Sunday in English)
    3. Your output must precisely follow this specification (and shown in the examples below) for printing a years calendar.
    4. Every row must begin and end with the one pipe symbol |
    5. Each row contains (DAYSIZE+3) x 7 + 1 visible symbols, and a newline
    6. Each month is composed of:
      1. A full-wdith separator line of dashes –
      2. A line composed of the months full name, centered using spaces, with one less space before than after if needed
  • A separator line
  1. A line with 7 columns of day labels, with pipes | in between. Each day label contains: i. A single space
    1. The day-of-week name cut down to DAYSIZE characters if needed
  • Additional spaces to pad up to DAYSIZE if needed A single space
  1. A separator line
  2. 5 or 6 lines that contain the days of that month:
    1. Print exactly 30 days always (avoids leap-years etc). Separate day sections with pipes | in between

iii. Lay out the date numbers with the usual logic:

  1. The first day of Junuary is specified with the argument FIRSTDAY
  2. The first day of each other month is on the weekday following the last weekday of the previous month
  3. When a week is not full with dates, blank days are printed to maintain spacing, both at the start and end of the month
  1. Each non-empty day section must contain, in order:
    1. A single space
    2. The date as a one or two digit integer, following correct ordering
  • Additional spaces to pad up to DAYSIZE if the number was too short A single space
  1. The final line of the year must be a separator line

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP206 Assignment 1-C strings, reading text files and structured output to standard output
$25