Professional Documents
Culture Documents
A compiled language such as Pascal, C or C++ does not use line numbers. The
program execution is controlled by the sequence in which the statements are written.
Some means must be used to write the source code. Since the program is essentially
a large file of characters, it is text that can be written by any text editing type of
program, like a word processor.
Turbo C++ makes your program writing simple. You are provided with
considerably more than a compiler that translates your programs into machine code.
The Turbo C++ Integrated Development Environment - called IDE from now on -
provides a Text Editor, File Handler, Compiler, Debugger and many other
features all in one. Before you even consider learning anything about programming
in C++, you will first need to learn how to work with the Turbo IDE. If you have
never used a word processor, you will find an added benefit from learning computer
programming. You will learn text editing that can be used for other subject areas as
well. Take the time to read and study this chapter well. In the beginning, you will
need this material very frequently. If you are using another compiler, the same logic
applies. You will need to learn how to use the program environment that you are
using. This chapter explain Turbo C++, Version 3.0 IDE, because that is the IDE
that is currently used in the Richardson school district for beginning students.
You may also prefer to operate in a DOS environment and enter commands at the
DOS prompt. Perhaps your computer automatically boots up in DOS or you have
selected to exit windows and restart to operate in DOS mode. Either way, you now
need to type TC at the DOS prompt.
C:>TC
Right now, the mission is to learn computer science and using the Turbo C++ for
DOS version will make your life simpler in learning the majority of introductory
concepts. The biggest benefit is that the Turbo C++ for DOS environment is simpler
than the windows environment. Do not be confused. It is entirely possible that you
are right now sitting behind a computer running Windows 3.1, Windows 95 or
Windows 98. There is a major distinction between the operating system that you are
using and the C++ IDE. This means that you can run a C++ for DOS environment
as well as a C++ for Windows environment, both from a Windows operating
system. The point is that once you are inside the C++ environment, Turbo C++ 3.0
for DOS in this case, you are not really concerned with the larger computer
operating system.
You will find that rebooting is a common occurrence in learning C++. Students new
to computer science manage to find many creative ways to totally discombobulate
the computer system. In many cases the computer responds by throwing in the
towel and freezing up completely. The only next step is to do a complete "cold
boot" and try again. It only takes a few reboots in Windows95 to realize that this is
not an ideal learning environment. In Windows95, turning off the power for a cold
boot throws Windows95 in a "what-is-going-on-check-everything" check up
mode, which is even slower than normal booting up. You may prefer to run
programs in DOS mode in the early stages.
Let us assume that you have managed, by whichever system you are operating on, to
get into the Turbo IDE. The opening screen for Turbo C++ will now appear,
looking something like what is shown on the next page. Some variations may occur
in the display mode, depending on the type computer and monitor in use.
Do not be surprised if you do not see the "About" window in the center of the
screen. This display usually only shows up when you run Turbo C++ for the first
time. This screen is quite intimidating for the rookie Turbo person. There are lots of
words, many strange lines, odd looking arrows and symbols, and few suggestions
what to do next. Feel assured that this screen is bunches less intimidating than
almost any other C++ environment that you might encounter.
Relax, it will all make sense after you play with the different commands. Take it
one step at a time. Besides, in this chapter we will not even attempt to explain the
complete Turbo IDE. You can easily write a healthy book on all the many available
features. At this stage, our main goal is to get you functional and capable of writing
simple programs. When you need advanced features, feel assured that they will be
explained as you come to them.
Right now let us take a tour of the Turbo IDE. Before we can even start to discuss
what all of these selections do, you need to know how to get to them. The Turbo
IDE uses the very popular "window pull-down" approach. Now, this is a DOS
text-based program you are using, which means that these windows are text
windows. This means that they do not look as fancy as the GUI (Graphics User
Interface) windows you see on the MAC, Windows 3.1 or Windows95 operating
system or "for Windows" applications. Fancy or not, our text windows work just
fine. One nice benefit is that you will never have to wait. Text is very fast.
File Edit Search Run Compile Debug Project Options Window Help
╔══[]═══════════════════════════ NONAME00.CPP ════════════════════════1═[]═╗
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚════════1:1═════════════════════════════════════════════════════════════════╝
F1 Help F2 Save F3 Open Alt-F9 Compile F9 Make F10 Menu
Now before we move on, you need to realize is that practically everything you do
can be done with key strokes or with the mouse. This is quite tedious in the
explanation department. It would be simpler to stick to either the mouse or to key
strokes, but most people like efficiency. The truth is that for some situations the
mouse is better and for other situations, key strokes are better. People also have
preferences, some folks prefer a mouse for everything, others prefer key strokes for
everything, and the third group goes back and forth. Take your pick. It is your
computer, your program assignment, and your business. If it works, and you are
comfortable with a given approach, use it.
Please do not get confused, in each situation you will be given both the mouse
approach and the key stroke approach. Do one, or the other, but not both.
The Menu Selection Bar offers many options that are available in the
Turbo IDE. You can use the mouse and click on any selection to open up a
window. You can also press the <F10> key. This does not open any window,
but it does move the highlighter to the menu bar. With the arrow keys, you can
move the highlighted selection around.
When you press the <Enter> key, the highlighted selection will open a
window. Once you are at the menu bar you can also press any red letter,
like O for Options and the options window opens up. Keep in mind this
does not work from the edit window. In the edit window, pressing the
letter O will get you the letter O nicely displayed on the screen.
From the edit window, you can instantly open a window with key strokes.
Press <Alt-F> and you will open up the File window. Press <Alt-C> and
you will open the Compile window. In general, the <Alt> key plus the
highlighted letter of any selection bar item will open up that window. The
example below shows the File window opened, by whichever method you
selected to use.
When you open a window, the first selection in the window will be highlighted. In
this case, that means the New selection. The highlighted item is briefly explained at
the bottom of the screen. In this case, it states Create a new file in a new Edit
window. Move the highlight bar up and down with the arrow keys. You will find
that the message at the bottom changes. Do not use the mouse for this exercise.
Some of the selections in the window show three dots after the name, like selection
Open ... F3. The three dots signify that an additional window will open up. In
other words, pressing Save or Quit requires no further selections or decisions, but
selection Open or Change dir... means that you are not finished yet with your
current choice, and you need to make additional choices from other windows that
have not been opened yet.
If you have followed the chapter examples, you should now have the File window
open. If the file window is not open, use whichever method you prefer. With the
file window opened - and no other actions performed - the New selection should be
highlighted.
You will notice that the bottom-left corner of the screen indicates:
F1 Help. Pressing the F1 key gives more detailed help than you get from the bottom
line. For example, highlight Change dir... by moving the highlight bar with the
arrow keys. By the way, using the mouse to select or pressing the highlighted letter
automatically opens up the next window. This is efficient and desirable when you
make selections, but right now we need to make a point. So Change dir... is
highlighted. Now press the <F1> key and you should get the screen display that is
shown on the next page.
The on-line help feature in the Turbo IDE is very powerful. Basically, you have a
reference manual available right on the screen. It amazing how much you can learn
by playing around with the different selections and checking the help windows. This
chapter will not even come close to explaining all the available features. The mission
of this chapter is to get you started and to teach you how to learn more on your own.
There is no better teacher than the person who is learning. Teachers, instructors,
professors, text books exist to guide students and give them the best tools available
so that students can teach themselves.
For this next discovery exercise, you need to be in the Turbo IDE edit window. If
the cursor is blinking in the large window, you are there. If any window is opened
up, press <Esc> and you will be in the edit window. If the edit window is split,
press the <F5> key to maximize the window or click on the up arrow in the right
top corner to achieve the same result with a mouse.
Right now you know pitifully little about Turbo C++. This chapter makes no effort
to teach you programming in C++ or any other language. The goal here is to use the
Turbo IDE. Now, one important feature of the IDE is to help you understand the
programming features of C++. Any programming language, like C++, has
keywords that have special meaning to the computer. Such keywords must be
Chapter III The Turbo C++ IDE 3.9
spelled correctly, used in the right context and include other special information. All
this keyword business is also provided with on-line help. You can type a keyword
anywhere in the edit window. Make sure that the cursor is somewhere on the word,
and press <Ctrl-F1>. This is a little different. Pressing <F1> gives help with any
highlighted selection in the IDE. Pressing <Ctrl-F1> provides help with any
"cursor-indicated" keyword in the edit window. For now go ahead and type if.
Make sure that the cursor is on the word and press <Ctrl-F1>. You should be
seeing a help window like the one shown below.
File Edit Search Run Compile Debug Project Options Window Help
╔══[]═══════════════════════════ NONAME00.CPP ════════════════════════1═[]═╗
║ ║
║ ║
║ ╔════════════════════ Help ═══════════════2═════╗ ║
║ ║ ║ ║
║ ║ if (keyword) ║ ║
║ ║ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ║ ║
║ ║ ║ ║
║ ║ Conditional ║ ║
║ ║ ║ ║
║ ║ Syntax: ║ ║
║ ║ if ( <expression> ) <statement1>; ║ ║
║ ║ if ( <expression> } <statement1>; ║ ║
║ ║ else <statement2>; ║ ║
║ ║ ║ ║
║ ║ If <expression> is non-zero when evaluated, ║ ║
║ ║ <statement1> is executed. ║ ║
║ ║ ║ ║
║ ║ In the second case, <statement2> is executed ║ ║
║ ║ if the expression is 0. ║ ║
║ ╚═══════════════════════════════════════════════╝ ║
║ ║
║ ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
F1 Help F2 Save F3 Open Alt-F9 Compile F9 Make F10 Menu
Right now it is totally unimportant if you understand the explanation of the Turbo
C++ keyword if. What is important that you realize how help is available when you
need it in the future. Also keep in mind that many topics cannot be displayed on a
single window. In such a case, you can press <PageDown> for the next window or
you can click on the down-arrow shown on the scroll bar, located on the right side
of the window. Pressing <PageUp> will return you to the previous window or you
can click the up-arrow on the scroll bar.
In the event that you type a word incorrectly, or type a keyword that you think
exists, but is not part of C++, you will find that the help feature tries to find the word
closest to your choice. Type qwerty and see what happens with <Ctrl-F1>. Use
this help feature. You can discover many neat features.
Type TC, click on an icon, or do what it takes to get into Turbo C++
If the window is not maximized press <F5> or click the up-arrow.
Type A:\ in the directory name box. The cursor should be there already.
Press <Enter> you should be in the edit window now.
This change directory business is frequently forgotten. There are ways to bypass the
Change dir options on and especially the mouse users find ways to access files
without specifying the default directory. I promise you that failure to change to the
proper directory will be a guaranteed major headache in C++. I have seen students
suffer for a long time with non-working programs that were written perfectly. The
only problem was working in the wrong directory.
The problem with changing directory is that it is not significant for the initial
programs. This makes you wonder what the fuss is about. Your own shortcut
method works; it is shorter; it is simpler; why bother? A couple months down the
road you are now totally habitualized into doing it the wrong way, precisely at the
time that it will hurt the most. There are only two approaches. You will have to do
the change directory business at some point. You can develop good habits now or
experience much frustration at some later point.
Why is this so important? That is a problem at this stage. You do not have the tools
to understand what is happening. Please have faith. Trust your teacher, trust this
book and go along. It will be helpful.
Press the <F3> key or first click on File, then click on Open.
Chapter III The Turbo C++ IDE 3.11
The Open a File window will now be displayed.
If you had previously created a file you could select it now.
However, this is your first time so the window should be blank.
If your diskette contains some files, they may also show up.
Type PRACTICE in the Name box and press <Enter>.
You will notice that the NONAME00.CPP at the top-center of the edit
window is now changed to \PRACTICE.CPP. Turbo C++ automatically
adds the .CPP extension if no extension is specified.
The cursor is located at the top-left corner of the edit window at Row 1,
Col 1. The cursor position is located near the bottom where it shows 1:1.
The screen should have the following appearance:
File Edit Search Run Compile Debug Project Options Window Help
╔═[]════════════════════════════ \PRACTICE.CPP ═══════════════════════1═[]═╗
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚═════════1:1════════════════════════════════════════════════════════════════╝
F1 Help F2 Save F3 Open Alt-F9 Compile F9 Make F10 Menu
Now type a few lines of text in the edit window. Use normal typing skills
and press <Enter> at the end of each line. The Turbo IDE text editor does
not wrap around the way a word processor does. This is an intentional
feature since the text editor is specifically designed to edit C++ programs.
It will make sense later that you do not wish to "wrap around." Your
screen should match the screen shown on the next page.
File Edit Search Run Compile Debug Project Options Window Help
╔══[]═══════════════════════════ \PRACTICE.CPP ═══════════════════════1═[]═╗
║The quick brown fox jumps over the lazy dog. ║
║Now is the time for all good students to learn C++. ║
║This text editor has features that were originally ║
Chapter III The Turbo C++ IDE 3.12
║developed for the popular Wordstar editor back in ║
║the early eighties. ║
║ ║
║Do not be surprised if some words are automatically ║
║highlighted. Turbo C++ displays all C++ keywords in bold. ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚═════════9:1════════════════════════════════════════════════════════════════╝
F1 Help F2 Save F3 Open Alt-F9 Compile F9 Make F10 Menu
When you are done, make sure that the cursor is on the line following the
last written statement, and in column 1. This is an important habit that
will make future assignment printing much simpler.
Now move the cursor to Row 1, Col 1 on the letter T of word The.
Check the size of your cursor. It is small and skinny. Press the
<Insert> key. The cursor should now be very tall covering the entire
letter T. If your cursor was already big, leave it alone.
Press the letter Q for about 20 letters. You will note that everything below
the Q disappears and is "over written" by the letter Q. You are right
now editing in the so-called "over write" mode. The cursor size indicates
which writing mode the text editor is in.
Press the <Insert> key again. The big cursor should now be small again.
Move the cursor to Row 2, Col 1. This time press a bunches of Zs. you
will notice that the text moves away. You are in "insert mode." Press
<Enter>. You have just inserted a CrLf or Carriage Return, Line Feed.
The <Insert> key toggles between insert mode and overwrite mode.
Deleting Characters and Lines
Delete the word features by pressing the <Delete> key. You will notice
that the letter directly underneath the cursor is deleted. Text to the right
side of the cursor moves to the cursor.
Now press the <Backspace> key until the words has and editor disappear.
This time the characters to the left of the cursor are deleted. Everything
to the right stays intact and the left side gets munched. Be aware of this
difference. It is very significant.
A note to Mac users. This feature will seem strange to you because the
Mac does not have a dual delete key feature. To help you somewhat with
the confusion the Mac <Delete> key behaves in the same manner as the
PC <Backspace> key. Actually, if you are a Mac user, this chapter will
be more than a trifle difficult. Turbo C++, Version 3.0 does not operate
on a Mac computer. You will need to get some compiler like
Code Warrior by Metroworks to compile your programs.
Please do not take the time to delete every single character when you need
to delete an entire line. Right now place the cursor somewhere on the line
that starts with Do not be surprised and press <Ctrl-Y>. Presto, the
entire line has been deleted. You will find that Y deletes lines as well as
blocks. It is tough to remember Y for delete. Think of Y as Yank out.
Did you think we forgot the mouse? Not really. Your mouse clicker can
click, drag, a word, a line or a paragraph. Now using the <Delete> key
or the <Backspace> will not remove the highlighted part. Click the Edit
window open and then click on Clear and the deletion is complete.
Personally, I think that the mouse is slow is this case. For large blocks it
is a different story, but not the small stuff. What is faster than a quick
<Ctrl-Y> to delete a line or pressing <Delete> to remove a character?
You may be surprised at this section. You were moving around just fine.
The trusty arrow keys make the cursor go anywhere you wish. This is
Chapter III The Turbo C++ IDE 3.14
true, but the cursor only moves one row or one column at a time. This can
be very tedious if your file is 2000 lines long. There are a few short cuts
that will make your cursor move faster.
Place the cursor somewhere in Col 1. The row does not matter, as long
as there is some text on that line.
Now press the <End> key and watch the cursor jump to the end of the
line. Press the <Home> key and the cursor jumps to the beginning.
Move the cursor with the up-arrow to the first row. You will only see 25
lines on the screen. A large portion of the file is hidden.
Press the <PageDown> key several times until you are at the last line of
the file. Now press the <PageUp> key until you are back at line 1.
You want faster? We have faster. Press <Ctrl-Pagedown> and watch the
cursor instantly jump to the end of the file. Press <Ctrl-PageUp> and the
file jump to the top of the screen.
If you followed the earlier directions, your file already has the name
PRACTICE.CPP. Saving becomes easy now. You can open the File
window with <Alt-F> and then press S to Save the file.
You can also click the File window open and then click on the Save
selection, but the quickest method is to use a "hot Key." You will notice
in the File window that next to Save there is an <F2> key. From
anywhere in the edit window you can press the <F2> key and your file
will be saved with the current name on to the current default drive.
It is possible that you did not specify a name at the beginning. You are
not interested in saving a file with the C++ default name of
NONAME00.CPP. It is also possible that you have a name but you wish
to change the name. The reason does not matter. Select Save as... to save
the file with a different name.
You have done well. Imagine that it is the end of the day, the end of the
period or the end of your computer session. The time has come to exit out
off Turbo C++ properly.
Make sure that your diskette is still in drive A and press <Alt-X>, which
is the quick key combination to exit the Turbo C++ IDE.
You can also click on the File window, followed by clicking on the Quit
selection with your mouse.
Sometimes it is not possible to exit the IDE. Turbo gives you a warning
message, such as the one shown below.
File Edit Search Run Compile Debug Project Options Window Help
╔═[]════════════════════════════ \PRACTICE.CPP ═══════════════════════1═[]═╗
║The quick brown fox jumps over the lazy dog. ║
║Now is the time for all good students to learn C++. ║
║This text editor has features that were originally ║
║developed for the popular Wordstar editor back in ║
║the early eighties. ║
║ ╔═══════════════ Message ══════════════╗ ║
║ ║WARNING: ║ ║
║ ║ \PRACTICE.CPP ║ ║
║ ║ not saved. Save? ║ ║
║ ║ ║ ║
║ ╟──────────────────────────────────────╢ ║
║ ║ ║ ║
║ ║ Yes No Cancel ║ ║
║ ║ ║ ║
║ ╚══════════════════════════════════════╝ ║
║ ║
║ ║
╚═════════9:1════════════════════════════════════════════════════════════════╝
F1 Help F2 Save F3 Open Alt-F9 Compile F9 Make F10 Menu
It is quite possible that you did save your file. You may even think that
the computer is so incredibly stupid. The answer is quite simple. You
wrote the text; you saved the file, and then you made a tiny change.
Perhaps you altered or added one single character. It does not matter how
tiny the change. Any change whatsoever since the last time that you saved
the file will generate the warning message.
At Berkner High School we want to keep the Turbo C++ IDE the same for
everybody. There are many options to customize the IDE. You can
change colors, change font size and give special boot-up instructions.
Such special options are stored in several files that Turbo C++ looks at during start
up time. We have locked these files to prevent them from being altered. This
way students can customize their IDE, do their thing, and when the bell
rings and they lack the time to change everything back, not to worry. Exit
Turbo C++ and the next person will start fresh. Turbo C++ will attempt to
save current settings. It is possible that you get an error message such as the
one shown below.
File Edit Search Run Compile Debug Project Options Window Help
╔══[]═══════════════════════════ \PRACTICE.CPP ═══════════════════════1═[]═╗
║The quick brown fox jumps over the lazy dog. ║
║Now is the time for all good students to learn C++. ║
║This text editor has features that were originally ║
║developed for the popular Wordstar editor back in ║
║the early eighties. ║
║ ╔════════════════ Error ═══════════════╗ ║
║Do not be surprise║ ║ ║
║highlighted. Turb║ Can't create ║ ║
║ ║ ║ ║
║ ║ D:\TC30\BIN\TCDEF.DSK ║ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ ┌──────┐ ║ ║
║ ║ │ OK │ ║ ║
║ ║ └──────┘ ║ ║
║ ║ ║ ║
║ ╚══════════════════════════════════════╝ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚═════════9:1════════════════════════════════════════════════════════════════╝
F1 Help F2 Save F3 Open Alt-F9 Compile F9 Make F10 Menu
Ignore the error message. Press <Enter> to continue and exit or click on
the OK button and you are on your way.
You did not realize this but it is now the next day.
Time just flies in the computer lab.
We now have a different situation. This time you are not creating a text
file from scratch. You want to continue with the file that you created
yesterday. Remember, the one saved as PRACTICE.CPP. Let us see if
you can load that file correctly.
Put your diskette in drive A and get into Turbo C++. Make sure your
diskette is the one that contains the file you saved. This is no problem
with the exercise we are running. You did not go anywhere and neither
did your diskette. However, very soon you will be going from lab to class,
to your locker, to home and back again. There will be many opportunities
to switch diskettes, to forget diskettes and in general not to be prepared.
Open the File menu with <Alt-F> or by clicking on the File name.
Remember, you must always change to the proper drive and/or directory
where your files are located. Press C for Change dir or click on Change.
In the Directory Name box type A:\ or other appropriate directory.
Press the <F3> key to open the "Open a File" window or click on File,
followed by a click on Open. You now have two options. You can actually
type the name of your file in the Name box, where the cursor is waiting or you
can select one of the files in the Files window below. Personally, I think it is
a good habit to select from available files.
You do not always remember what you called a file, and you also have the
opportunity to make typing errors.
Unless you specify something different, you will notice that the Name
window displays an *.CPP file name. This is the default action and the
Chapter III The Turbo C++ IDE 3.18
files displayed in the lower Files window all end with extension .CPP. Let
us assume that your file does have the usual .CPP ending.
Press the <Tab> key. The cursor will jump from the Name window to the
Files window and highlight the first file name. You can use arrow keys
to highlight the desired file and press <Enter> to load the file in memory
and show it in your edit window. Mouse users can double-click on the file
name to achieve the same result.
Sometimes students see nothing on the screen. The file name is correct at
the top of the edit window, but the file is empty. Usually, students will
swear to everything that is holy that they did write the required
information, they did save it properly and now the file is empty. This is
quite normal for beginning students. Most teachers, including myself, have
few answers for such occurrences. New students have unique skills that
they lose rapidly. These unique skills include the ability to make the
computer perform in a manner that no experienced computer person can
duplicate. Whatever, mysterious actions are performed by students it is
always done away from the teacher's eye. The evidence of the wrong
action is apparent, but the actions are the mystery. Usually, the best advice
is to repeat the correct steps. In most cases, you will get the desired result
on the second try.
There sure are bunches of ways to work with text blocks. In word processing lingo
this usually means "cutting and pasting." This skill is vital for efficient program
writing. You will frequently encounter situations where it is very desirable to copy a
section of code that needs to be repeated elsewhere. It is also possible that you have
a correct program segment, but it is in the wrong location and it needs to be moved.
There are many reasons, and there are many ways to perform these important
actions.
The second letter of the keystroke indicates the nature of the block command, and
this letter is a logical letter in most cases. Consider the following (incomplete) set of
block commands:
Press <Ctrl-KB> to mark the beginning of the block. Make sure that you
press the <Ctrl> key first. Nothing will happen as a result of this first
action.
The mice people are getting anxious. You sense a distinct prejudice here.
Why are the keystrokes always mentioned first and the mouse actions
shown last? The answer is simple. Mr. Schram wrote this book - and
quite weird, he sometimes writes about himself in the third person - and
he prefers keystrokes and therefore mentions them first. However, the mice
people are not ignored, but they do come second. Anybody, who does not
like this approach is cordially invited to write his or her own book and
explain mouse business first.
Perhaps many mice people will argue that the use of the mouse is so
intuitive that little explanation is necessary. The keystrokes on the other
hand, are not exactly so easy to learn without instruction.
Cut and Paste is almost the same. The only difference is that you click
on the Cut command, rather than the Copy command.
Deleting a Block
You can delete a block with <Ctrl-KY>. The only way I can easily
remember this is that Y stands for Yank. The command is consistent.
You delete a line with <Ctrl-Y> and an entire block with <Ctrl-KY>.
With the mouse you need to open the Edit window and click on the Clear
command.
Turbo C++ is very particular about the "current" or "default" directory. You will
realize later why this is so important. Earlier in this chapter we changed the current
directory to A:\. This was nice and simple, but frequently directories can be deep
inside a complex directory tree structure. The Turbo IDE gives you several options
to help you navigate to the right location. Imagine that you have opened the
Change Directory window and it looks like the one below.
File Edit Search Run Compile Debug Project Options Window Help
╔══[]═════════════════════ D:TC30\BIN\NONAME00.CPP ═══════════════════1═[]═╗
║ ║
║ ║
Chapter III The Turbo C++ IDE 3.21
║ ╔═══════════ Change Directory ════════════════╗ ║
║ ║ ║ ║
║ ║ Directory Name ║ ║
║ ║ ┌───────────────────────────┐ ║ ║
║ ║ │ C:\ │ ║ ║
║ ║ └───────────────────────────┘ ║ ║
║ ║ ┌────────┐ ║ ║
║ ║ Directory Tree │ OK │ ║ ║
║ ║ ┌──────────────────────────┐ └────────┘ ║ ║
║ ║ │ Drives │ ║ ║
║ ║ │ C:\ │ ┌────────┐ ║ ║
║ ║ │ └┬─CDROM │ │ Chdir │ ║ ║
║ ║ │ ├─DOS │ └────────┘ ║ ║
║ ║ │ ├─DRIVERS │ ║ ║
║ ║ │ ├─NAV │ ┌────────┐ ║ ║
║ ║ │ ├─NCDTREE │ │ Revert │ ║ ║
║ ║ │ ├─NWCLIENT │ └────────┘ ║ ║
║ ║ │ ├─PLUGPLAY │ ║ ║
║ ║ └────┴─────────────────────┘ ┌────────┐ ║ ║
║ ║ │ Help │ ║ ║
║ ║ └────────┘ ║ ║
║ ╚═════════════════════════════════════════════╝ ║
║ ║
╚═══════ 1:1 ════════════════════════════════════════════════════════════════╝
F1 Help │ Use cursor keys to navigate through directory tree
If you know the precise path, from root to final subdirectory, you can type that in the
Directory Name box. But for now let us assume that you do not know the exact
path. For starters assume that you are not even in the correct drive. We want to
change to drive E:\.
Type E:\ in the Directory Name box and press the <Tab> key. Do not press
<Enter>. Pressing <Enter> will change the current drive to E:\, but it will also
close the window and assume you are done. When you press the <Tab> key the
Directory Tree window changes and appears like the one shown on the next page.
To save space, only the Change Directory window is shown. Imagine that the
window fits inside the larger Turbo C++ IDE window.
In this case I am trying to find some CPP files that I am using for some assignment.
The directory is not always alphabetized, as it appears. I need to use the arrow keys
to see the rest of the selections. I stop when I see BOOKS. My files are located
somewhere in there. The window now looks as follows:
As before I need to scroll down to get to the desired subdirectory, which in this case
is SF-BOOK1.CPP, and then press <Enter>.
There seems to be no end to these subdirectories, because we have not reached the
end yet. There are more subdirectories at the lower level, which are shown below.
Highlight DEMOS1.CPP and press <Enter>. What a surprise, there are more
subdirectories. You may think that this is a phony demonstration, but in fact, a real
hard drive was used. You are looking at the subdirectories of the hard drive that I
used when I first wrote this chapter. This is a realistic example and helps to explain
why it is not always easy to type in the entire path from root to final subdirectory.
We will go through the same steps, but now use a mouse. It will not be
necessary to show most of the windows. They are identical after the
change to the new drive.
Many people prefer to use a mouse for this changing directory business.
It can be confusing without a mouse. There are times when you use
<Tab>, there are times when you need to move <Arrow keys>, and there
are times when you press <Enter>. Do you know which one?
Here are the mouse steps to get to the same subdirectory, which by the way has the
following path:
E:\BOOKS\SF-BOOKS1.CPP\DEMOS1.CPP\MOREBASC.C03\
Click on File and Change dir to open the Change Directory Window
Now double-click on E: and you have the same menu that was shown
earlier with the key stroke method.
Click on the down arrow at the bottom-right corner of the Directory Tree
window to scroll the directories upward until Books appears.
Click on the OK button accept and exit the Change Directory Window.
Press the <F3> key and the Open a File window opens up. The normal
default are files with *.CPP extensions and those will be the only files
shown. You will see something like:
If the file you need shows in the Files window, use the arrow keys to
highlight the desired file and press <Enter>. This will load the file in the
edit window.
You can also double-click on the file name to load the file in the edit
window. Perhaps you are a single-click kind of person. That works too.
Single-click on a file name to select the file, and then single-click on the
Open button to load the file in the edit window.
Frankly, I am not sure why the Open button exists. You do not need it for
the key stroke method, and you do not need it for the mouse method.
However, it is good for impressing friends if you want to show more steps
to do less work.
Normally, your C++ files will have an .CPP extension, but at times that
is not the case. You may open up the file window and the desired file
does not appear. Not to worry. Change the *.CPP default in the Name
box to *.* and all the files at that location will show up. It will give this
type of appearance.
What if your file still does not show up? Well, there are two possibilities. One, you
are in the wrong subdirectory, and you need to search elsewhere. Two, you did not
save your file, or at least you did not save it with a name that you are able to
recognize.
One final warning for this section. It is tempting to load a file by skipping the
Change Directory Stage. You could type something like:
E:\DATAFILE\LABEXR01.CPP
That method may work, at least it may work in the beginning, but please listen
carefully. Never, never, never, type any directory path in the Name box of the Open
a File window. It will give you headaches.
Everything shown up to this point has revolved around using the Turbo IDE for
editing and filing purposes. Nothing has required writing, compiling, or running any
type of program. In this section we will write a small program. No attempt will be
made to explain any of the C++ program logic or requirements. The main purpose
of this section is to show you the steps necessary to edit, save, compile and run a
program. Many of the previous sections have been unrelated. We will now take
you through a complete program sequence by the numbers. We will assume that
you are at a DOS prompt or in a Windows environment.
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
cout << "THIS IS YOUR FIRST PROGRAM" << endl;
cout << endl;
cout << "PRESS <ENTER> TO RETURN TO TURBO" << endl;
Chapter III The Turbo C++ IDE 3.29
getch();
}
[04] Save the file as FIRST.CPP. Have patience with the computer. You may
have a fast computer, but file operations with a floppy diskette are
notoriously slow.
[05] Compile the program with <F9>. A Compiling window will show on the
center of the screen. At the bottom of the window it should say Success
and Press any key should be blinking. It is also possible that the window
says Errors at the bottom. Go ahead and press the space bar. An
error message window will show up and other weird stuff will happen. Press the
<F6> key to return to normal editing. Toggle the <F5> key to maximize the
edit window. Check your text carefully. Something was not copied
correctly.
[06] If your program compiles correctly, you are ready to run the program and
see the output. Press <Ctrl-F9>. The program will go through the same
steps as compiling earlier, and then you should see the following message
on the screen.
┌──────────────────────────────────────────────┐
│THIS IS YOUR FIRST PROGRAM │
│ │
│PRESS <ENTER> TO RETURN TO TURBO │
│ │
└──────────────────────────────────────────────┘
IMPORTANT NOTE:
It may be that you have done everything correctly and the program does
not work correctly. There are a variety of Turbo C++ files that have to be
found. It is possible that the Turbo IDE needs to be altered slightly to
indicate where those files are.
Sounds confusing? It is, and the point is that you probably need to call
your teacher or somebody with greater knowledge to check what is wrong.
At this stage, you can only check a careful line by line comparison to
make sure that you copied the files correctly.
For this exercise start by writing two separate files with names FILE1.CPP and
FILE2.CPP. Write each file and save it when you are done. Create the following
files.
┌─────────────────────────────────────────────────────┐
│This is File1.CPP │
│Kathy Coleman │
│1234 Main Street │
│Dallas, Texas 75240 │
│ │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│This is File2.CPP │
│Tom Terrific │
│4321 Elm Street │
│Richardson, Texas 75080 │
│ │
└─────────────────────────────────────────────────────┘
After the two files are created, and saved, exit Turbo with <Alt-X>. This is done to
make sure that everybody has the same screen appearance.
Turbo C++ can deal with many files simultaneously. For now we only want to work
with the two files that you have just created. Load FILE1.CPP in the edit window,
and then load FILE2.CPP. You should get the following screen result.
File Edit Search Run Compile Debug Project Options Window Help
┌───────────────────────────────── \FILE1.CPP ─────────────────────────1─────┐
│╔═══════════════════════════════ \FILE2.CPP ═════════════════════════2═[]══╗
│║This is File 2 ║
│║Tom Terrific ║
│║4321 Elm Street ║
│║Richardson, Texas 75080 ║
│║ ║
│║ ║
│║ ║
│║ ║
│║ ║
│║ ║
│║ ║
Now your two edit windows are cascaded. You can tell there are two files because
each file has a number, you can see both file names, and you see two file borders on
the screen. However, copying blocks between the two files is not very practical. The
easiest way to change between the two screens is by toggling the <F6> key. Open
up the Window window with <Alt-W> or click on Window.
Press T for Tile or click on the Tile command. You will now have two windows
side by side for viewing, and block copying convenience. The appearance is like the
example on the next page.
File Edit Search Run Compile Debug Project Options Window Help
┌────────────────────────────────────────────────────────────────────────────┐
│┌──────────── \FILE2.CPP ───────2─────┐╔═[]═══════ \FILE1.CPP ═════1═[]═╗│
││This is File 2 │║This is File 1 ║│
││Tom Terrific │║Kathy Coleman ║│
││4321 Elm Street │║1234 Main Street ║│
││Richardson, Texas 75080 │║Dallas, Texas 75240 ║│
││ │║ ║│
││ │║ ║│
││ │║ ║│
││ │║ ║│
││ │║ ║│
││ │║ ║│
││ │║ ║│
││ │║ ║│
││ │║ ║│
│└─────────────────────────────────────┘╚═══════════════════════════════════╝│
└────────────────────────────────────────────────────────────────────────────┘
F1 Help F2 Save F3 Open Alt-F9 Compile F9 Make F10 Menu
You will notice that one of the screens - FILE1.CPP - is highlighted. The file name
is in bold, the edit window has a double-line border.
Chapter III The Turbo C++ IDE 3.32
You can toggle between the two screen by repeatedly pressing the <F6> key. You
will notice that the highlighting switches. With the mouse you can click anywhere
in the "non-highlighted" screen to make it the current edit screen.
Working with a larger edit window is easy without losing the second file.
Press the <F5> key any you will see the current file maximize to the entire screen.
Press the <F5> a second time and you are back in the Tile display.
With a mouse you can click on the up-arrow in the current screen, which will
maximize the screen. Clicking on the up/down-arrow will minimize the screen
back to Tile display.
Now we will copy Tom Terrific's address to FILE1.CPP.
Please be aware that the copy (<Ctrl-KC>) and the move (<Ctrl-KV>) shortcut
commands are block commands that only work within a file. You will need to use
the Edit window to copy between files.
In this section we will not list all the hot keys commands. It is lovely to supply you
with a complete list, but this book is meant to teach as a tutorial and not be a
reference guide. You will see many, many key strokes on the Turbo IDE that were
not explained, and are not mentioned here. Remember, that this chapter will not
attempt to explain the entire Turbo IDE. You can satisfy any curiosity by
highlighting a command and reading the <F1> help window.
<F3> Allows quick loading of a file from the Open a File window
<F9> Compiles your program into an *.EXE file. <F9> will not
compile a program if a current compiled file exists.
Block Commands
There are also many other key strokes, that you will see on the Turbo IDE that have
not been mentioned. Again, remember, this book is meant to be a practical learning
guide for you, not a complete reference manual.
There is one important topic that is difficult to insert in this book. It is the type of
thing that should belong in an appendix. My concern is that you may get into
trouble and not think of looking for answers in some obscure appendix. Read the
section that follows, and try the exercise. Try not to figure out what is going on.
This section is here to make you aware of an important feature that may be needed
some time in the future. When it happens, hopefully a light bulb will go up and you
will jump back to this section.
Do you have a clue what is going on? Of course not, absolutely nothing has been
explained. This is part of the student friendly approach. Tell somebody nothing and
they will not be confused. Student friendly or not, a brief explanation will be
attempted to trigger your memory for later needs.
Proper memory management is a major problem for program compilers like C++.
Different parts of the program require different chunks of a small, finite quantity of
memory. If the wrong amount of memory is allocated to some program feature
called a stack, you may find that your program will crash. Now keep in mind that
nothing is wrong with your program. You did your job, but your program cannot
function without the proper memory allocations. The understanding of these
different memory needs is way beyond the scope of the current chapter. However,
try the following analogy. Imagine that 250 students need to fit in 10 classrooms,
which each holding 30 desks. At first glance, everything seems fine and there
should be no problem. But there is a problem because 100 students are part of the
band and need a classroom large enough to hold all 100 students at once. In this
case the school space is not allocated properly.
Use the <Tab> key to move around the Code generation window, and the <arrow>
keys to move up and down the memory Model selection box. Stop at the desired
memory model and <Tab> to the <OK> button and press <Enter>. Mouse folks
have an easier job here. Click on the desired memory model and on <OK> and you
are done.
The computer lab you are using may be set up to prevent permanent changes of
certain file configurations. If that is the case you may need to make this change
whenever it is needed. If your computer does not have file configuration protection,
you will have the same memory model for future use.
3.12 The Turbo C++ Selection Menu
We will finish this chapter with a brief overview of the different selections on the
Main Turbo Selection Menu Bar. This is not an explanation on how to use
various features, but rather an awareness of some of the available options. The
selections will be listed from left to right, as they appear on the menu bar.
File Window
Edit Window
Chapter III The Turbo C++ IDE 3.37
Used for editing features such as:
Undo latest editing command
Cut and paste a text block
Copy and paste a text block
Delete a text block
Search Window
Run Window
Used to:
Run entire program in the edit window
Trace through a program execution
Run part of a program
Compile Window
Used to:
Compile the program in the edit window
Create a DOS *.EXE program file
Link different programs together
Provide information statistics about a program
Debug Window
Project Window
Options Window
Window Window
Help Window
I think that the Turbo C++ for DOS, version 3.0 is absolutely wonderful for teaching
computer science to introductory students. The integrated development environment
is the simplest around and students require minimum "start-up" time to learn how to
use the editor and compiler.
Another benefit is that it is very easy to load many program examples. You will find
that one teaching approach is to have you load one program example after another
into the editor, view it, run it and discuss it. This method is only practical if loading,
compiling and running can be accomplished with a minimum of difficulties. In this
area Turbo C++ 3.0 reigns supreme.
However, version 3.0 is an earlier and older version. This compiler was developed
before the C++ standard was even close to being finished. The result is certain later
features are not available and perhaps more troublesome, Turbo C++ lets you do a
few illegal maneuvers that should not be allowed in C++.
Now this is not a problem for the introductory student. The features in question do
not apply at all to anything students will encounter in the first semester and hardly
even during the first year. It is with advanced topics that the older compiler will not
be as beneficial as it was in the beginning. So do not be suprised if you need to learn
another compiler at some later date. For now this is mentioned for the benefits of
both teachers and students who look ahead, try certain things and find a few quirks
that do not add up properly.