Picture Lab: Use Graphics, Arithmetic, Functions

 

Overview

In this lab you will write your first independent program. The program first defines a function that paints a simple square shaped picture at a given location and of a specified size. The main program then calls this function several times, testing that the function is well defined and illustrating simple user interfaces.

Objectives

Program Management Skills

Programming Statements and Directives

Design and Programming Patterns

 Project Description

Project Goals

You goal is to write a program that performs the following tasks:

  1. Write the name of both partners in the comments in the program header.
  2. Define the function Picture to display a square picture that will fit inside the selected square. You must use at least one rectangle, one oval, one circle, and two lines and at least three different colors.
  3. In the main program write function calls for four tasks: BigPicture, UserPicture, and FourPictures.
  4. Write a function BigPicture that will first clear the graphics window and then display the picture to fill the entire graphics window.
  5. Write a function UserPicture that will first clear the graphics window and then ask the user to enter the desired location and size of the picture. Use a default location (100, 100) and default size 150.
  6. Write a function FourPictures that will first clear the graphics window and then display four pictures of size 150 so that they fill the window.

Project Environment

The Shell.cpp file contains the usual skeleton of main function and a skeleton of a function Picture(int x, int y, double size). In addition, two calls of the Picture function are included in main for illustration. You will need to modify Picture function so it paints something nice and you will build four other functions that will supervise the painting of several of your pictures in different sizes and configurations.

Lab Guide

In order to write this program, start with thinking with a piece of graph paper. Design a simple picture and record the needed information (coordinates in terms of the top left corner x,y and the given size). Note that size has been defined as double and so you can safely use quantities such as  2.5 * size or size/3. Use the sample code in Picture function as a guide.

Design the function Picture - by writing the entire code on paper first.

Implement your picture code and make sure it works correctly with the existing code in main.

Once this is done, save your Shell.cpp and copy it into a folder labeled FirstPicture.

Now you are ready to test your Picture function thoroughly. To do this you need to declare and define four functions and call these functions from main as specified above. Each function should start with clearing the display.

 

Test each function after you build it and before you go on to the next one. As you are working on the different tasks, make sure your program is readable. Use comments, tell the reader which task is being performed, use extra blank lines to separate different kinds of actions, use identifiers that are meaningful. Part of your grade will depend on the organization and readability of your program. You may even finish up at home, adding comments and polishing the final layout of the source code.

Completing the Lab Project

Once your program is correct, you need to do the following:

·        Save the Shell.cpp file (though you had to do it every time you ran the program).

·        Print the Shell.cpp file by selecting Print command from the File menu.

·        Print an extra copy for one for the two partners - the other one will get back the graded copy.

·        Close the Visual C++ environment - ask if you do not know how.

·        Copy the Shell.cpp file onto a diskette into a folder labeled PictureLab to hand in, and onto backup diskettes for yourself and for your partner.

·        Label the diskette so it shows both names and the name of the lab (Picture Lab).

·        Erase all your work from the D drive.

·        Hand in the Shell.cpp printout and the diskette.