Summer 2001 CS401: Introduction to Computer Science Lab 0: Using Borland C++ V5.02 |
||
|
||
|
||
Writing a good computer program is not an easy thing to do (heck, using a computer program is often not an easy thing to do, much less writing one). Thus, learning how to program is a daunting task. A great amount of effort and time has been spent on writing programs that make it easier to write more programs. In fact, this has been a general trend since computers first existed! As you've already learned, a source code file (containing the text of a program as written by the programmer) must undergo some transformation before it can be executed on a computer. We could, in theory, do this translation by hand - by going line-by-line through the source code and creating machine code (all binary) that implements our program. Luckily, we have programs available that will do this for us, and these programs are known as a compilers. Software that combines a compiler with other program development tools (editor, linker, debugger, loader, etc.) are called integrated development environments (IDE). Borland C++ is such an environment, and is the topic of this lab. Just a note: sometimes you will hear people refer to an IDE as a compiler. For example, someone could ask "what compiler are you guys using?" with the answer "Borland C++". Even though Borland C++ is an IDE, it is ok to refer to it as a compiler. The implicit meaning is that you are talking about the compiler module within the IDE, but no one ever worries about such details in casual conversations. Now that I think about it, us being in Pittsburgh and all, you might hear someone say "What compiler are yinz guys usin'?", to which you might hear, "Ahh... Borland, en' at'". Also, even if you don't intend
to use Borland C++ in the future, it is important to become comfortable
and proficient with an IDE. Even though every IDE is different, they
all share a similar feel. For example, all provide an editor, debugger,
linker, loader, etc.
|
||
|
||
The primary goal of this lab is to help you get you up and running within the Borland integraded development environment. By the end of this lab, you should be able to:
|
||
|
||
You should not have a problem finishing this within the alotted lab time, however if you don't, you'll need to have a floppy disk so that you can save your work and finish later (perhaps on a different computer). To save your work (don't do this now, only if you do not finish your work in the lab), close your project (directions are in the next section), then copy your source code file to your disk (only the .cpp file, not the other project files, they are too large). To be a good citizen, go back to the c:\users directory and delete the files there, just so the next person has a clean directory to use. When you return, you'll need to start a new project with the same name, but copy your source code file to the c:\users directory before you do this. IMPORTANT INFO FOR EARLY
STARTERS: If you are attempting to do this lab ahead of time (before
your lab meets), make sure you have a floppy disk to save your code
as described above. You will need to bring this disk to the lab
so you can recover the work you did.
|
||
|
||
Borland C++ 5.02 uses a lot of auxiliary storage for each project. In this lab, and in the labs to follow, you will use the directory c:\users to temporarily store your work. Before you leave, be sure to copy all of your .cpp files from c:\users to your floppy disk, then erase your work from the c:\users so you don't interfere with other students' work. These instructions were designed for Windows NT and the computers in room MIB 111. If you are working in a CIS Lab, replace all references to the directory c:\users with c:\temp. These instructions may vary from one lab to another, and programming software is occasionally modified; please ask your TA for assistance if something doesn't quite work right and you've given a decent effort to figure it out on your own. No matter how much programming experience you have, learning a new environment can be time-consuming and frustrating. The Borland IDE is a large, complicated system. It might take time for you to get used to it. Creating a new ProjectThe IDE manages a program as a project. Starting a new project requires several steps:
Running the programThere are two ways to run the program: from within the IDE, or from a command-prompt. We'll do both.To run it from within the IDE, pull down the Debug menu, and select Run. Watch carefully! You will see it go through the compilation, link, and load phases very rapidly. The output window will then appear and disapeer almost instantly. The reason it goes away so quickly is due to the fact that the program doesn't do much. All it has to do is print a message. NOTE: You will see several messages pop up in the Message window at the bottom of the screen. The lines beginning with a yell exclamation point are known as compiler warnings which do not prevent your program from running, they are only there to alert you of things to be aware of. For this project, you should at least glance over them, but nothing else. If you get a syntax error you probably had a typo somewhere, just double-check that you typed the program in correctly. If you get a more serious error then something may be wrong with the compiler's configuration. Check with your TA. To get a better look at the output, we need to use a command prompt, which runs independently of Borland.
Closing the projectClose your project by selecting Close_Project from the Project menu. You should see the empty IDE again, just as when you started Borland initially.A more involved exampleNow we'll do something slightly more realistic. Use the steps above to create a new project, but this time call the project finance.ide. You will probably find that many of the selections you made earlier are still there, but you should verify them nonetheless.When it comes time to enter
code, use the following program instead. NOTE: You probably
will not understand much of this (you've seen some of it in the reading,
though). Don't worry, you will just type it in and run it, no need
(yet!) to understand all the details.
Make sure you have saved your work! Run the program a few times (you'll need to use a command-prompt window) and watch it work. Again, if you have any errors, you'll need to resolve them before you start your worksheet (this project is used in the worksheet). Breaking an executing programIt is often necessary to stop ("break") a program while it is running after you've seen something go wrong, or you've decided to stop before the program officially completes. To see how to do this, run the finance program in a command window, answer the first two questions, then hold down the control key (Ctrl) and then press the "C" key. You will often see this in print as: Ctrl-C. You'll see the program stop and you'll be sent back to the command prompt. If you did the same thing in a Borland execution window, you'd be sent back to the IDE. |
||
|
||
Two important skills a good Computer Scientist / programmer needs is first, the ability to find answers that are buried in mounds of documentation, and second, to be able to explore an environment and figure out how to do something based on intuition alone. Each lab will have a section like this with something in this category. Sometimes we learn the best information on accident, while looking for something else. Therefore, do not ask for help here! You've noticed by now that in the editor window the program has syntax highlighting. This is a nice feature that helps us to see the program more clearly (e.g., reserved words are in boldface). First, figure out how to turn off syntax highlighting. Take a look at the source code and notice how different (and plain) it looks. Turn syntax highlighting back on. Next figure out how to customize syntax highlighting. See if you can make strings be light gray (rather than blue). Take a look again at the text of your program, then go back to the customization screen and return it to blue. You may go about this by
either just surfing through the menus, looking through the online help,
or both.
|