Computer programming - Lab 11

1. Define a structure type for vectors in 2-dimensional space. Define functions for addition, subtraction and magnitude, and to read a vector (space-separated real coordinates of endpoint, assuming zero origin). Use this function to compute the total length of the segments drawn in the path d="..." element read from a SVG file. The path keeps a current point, and the commands are of the form letter x y, with L/l for "line to" and M/m for "move", uppercase for absolute coordinates, and lowecase for relative. Check that your answer is correct computing a formula

2. Use the struct timespec structure and the timespec_get function declared in time.h (C standard, paragraph 7.27.2.5, p.391/409) to benchmark the time taken by some code of your choice (be sure to run it many times).

3. A real number 0 < x < 1 can be successively approximated in a continued fraction with 1/a1, 1/(a1+1/a2), 1/(a1+1/(a2+1/a3)), ... where a1, a2, a3, ... are natural numbers. In the initial approximation, a1 is ⌊1/x⌋, and one continues using the same rule for the fractional part of the denominator approximated with a1, etc. One obtains a sequence of rational numbers p1/q1, p2/q2, ... that approximate x increasingly well, alternating from above and below.
Define a structure that represents a rational number and compute recursively the nth rational approximation of a fractional number x using a continued fraction.

4. A .csv file contains the grade situation for a class of students. Each line contains fields separated by commas. The first field is the student name, followed by up to 10 fields with real-numbered grades or other characters; any remainder of the line is ignored.
Read the file using an appropriate data structure; you may assume there are at most 200 students. Compute averages for the students that have 10 passing grades. Sort students in decreasing order of their grade averages; break ties in alphabetical order. Print the sorted list with grade averages.

5. A propositional formula in conjunctive normal form is represented as a conjunction of clauses which are disjunctions of literals, as follows:

(and (or lit11 lit12 ...)
     (or lit21 lit22 ...)
     ...
     (or litn1 litn2 ...)
)
with arbitrary many literals per clause and arbitrary many clauses; the amount and type of whitespace does not matter. Literals are represented by nonzero integers: a positive integer n denotes proposition pn, a negative integer -n denotes its negation ¬pn.
Use an appropriate data structure (structures or zero/NULL-terminated arrays) to read and store a formula from input.
Optional: Read values of 0 or 1 for each of the propositions (assumed to be consecutive integers from 1 to some n) and determine the value of the formula.
Optional: Use the DPLL algorithm to determine if the formula is satisfiable.

Marius Minea
Last modified: Tue Dec 3 14:30:00 EET 2013