EEN118 LAB ONE solution




5/5 - (5 votes)

The purpose of this lab is to get you familiar with our computer
systems, so that you will know how to create, edit, and run programs,
how to download needed software, how to make safe copies of your
work, and things like that. You will not need to make any clever
designs today.
1. Use Microsoft Visual C++ to create and run a very simple text-based program.
Create a new folder to work in, and create another sub-folder within it. Remember the
names of the two folders. It is quite reasonable to give them both the same name, then there is
less to remember.
Use a web browser (Internet Exploiter will probably be the easiest to use) to connect to
this URL:, follow the link for “class related material”,
then “the Programming Library: Downloads and Documentation”, and download library.h
and library.obj, storing them both in the sub-folder you created. Check the file names are
Start the Visual C++ I.D.E. (Integrated Development Environment), and create a new
project. It should be a “Win32 Application”; the location should be the main folder that you
first created, and the name of the project should be the name of the sub-folder that you created
within it.
Add to the project the two files that you downloaded, then add a new file of kind “C++
Source File” to the project.
Type your program into the big empty window that appeared, and press the run button.
If you didn’t make any mistakes in the typing (and if I haven’t made any mistakes in the
instructions), you should see the results you expected.
If anything goes wrong, try to work out what the problem is, but don’t waste a lot of
time on it, if you don’t see the problem quickly, get the Lab Guy to help. That’s what he’s
there for.
You are not expected to know how to write programs yet, so there is a sample below.
You don’t have to follow the sample exactly, you can adapt it to do something else, but don’t
get too clever until you know that you can make the basic things work. Remember that C++ is
VERY picky about what might seem to be minor details of punctuation.
#include “library.h”
void main()
{ print(“Greetings, Human!”);
print(“2 plus 3 is “);
new_line(); }
When your program has run, and you have finished looking at the results, just type
control-C to make its window go away.
2. Use Microsoft Visual C++ to create and run a very simple graphics program.
This will be a little more interesting, as you get to write a program that draws a picture.
Everything you do is fundamentally the same as for the text-based program. You do not need
to download anything new. You do not need to create a new project even.
If you want to save the program you wrote for part 1, go to the sub-folder that you
created and put all the files into. Look for the .cpp file whose name matches the name you
selected, and make a copy of it. In a normal windows explorer window showing names and/or
icons for files, the easiest way to copy a file is to first click on it so that it is highlit, then
select “copy” from its window’s “edit” menu, then select “paste” from that same “edit” menu.
A new file called “copy of (name).cpp” appears, you can change its name to something more
meaningful, and know that your program has been kept safe.
You can use the sample program below or, as before, you can adapt it to do something
you find more interesting. If you think about what you are typing while you are typing it, you
will probably understand this program, and be able to work out how to make a similar one
that draws something else.
#include “library.h”
void main()
{ make_window(400, 400);
move_to(150, 250);
write_string(“Pentagon”); }
Notice that this time your program produces two windows. One is for the graphics to
appear in, the other is for normal text as before. Even though this program didn’t use print(),
and therefore didn’t produce any normal text, the window still appears. You can mix graphics
operations and text operations in the same program, they appear in different windows so they
don’t get mixed up. When your program has run, and you have finished looking at the results,
just type control-C to make its windows both go away.
Your Own Designs
Remember, the point of this assignment is to get you used to writing programs properly.
If you can’t work out how to do something, ask the Lab Guy. You should be concentrating on
getting used to the form or shape of a correct program. If you didn’t see the solution right
away, and needed help from the Lab Guy, that isn’t a problem. Just be sure that once you have
made it into a working program, you really do understand it. Your working programs should
not contain anything that you don’t completely understand.
Pay particular attention to giving your programs a good clear layout. All the statements
of a function should be neatly lined up at their left-hand edges, and should be indented more
than the heading of the function itself. This seems pointless for small programs, but the habits
you make now will stick with you for a long time, and if they are bad they will get you. It is
much easier to enter a program correctly in the first place than to type it messily and fix it up
A. How Long is a Year?
Write a program that calculates the number of seconds in a year, and prints the answer nicely.
A year is 75 seconds long
This sample output does not show a perfectly correct answer
B. Black Magic, Stars.
Either: Write a program that draws a tidy regular pentagram.
Or: Write a program that draws a star with an even number of points, like a star of David.
C. Stick Men, Round Heads.
Write a program that draws a stick-man or stick-woman, with his or her left hand raised. It
doesn’t have to be very good. Try to give him or her a proper round head, but don’t worry if
you can’t see a good way of doing that, it isn’t that important.
(Hint: on a white background, drawing in white has the effect of erasing)