CS 150 - Test Project 1

Due: Wednesday 4/5 at 8am

A test project is an assignment that you complete on your own, without the help of others. It is a take-home exam. You may use the textbook, your notes, your previous assignments, the notes and examples on the course web page and the Python library documentation (linked on the course web page), but use of any other source is not allowed. You may not discuss these problems with anyone except the course instructor. You may only ask the tutors for help with hardware problems or difficulties in retrieving or submitting your program.

Complete each of the three problems below, each as a separate program, in a separate file. You are encouraged to reuse code from your assignments or our class examples. Partial credit will be awarded, so if you can't solve a whole problem, get as far as you can.

Note that each problem is worth 31 points, 20 of which are for functionality, and 11 for style. Be sure to write clean code with good comments and docstrings in order to get all the style points.

Improving the programs and extra points

If you do everything that is stated below, the maximum number of points you can get is 93 (corresponding to a grade of A). In order to get the full credit of 100, you must implement some extra features for at least two of the problems. I've provided some ideas below, but you should feel free to exercise your creativity. You may receive at most 4 extra points for any given program, with a total of at most 7 extra points.

For all additions, include in the comments at the top of the file what you've added or you may not get credit.

Problem 1: GPA calculator

As you talk to some of your friends around campus, you realize there is a real need for a program that calculates a student's GPA both for their current grades as well as for their overall time here at Middlebury. When you run the program:
  1. The user is first prompted to enter how many semesters they've been here (not including the current one), and their GPA so far.
  2. The user is then prompted to enter grades for their four courses for the current semester.
  3. The program outputs the GPA for this semester, as well as
  4. a revised version of their cumulative GPA that includes this semester.
For example, here is a sample transcript from the program running:
***** GPA Calculator *****
How many semesters have you been at Middlebury? 4
What is your GPA so far? 3.0
Enter grade for course 1: A
Enter grade for course 2: B
Enter grade for course 3: b
Enter grade for course 4: A

------ Results ------
Your GPA for this semester is: 3.5
Your new cumulative GPA is: 3.1
You must write the following functions: Possible program extensions: Include support for "+" or "-" grade variations (without code duplication, i.e., you may not simply add more elif statements for every combination); prompt the user for an optional 5th course; prompt the user for the number of courses; have the user enter a target GPA and calculate what grade average they must achieve on average for the remaining semesters to achieve this.

Problem 2: Word facts

Write a program that prompts the user to enter a word and then displays the following facts about the word: For example:
Enter a word: APPLE
Apple has 5 letters in it, 2 of them vowels;
it is not a palindrome;
it starts with 'A' and ends with 'E'.
Enter a word: Racecar
Racecar has 7 letters in it, 3 of them vowels;
it is a palindrome;
it starts with 'R' and ends with 'R'.
To receive full credit you must: Possible program extensions: print out another fact about the word; print out all the unique consonants in the word; allow the user to repeatedly enter words until some stopping criteria is reached; check whether the word is a valid English word (you can use the file "english.txt" from the class examples on March 15.

Problem 3: Visualizing pi

In class on March 6 we discussed how to approximate the value of π using Monte Carlo simulation. Here we explore this idea again, this time by generating random points in a 2 x 2 square. If we count what percentage lies inside a circle with radius one inside this square, one gets an approximation for pi/4.

Write a program that visualizes this approach using turtle graphics. The program should draw the outer square, the inscribed circle, and then generate random points within the square. If the point lies within the circle it should be one color, and if it lies outside the circle another color. I strongly encourage you to start from the code we looked at in class and then add on from there.

You must:

I encourage you to define additional functions to structure your code neatly. Be careful not to use variable or parameter names that are also functions. For instance, "color" is one of the turtle functions. Use the following code as the "main program" after your functions definitions:
tracer(0, 0) # no animation

# call your function visualize_pi here


Here is a sample image resulting from a call to visualize_pi with a radius of 150 and 300 points:

Possible program extensions: add some text to the turtle printout (look at the documentation for how to do this), for example, print out the approximation of pi or add a title; make the picture look better.

In addition to your code for this problem, you must also submit a screenshot of an example run. See the instructions for Lab 2 for a reminder on how to get a screen capture.

When you're done

You should have three separate files/programs, one for each of the programs above. Each program should run when you hit the green triangle button, that is, after all of your function definitions you should have a few lines of code (or just one) that calls your main function(s) to set everything in motion.

As always, make sure that each program is properly commented:


Submit each of your files digitally using the online submissions script. Note that the submission script lets you upload one file for each problem, and also a screenshot for problem 3. Be careful to upload the correct files!



Style/comments (per program)    11 * 3
    variable naming
    additional functions

GPA calculator
    letter_to_gpa                   5
    semester_gpa		    5
    cumulative_gpa		    4
    User input and program output   6

Word facts
    output format		    3
    capitalization		    2
    count_vowels		    5
    is_palindrome		    5
    start/end letter		    2
    additional function		    3

Visualizing pi
    draw_circle			    6
    outer square		    3
    large circle		    2
    random points		    4
    colored appropriately	    5

Extra points (max 4 / program)      7

total	            33 + 60 + 7 = 100