Chapter 1 Computer Science w/ C++ Name: Guided Lab (v. 2.0) Mr. Ferwerda Using the Turbo C++ Integrated Development Environment (IDE) A. Entering Borland Turbo C++ 3.0: two methods: 1) From Windows, click on the Turbo C++ shortcut icon. 2) If the shortcut doesn t exist, from the Start Menu, choose the Run option and type: C:>\tc\bin\tc Once started, the Turbo C++ Integrated Environment opens up the desktop, and may open a new (or whatever was last used) program into the edit window, and/or open the message window in which compiler and error messages appear. It also contains a menu bar on the top of the screen, scroll bars on the right and bottom, and a status line at the bottom that shows keyboard shortcuts or other information about the menus. B. The Turbo C++ Integrated Debugging Environment (IDE) Window Close Box Menu Bar Edit Window Status Line Message Window Scroll Bars
Comp. Sci. w/ C++: Ch. 1 Turbo C++ IDE Guided Lab (v.2.0) page 2 C. Using the Turbo C++ Main Menu 1. To access the main menus from the menu bar (one of three methods): Alt (hold down) + first letter of menu F10 + first letter of menu mouse (put cursor on menu title and click the left mouse button) 2. Write down the options listed under each of the following menus: File Edit Run Compile 3. The Status Line Open the File Menu and look at the choices. What does the status line say when each of the following options are highlighted: New Open Save Save As Print DOS Shell D. The Edit Window 1. Use the New option under the File Menu to create a new program edit window. a. What is the name of the new program? b. Create another new program. What is its name? c. What do you notice about the way the edit windows of each of these programs are arranged? d. To close the edit windows, click the mouse on the green square in the upper left corner of each program's edit window. Close all the programs now. You should be left with a blank desktop.
Comp. Sci. w/ C++: Ch. 1 Turbo C++ IDE Guided Lab (v.2.0) page 3 E. Creating a New Program 1. Create a new program edit window, and then type in the following program exactly as is shown below, using the same indenting, capitialization, and spelling (with the exception of the first line, in which you need to put your name after the double slash): // Please type your name here // My First Program #include <iostream.h> int main() { cout << "Hello, there!\n"; COUT << "\n"; cout << "Welcome to Turbo C++\n" Cout << \n; cout < "Good Bye!\n; } return 0; 2. The program shown in the edit window is called the source code. As you type, notice that different words and symbols automatically appear in different colors. 3. Save the source code of your program on your auxiliary memory device by using either the File Menu or by pressing F2. (Be sure to save to your auxiliary memory, not the hard drive.) If using a floppy disk, name the file: A:\FIRST.CPP If using a flash drive, name the file: E:\Cfiles\FIRST.CPP (use E: or F: ) F. Compiling a Program 1. Compile the program to create the object code (the machine language version of the program). You can compile the program by using either the Compile option in the Compile Menu, or by pressing Alt + F9. a. What happened when you tried to compile the program? How many error messages did you received? (Be sure to use the message scroll bar to see all of them!) Write the first error message here: Write the second error message here: b. Fix the first error indicated by changing COUT to all lower case letters (at the beginning of second statement after the opening french brace - { - symbol.) c. Fix the second error indicated by putting a semi-colon at the end of third statement after the opening french brace.)
Comp. Sci. w/ C++: Ch. 1 Turbo C++ IDE Guided Lab (v.2.0) page 4 2. Try to compile the program again. What happened? How many error messages did you received this time? How many errors occurred on line 11? (Fix the errors by replacing Cout with cout (all lower case), and by putting quotes around the \n on the same line.) 3. Keep trying to compile the program until all of the errors are fixed. (HINT: look at the previous lines of code to see if you can fix the errors left there is only one more line that has some errors.) Record the corrected line of code below. (If you absolutely cannot fix the errors, please ask for help.) The program will be free of syntax errors when it says SUCCESS at the bottom of the compile window. Be sure to save your program again once it compiles successfully! Corrected line: G. Running a Program 1. To run the compiled program use the Run option under the Run Menu, or press Ctrl + F9. 2. Run FIRST.CPP now. a. The output goes to the user screen for a brief period of time, and then returns you to the edit window the user screen flashes up for only a moment. b. To see the user screen again, press Alt + F5, or use the User Screen option under the Window Menu at the right of the menu bar. What do you see on the screen? Pressing any key will then return you to the edit window. H. Toggling between Windows and Turbo C++ You can change the Turbo C++ to appear as a separate window on the Windows screen by typing Alt + Enter. This allows you to access other Windows programs, including programs like Notepad, as well as access to My Computer and the file structure of your auxiliary memory device. Please try it now. To return Turbo C++ to the full screen display, once again type Alt + Enter. I. Printing the Source Code on the Printer A hardcopy is a paper listing of your program's source code. Unfortunately, you cannot use the Print option of the File Menu in this computer lab. To make a hardcopy of FIRST.CPP, you need to open the file in Notepad, and then print it. (To access Notepad, recall what you did in part H. of this worksheet.) You will need to hand in this hardcopy with this worksheet when you are finished.
Comp. Sci. w/ C++: Ch. 1 Turbo C++ IDE Guided Lab (v.2.0) page 5 J. Changing the Directory from which you are working 1. To change the directory or disk from which you are working, use the Change dir... option of the File Menu. Right now, change the directory: If using a floppy disk, change directory to: A:\ If using a flash drive, change directory to: E:\Cfiles\ (use E: or F: ) Notice what happens to the file name at the top of the Edit Window it no longer shows the folder path with the file name. NOTE: This is a step you will ALWAYS do when you enter Turbo C++ from now on; it will prevent you from accidentally saving programs to the hard drive and instead save them to your disk or flash drive. 2. Now, rerun the program FIRST.CPP, and watch the light on the floppy drive or your flash drive. What happened?. Congratulations, you just created an executable version of the program on your disk! K. Loading in a Program from Disk 1. To load a program from your disk, use the Open option under the File Menu, or press F3. Try to load in the program GREETING.CPP from your disk now. Be sure that you are trying to load from the correct drive and folder; if not, be sure to change the directory by typing A:\ or E:\Cfiles\ and press the Enter key to activate the disk drive. Use the mouse or the cursor keys to highlight the correct file name, or just type the file name. 2. Try running the program GREETING.CPP without compiling it first. Describe what happened. 3. Close GREETING.CPP right now, so that the edit window for FIRST.CPP is again visible. L. Files on your disk 1. In the File menu, choose the Open option, and in the Name box enter: *.* This should show you the names of all the files on your disk. Write the names of all the files that are on your disk here: 2. You should notice that one of the files has an extension.bak. This is a backup version of the program from the previous time you saved it. The updated version gets the.cpp extension. 3. The other files have extensions of.obj (the object code) and.exe (the executable code)
Comp. Sci. w/ C++: Ch. 1 Turbo C++ IDE Guided Lab (v.2.0) page 6 M. Exiting Turbo C++ 1. To exit Turbo C++, use the Quit option under the File Menu, or press Alt + X. 2. Try exiting now. The computer may inform you that changes were made to the program FIRST.CPP. Tell the computer you wish to save the changes. This is a nice feature of Turbo C++ that helps you avoid losing updated programs. You should always exit Turbo C++ this way before turning off the computer s power. N. Using the DOS Shell 1. The DOS Shell allows the user access to DOS without having to quit Turbo C++ and close all program files. To shell out to DOS, use the DOS Shell option under the File Menu at the top of the screen. Use the DOS Shell now; this takes you to the command prompt. 2. Look at the directory for your auxiliary device; at the command prompt, type: dir a:\ or dir e:\cfiles\ You should notice a file called FIRST.EXE on the disk. This is the executable code that was saved on your disk when you last compiled the program FIRST.CPP. a. To run an executable program out of DOS, simply type the name of the program (the extension is not necessary) at the command prompt. If using a floppy disk, type: A:\FIRST If using a flash drive, name the file: E:\Cfiles\FIRST (use E: or F: ) What happened? b. Executable code is a nice feature of many high-level programming languages. It allows a person to run a program written in C++ (or Pascal, etc.) without having to have the C++ compiler. Most game or other application programs are written this way; only the executable code gets sold and cannot be changed by the user. c. A word of caution. It is best to compile a program to memory instead of disk, until the program is completely finished. This is because the executable code takes up quite a bit more disk space than the source code. 3. To get back into Turbo C++ from the DOS Shell, at the command prompt, type: exit This will return you to Turbo C++ with all the files open that were open when you shelled out to DOS. O. Finishing the Project You may now quit Turbo C++. Be sure to hand in: this worksheet with all the answers written down, and the hardcopy of the program FIRST.CPP that you made in section I of this worksheet.