[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] >> [CSE201] >> [Lab01] >> index
[Index] [Schedule] [Syllabi] [Glossary] [Labs] [Projects] [Resources] [Grading] [Search ]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10]
Wed Apr 18 14:36:20 PDT 2012


    CS201 Laboratory 3 -- Simple Graphic Programming

      Previous [ ../lab02/ ] Next [ ../lab04/ ]


      In this lab you will test two programs based on the book and then design and code a program that draws some kind of smiley face.

      This laboratory should be done on our lab computers and physically in the laboratory. It needs some special libraries on our machines. They do graphics. It is non-trivial to get graphics like these to work through the internet.

      Setting up a cs201/lab03 directory

      This is just like the last lab. Use the "Files" application (in Activities) to find your "cs201" folder and to make a "lab03" folder. Also start up a terminal/command window in this directory.

      Download these files

      1. A program like that on page 72 [ circle.cpp ]
      2. A program different to that on page 72 [ circle2.cpp ]
      3. A program using strings and Messages [ corners.cpp ]
      4. A program that draws a stickman [ stickman.cpp ]
      5. A blank program to get you started on P2.22 (draw a face) [ face.cpp ]

      Compile and run the two given programs

      Open a terminal window and change directory/folder to the lab
       		cd cs201/lab03
      then enter this command to test the "circle" and "corners" programs
       		Q circle.cpp
       		Q corners.cpp

      These will compile and run the two programs for you. Notice the complex commands needed to include the graphics libraries.

      The corners program will ask for 4 characters to be type in the graphic window.

      You have to close the pop-up graphic window to get the next program to run.

      Study the code of circle and corners

      You can click circle.cpp and corners.cpp to see how they work. Take a little time, and perhaps using the book, see what you can guess/figure out about the code.

      Compare circle and circle2.cpp

      Compare the code in circle.cpp and circle2.cpp. What has changed? How does this change the picture they draw? What does this teach you about Point and Circle?

      Compile and run the stickman program

      You can use
       		Q stickman.cpp
      to compile and run this program.

      Make the stickman into a stick women

      Study the stickman.cpp file and use
       		gedit stickman.cpp &
      (or by right clicking the image of the file in Files) to give the figure a skirt instead of legs. You can use
       		Q stickman.cpp
      to compile it and run it.

      Credit (Grade=B)

      If you get this far before the end of the lab session you have earned an B.

      Drawing a face

        First Think

        First think about how a "smiley" face is made out of parts that you know how to program: lines and circles. Look at the example in P2.22 in the text. The real problem is the set of steps "// 1.", "// 2. " and so on that you need to draw a face. So start by writing them as comments in English. This is your algorithm.

        The next problem is getting the parts of the face in the right place. It helps if you have a piece of paper with the coordinates on it and a pencil to do a rough sketch of what you want.

        Then Code

        You need to fill in the blanks in the "face.cpp" file (downloaded above).
         		gedit face.cpp &
        Your first step should be to put your name as the author.

        You may look at "circle2.cpp" by opening it in "gedit" and copy/paste code from it to "face.cpp"

        When you are ready fill in the blanks in the face.cpp program and test the result:

        		Q face.cpp

        Compilation errors?

        Does the compiler object to your code? If you can't guess why call us over...

        Fix the error and try again until the program runs...


        If you don't like the look of your graphic.... think about what has gone wrong and fix it.

      . . . . . . . . . ( end of section Drawing a face) <<Contents | End>>

      You get an A for getting the smiley face to run

    . . . . . . . . . ( end of section CS201 Laboratory 3 -- Simple Graphic Programming) <<Contents | End>>

    Historical Note

    This laboratory originally used a "Makefile" [ Makefile ] and the Unix (Linux) make command. A file system failure Jan 21st 2011 resulted in inconsistent clock settings and that stops make working.


  1. Gnu::="Gnu's Not Unix", a long running open source project that supplies a very popular C++ compiler.
  2. TBA::="To Be Announced", something I have to do.
  3. TBD::="To Be Done", something you have to do.