COSC 105 Assignment List

All Assingnments are due at 11:55 pm. Grammars are available from the file COSC 105.pptx on Courses.

A1 (1/13)

  1. Write the regular expression that accepts all words that start with an a followed by any number of a's, b's, or c's.
  2. Write the regular expression that accepts all words composed of a's, b's and c's that ends with an odd number of b's.
  3. Use Grammar A to show that a1b2c3 is valid.
  4. Use Grammar B to shaw that d is valid.
  5. Use Grammar B to show that -ddd is valid.
  6. Use Grammar B to show that +ddddd is valid.
  7. Use Grammar C to show that a * a + a * a is valid.
  8. Use Grammar C to show that a + a + a * a + a is valid.

For grammar problems, find the left-most derivations. Email your solutions directly to Brad.Cupp@pepperdine.edu.

A2 (1/16)

Submit your homework as a presentation on RPubs, one solution per slide. Make sure that the assignment number and your name are on the first slide. Send me an email with the URL for your RPubs root directory.

  1. Use Grammar C to show that a * (a + a) + a is valid.
  2. Use Grammar C to show that (a * a + a) * (a + a * a) is valid.
  3. Use Grammar C to show that a + (a + (a * a)) is valid.
  4. Use Grammar C to show that (((a))) is valid.
  5. Use Grammar D to show that aaabbbccc is valid.
  6. Write the following three formulas (one per slide) using Latex.
    \[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]

    \[ \int_{-\infty}^\infty e^{-x^2}\,\mathrm{d}x = \sqrt{\pi} \]

    \[ f(x) = \sum\limits_{n=1}^\infty (a_n \cos{\frac{n \pi x}{L}} + b_n \sin{\frac{n \pi x}{L}}) \]

A3 (1/20)

Martin Luther King, Jr. Day—Nothing due.

A4 (1/23)

Submit solutions to each problem below as a separate slide in a single RPubs presentation.

  1. Write the function meters(feet, inches) that takes feet and inches as input and returns the equivalent number of meters. For example, meters(4,8) should return 1.4224. One inch is exactly 0.0254 meters.
  2. Write the function celcius(fahrenheit) that takes degrees fahrenheit as input and returns the equivalent temperature in degrees celcius.
  3. The future value of an investment with compounding interest is computed as \( f = p(1+i)^t \), where f is the future value of a present value, p, after t years of compounding interest i (a perecentage rate). Write function fv(pv, years, rate) that computes the future value of present value pv for the given rate and years.

A5 (1/27)

Submit solutions to each problem below as a separate slide in a single RPubs presentation.

  1. Write the function hyp(sideA, sideB) with two numeric parameters for the lengths of two perpendicular sides of a right triangle that returns the length of the hypotenuse.
  2. Write the function duration(hours) that takes an integer input of hours and returns a vector containing the equivalent number of weeks, days, and hours (in that order). For example, duration(4123) should return (24,3,19) representing 24 weeks, 3 days, and 19 hours.
  3. Make one slide containing the R expressions that

Use the range operator to answer problem 3.

A6 (1/30)

Submit solutions to each problem below as a separate slide in a single RPubs presentation.

  1. A salesperson's commission is computed as 15% of the sales that exceed $1000. For example, someone who sells $1,100 should receive a commission of $15. Someone who sells $500 should receive a commission of $0. Write the function commission(sales) that returns a commission amount based on a sales amount.

  2. In a bowling tournament, participants bowl three games and receive a consolation prize of $15 regardless of their score. Those bowlers whose three-game average are at least 200 get an additional prize of $50. Write the function award(score1, score2, score3) that returns the award earned based on the three scores.

A7 (2/10)

Submit solutions to each problem below as a separate slide in a single RPubs presentation.

  1. The fine for speeding in a 45 MPH zone is $10 for every mile per hour over the speed limit for speeds from 46 to 55 MPH. It is $15 for every additional mile per hour between 56 and 65 MPH. It is $20 for every additional mile per hour over 65 MPH. For example, the fine for driving 57 MPH is $100 for the first 10 MPH plus $30 for the 2 MPH in excess of 55 MPH, for a total of $130. Write function fine(speed) returns the fine earned for the numeric speed parameter. Use the smallest possible number of comparisons.

  2. Write the function sort(a,b,c) that outputs a vector containing numeric parameters a, b, and c in descending order. Your function must contain no local or global variables. It must use no more than five comparisons and must work correctly even if some of the integers are equal. A comparison is any use of a relational operator. For example, x < 5 contains one comparison, while x < 5 && x > 2 contains two comparisons.

  3. More to come…