CPSC170 Lab 0

Objects

Getting Started

Generally in lab you will be typing your programs into emacs, typing shell commands into a terminal window, and using Firefox to access the lab. So, to get started

  1. Open a terminal window and create a directory for your lab0 files. Recall the command to change directories is cd and the command to create a directory is mkdir.

  2. Remember, when opening python files you should start the emacs program first then use C-x C-f to find the file you want to open. If you just double click the file from the Ubuntu file browser it will open in gedit, which you do not want.

Gradebook

We will work on writing a gradebook that a certain lazy professor might be in need of. For this basic version, we will want to be able to store grades for multiple students, and view particular students grades and averages.

The file Student.py contains an incomplete class definition. Complete the definition for Student using information from the comments in the file.

The next file is Gradebook.py, and is another incomplete class definition. You will need some way of storing multiple students, and methods to access the different students. Follow the comments again to complete the implementation.

And finally, the test program is Grades.py. Notice that it only has one student currently defined. Make sure your classes provide behavior similar to below:

> python Grades.py
95 92 85 87 
100 92 99 
99 83 
91.3
ERROR: No student with name "Scotty"
    

Add another student to the Grades program, and assure you can differentiate between students.

Persistence

Your professor is forever grateful that you wrote this wonderful gradebook for him, but he does have one slight request. It would be nice if your program was able store the data that has already been entered, as opposed to having to re-enter the data every time the program restarts.

You know how to write files (Remember from CPSC 120?). We will talk later how we could use the pickling module here, but for now we will manually do it. So, assume the following file layout:

	student1 name
	number of assignments
	assign1 
	assign2 
	assign3 
	...
	number of quizzes
	quiz1 
	quiz2 
	quiz3 
	...
	number of tests
	test1 
	test2 
	test3 
	...
	student2 name
	...
      

You will need to write at least two new methods: writeData and readData. To simplify matters, you can assume a file name, such as grades.in.

Drawing Circles

We will be using turtle again this semester, so now would be a good time to get reaquainted with turtle. We will write an python program which will draw N randomly placed, sized, and colored circles on the screen. For simplicity sake, assume N == 10 while you start, but your program should be generic enough that changing the value of N changes the number of circles drawn.

The file Circle.py has a incomplete class definition of a circle. the circle class should store all the information necessary to draw a circle in a specific location with a specific color. The draw method should use the passed turtle_handle to draw itself. If you do not remember how to use turtle, the documentation is here.

Notes

Submission

Submit a zip file of your code on the course Inquire site using the format FirstLast.zip as the file name.

If you worked with a partner, use the file format FirstLastFirstLast.zip. Don't forget to also email your partner the lab material.