Thursday Section

QU

16th January 2003

 

Friday Section

Q2, QH

17th January 2003

EEN118 LAB ONE

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 design your own program 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 http://rabbit.eng.miami.edu , follow the link for "class related material", then "the Programming Library: Downloads and Documentation", and download library.h and library.cpp , storing them both in the sub-folder you created.

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.

 

 

Sample program for part 1

 

#include "library.h"

 

void main(void)

{ print("Greetings, Human!");

newline();

print("2 plus 3 is ");

print(2+3);

newline(); }

 

When your program has run, and you have finished looking at the results, just type control-C to make its window go away.

  1. 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 (which is borrowed from the class notes, it draws a green pentagon with the word "pentagon" in orange beside it) 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.

 

 

Sample program for part 2

 

#include "library.h"

 

void main(void)

{ MakeWindow(400, 400);

PenColor(PEN_GREEN);

PenWidth(5);

MoveTo(200,100);

DrawLineLength(100);

TurnRightByDegrees(72);

DrawLineLength(100);

TurnRightByDegrees(72);

DrawLineLength(100);

TurnRightByDegrees(72);

DrawLineLength(100);

TurnRightByDegrees(72);

DrawLineLength(100);

PenColor(PEN_ORANGE);

MoveTo(200,100);

SetFontSize(24);

WriteText("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.

 

  1. Programming under Unix.
 

Now you are going to run a little program under the unix system. Unix is now considered to be the choice operating system for professional programmers (Linux, FreeBSD, and MacOS-X are all versions of unix), so it is important that you know how to use it.

Unix is a text-based operating system: you type commands, and the computer types responses back to you. It is more like using DOS or a "DOS shell" than windows. At the moment, you can't do graphics programming under unix, but I am working on a fix for that.

Run a TELNET application. If you are in one of the college labs, you can use powerterm, but most students prefer to download something more functional if they are going to be working for more than just a few minutes.

When the telnet application starts, you will need to apply a few settings. Set the "host" to rabbit.eng.miami.edu , and the "emulation" or "terminal" to vt100 . That should be all that's needed. If it gives you a choice of protocols, ssh2 is better than telnet , but both work. When you press the "connect" or "OK" button, a window inviting you to log in should appear. You are now communicating with the server called Rabbit. If you have any kind of internet connection at home, exactly the same steps should be used.

The response to "login:" is your username, which should be the first letter of your first name, followed by all of your last name, all run together into one word, no capitals, no spaces, and no punctuation. After typing your username, it will ask for your password. Initially, your password is your U.M. student number, beginning with a capital C.

As soon as you have successfully logged in, change your password. Change it to something that will be meaningful only to you. Don't use a real word or a name or your birth date. Use a mixture of capital and little letters, maybe throw in a digit or two to make it even harder to guess. Remember your password, but never tell anyone what it is, not even me.

If anything goes wrong, the Lab Guy will sort it out.

 

3A. Check your mail.

You should have a mail message from the lab guy. Reply to it, so that he can see that you are able to use email. If you have another email account that you prefer to use normally, set up your rabbit account so that mail sent there will be automatically forwarded to it. If I ever need to contact you, I will send email to your rabbit account, so either set up forwarding or check it regularly for new messages. To set up forwarding, all you need to do is create a file called .forward (the dot at the beginning is an essential part of its name). That file should contain just one line of text, and that line of text should be your correct email address. That's all it takes. The easiest way to create a file is by using pico , the text editor. The Lab Guy will explain how.

 

3B. Type in and run a program.

You do not need to download anything or create projects when you are using Rabbit. Just use the editor pico to create a new file. You choose the name of the file, but it must end with these exact four characters: .cpp that it what marks it as a C++ program. Once the editor is running, just type your program. You can use the same program as you used for part 1. Everything should be the same, but remember you can't use graphics operations. Check that your program appears to have been typed correctly before exitting the editor by typing control-X.

Then compile your program. This prepares it for running. If there are any mistakes in your program, you will be told about them as part of the compilation process. To compile a program, type the command CC (both capital letters) followed by a space and the name of the program.

If there are errors, go back into the editor and fix them, then compile again, repeating the process until there are no errors. When there are no error messages, run your program by typing the command run .

  1. Use FTP to transfer your program to the PC.

Even though you were sitting in front of a PC typing and running your program in step 3, that PC was just acting as a very expensive go-between. All the work was being done on the server, Rabbit. The file you created is stored in your share of Rabbit's disc.

That is not a problem. It is safe there and will not go away unless you delete it. However, sometimes you will want to keep a copy of your files on your own personal computer at home or in your dorm room. That is always a good idea, because accidents do happen. If a college elephant were to sit on Rabbit one day, its discs could be damaged and files could be lost.

FTP is a simple program that allows you to transfer files between any two computers over the internet. All you have to do now is successfully use FTP once, so that you will know how to do it when you are at home wanting to save your files and there is nobody around to help.

Start the FTP application. In the labs, it is called "WS-FTP", and I recommend you download that same version for yourself at home, I believe it is free. The version of FTP produced by microsoft and shipped with windows is not recommended at all. When you start WS-FTP, you will have to provide a few peices of information in a little window.

Profile Name: (doesn't matter, anything will do)

Host Name/Address: rabbit.eng.miami.edu

Host Type: UNIX (standard)

User ID: (your username)

Password: (your password, the new one that you just set)

Account: (leave blank)

Notice the two check-boxes at the right of the window. "Anonymous" must be OFF. If you are using a public computer, "Save PWD" MUST BE OFF. Save Pwd means that it will remember your password, and the next person to use the computer will be able to access your account unhindered.

Then press OK. If all goes well, it will connect to rabbit. You will see two file views. On the left you'll see the files of the PC you are sitting in front of. On the right you will see your files on Rabbit. Navigate (by double-clicking folder icons or "..") to a suitable place; select (by single-clicking) the Rabbit file that you want to transfer, make sure that "ASCII" is selected, then press the arrow button " <- " that points from your Rabbit files towards the PC files. The file will be transferred, and you will be able to access it directly on your PC. Make sure that you can.

Always select ASCII for any file that contains PLAIN TEXT ( .cpp or .txt files mostly), and BINARY for other files (such as .gif or .jpg graphics or .doc word-processor files). FTP shoule work exactly the same from home as it does in the labs on campus. It is very useful.

 

  1. Make sure you understand what you've done.

When you get a homework assignment you'll be on your own. The purpose of this lab session is to make absolutely sure that you'll be able to do all the important things. If you are not sure that you would be able to create a new program on your own, run through the steps again, perhaps taking note of what the screen looks like at each stage. Or get help from the Lab Guy.

 

  1. Go Home, you have Finished this Lab.