First, create a project of type Win32 Application in
C:/FILES called FileRead. Add the EzWindows
library to your project and, if necessary, modify the options under
Tools to add the path to the EzWindows include directory.
Add a new C++ Source code file called FileRead.cpp
to your project. Paste the program outline found on this link into FileRead.cpp.
In this lab you will write a program that reads a description of
a drawing from a file and displays it in a window.
Each line of the file will describe a shape using six components:
Colors and shapes are described by one letter. The encoding for
colors is given in the comment to the C++ function
letter2color. The three shapes are encoded by
the letters r, e, and t.
There are three places where you need to modify this program.
First, insert your name into the comment on the first line.
Second, look for the comment line that read
Third, do the hard part. Look for the line
Once you are able to draw a rectangle with little trouble, modify your
program to produce any of the three shapes encoded by the letters
r, e, and t.
Your program contains the line
Ask your lab instructor to verify that your program correctly produces
the drawing specified in the sample file above.
If you go through this exercise at warp speed, you might consider the
following extra credit assignment. Write a simple program that reads
this list of integers from one file and writes
them to a different file. This is easy to do using the information in
section 5.6 (on pg 244) of your text. Hint: an input file (i.e.,
a file that you read from) is of type ifstream
(see the program that you wrote above for an example), and an
output file (i.e., a file that you write to) is of type
ofstream.
After you have tested your program, ask your instructor to run it.
After these six items an optional "comment" may appear on the line.
Here are a few lines that describe a couple of red rectangles
followed by a blue ellipse
5.0 6.0 3.0 2.0 r r
7.8 3.0 4.0 3.0 r r please ignore the comment
10.0 10.0 2.0 2.0 b e
// Fill in here to read the line
This is where you add four more ">> variable"
into the while loop condition
to read in the other items of the line.
// Fill in here to draw the shape
This is where you add the code that creates an appropriate shape and
draws it to the screen. As a first step for this part of the
assignment you might want to try drawing a rectangle of
the appropriate dimensions and color. If you are unsure about how to
use the function letter2color to transform the input letter
into an EzWindows color, you should ask your lab instructor for help.
Sample inputfile
ifstream fin("Lab07.txt") ; This line declares fin
to be an ifstream object that extracts values from the file
Lab07.txt. Consequently, you will need to have a drawing
description stored in a file called Lab07.txt in your
project directory. We have provided a sample file for cut-and-paste
to help you out here. This file is a "translation" of a C++ face
program written last year. Create a new Text File in your project
with the name Lab07 and paste the contents of
this file into it.
Lab Checkoff
Extra Credit
Extra Credit Checkoff
Return to CSCI 201 page
Return to the UNCA Computer Science home page