< Back

Lecture 34 - Final Review


As usual, create a directory to hold today's activities:

  $ mkdir ~/cs170/labs/lab34 
  $ cd ~/cs170/labs/lab34


Practice Problems
  1. Create a Qt program which performs a Monte Carlo estimation of the value of Pi. To perform this estimate, you will create a square Qt window, and inscribe a circle in that window.

    Generate a large number of random points on the window, keeping track of how many dots are within the circle vs. the total number of dots. If a dot is inside the circle, color it green. Otherwise, color it red.

    Your program should also write the estimate of pi. You can compute this as \(4 \times \frac{num\_point\_in\_circle}{total\_points}\)

    Note: Bonus credit would be awarded to programs which animate the process of drawing dots.

  2. Write a recursive function int sumDigits(int val), which takes a positive integer as a parameter. This function should return the sum of all of the digits in val.