CS 010 - Introduction to Computer Science I
Lab 4.
Graphical Objects and the If Structure

Points(10 overall)

  1. 2 pts: Attendance(at start and end of lab)
  2. 7 pts: Programs
  3. 1 pt:  Commenting and Style

Collaboration policy:
You will be working in pairs during labs.  Pairs will be randomly selected and will be announced by the TA.  Each week you will have a new random partner.  You will discuss the programs with your partner, but you will still be typing in your own code to show to the TA.  You can help each other debug, give plenty of suggestions and hints, **explain** why things work or don't work, etc.


Lab Objectives

To gain experience with

  1. using objects
  2. drawing graphical shapes
  3. changing coordinate systems
  4. using if structures

Commenting and Style

  1. Be sure to use good variable names.
  2. Use comments throughout your code to explain your code.
  3. Use good spacing and keep it consistent throughout your program.

 


Program 1: Moving Graphical Objects

Generate five circles with center (0,0) and radius 1, 2, 3, 4, and 5.  Use the move function of the Circle object to draw the circles all tangent at a common point, like this:

 

 


Program 2: Employee Objects and the Graphics Window

You will be writing a program that allows the user to input three employee names and their salaries.  Draw a stick chart illustrating their salaries and showing their names. The highest salary can be assumed to be $250,000. If the input for an employee's salary is not valid, do not print the stick or name for that employee. Thus, at times you may print 3 sticks and names, but if there are errors, then you may only print 1 or 2, or even 0.

 

Example 1

__________________

Doe, John

__________

Greene, Susan

______________________________

Ford, Tammy

 

 

Hints:

You will want to change the coordinate system.


 

Bonus Program (1 pt):

Write a program that allows the user to drawing a face.  The user will participate in drawing the eyes and the mouth.  For the eyes, they will specify the center points.  For the mouth, they will choose five points (equating to four lines).  You do not need to check that what they draw stays within the confines of the face.  An example result could be: