The main purpose of this lab is to introduce you to the computing environment of your laboratory. You will use the ideas in this lab again and again throughout this course, so you should make every effort to understand not only what, but why you are doing what you are doing at each step.
Before we can begin our session, your instructor must inform you how to begin a session with the computer at your particular institution. The way this is done differs from school to school, according to the kind of computer being used, whether they are networked or stand-alone, whether a security system is in place, and so on. Among the things your instructor will tell you will be the answers to the following questions:
The distinction between typing something and entering something is as follows:
If you are not accustomed to using a mouse, take a few moments to practice pointing at objects on the screen.
Since you are reading this, you are presumably doing so using a software application called a web browser, such as Netscape or Internet Explorer. A web browser is an application that provides a GUI environment for exploring the World Wide Web, a network of computers from around the world linked together to share information. As you have (presumably) already discovered, a web browser lets you download information from remote computers simply by pointing the mouse at a link and clicking its left button.
In contrast to a GUI, there are environments in which you repeatedly:
In order to use a command-line environment, you must learn those commands that the environment "understands." This in general makes a command-line environment more difficult to use than a GUI, since you must be able to recall the right commands to use the system. By contrast, users of a GUI environment need only be able to recognize the proper menu choice, link, or icon they need to select in order to make something happen.
Let's begin by learning about the mouse. The left mouse button is usually used to select and open an object on the screen. Selecting an object is accomplished by pointing the mouse at the object and clicking once, opening is is similar, but requires a double-click (clicking the left button twice in rapid succession).
To illustrate, there is probably a tiny picture (called an icon) of a single computer labeled My Computer in the upper left corner of your computer's screen. (This is its default name and location -- depending on your local configuration, its name or position may be different.) Point the mouse at that icon and click the left mouse button. The icon should darken, indicating it has been selected.
Next, double-click while pointing at the My Computer icon, to open your computer. A new window should appear listing some of the storage devices that are inside your computer (e.g., a floppy drive named A:, a hard disk named C:, a CD-ROM named D: are common devices).
To select your browser window, just move the mouse over your browser and click the left mouse button. Note that the titlebar at the top of the window darkens (i.e., it turns blue on most machines) to indicate that the window is selected. If you click the left mouse button while pointing at your My Computer window, its titlebar darkens accordingly. Since you may have multiple windows on your screen at the same time, Windows darkens the titlebar of whichever window is currently selected, which is known as the active window.
One of the most common things people want to do with windows is reposition them on the screen. This is quite easy in Windows-95: just point the mouse at the titlebar of the window, hold down the left mouse button, and move the mouse until the window is where you want it. This is called dragging the window. Then release the left mouse button and the window will stay put (until you drag it somewhere else). This is called dropping the window. Dragging and dropping makes it easy to reposition a window.
Another common window-related task is resizing a window. Again, Windows-95 makes this easy: just point the mouse at one of the corners of the window until the mouse cursor changes from an white arrow to a diagonal two-headed arrow (called the resize cursor). Then drag the corner of the window in or out until it is the size you want. By dragging, dropping, and resizing you can arrange the objects on your screen according to your personal tastes.
In the upper right corner of every window are three buttons: one labeled with _, one labeled with a tiny window, and one labeled with an X. Click the _ button of your My Computer window, and you should see the window "collapse" into the task bar at the bottom or your screen. If you left-click on the rectangle labeled My Computer, the window will reappear. The _ button is sometimes called the minimize button, because clicking it shrinks the window until it is just an icon in the task bar at the bottom of the screen. Selecting that icon on the task bar returns the window to its previous position and size. Take a moment to try it with the My Computer window.
The button with the tiny window is the maximize button. Clicking it causes your window to enlarge and fill the entire screen, at which point the button changes to show two tiny windows. Clicking this button returns the window to its original size and position. Take a moment and try it with the My Computer window.
An alternative way to maximize a window is to double-click in its titlebar. Double-clicking in the titlebar of a maximized window returns it to its original size and position.
The final button in the upper right corner of a window is the X button which is called the close button. Clicking this button removes the window from your screen, terminating any program that was running within the window. You should use this button with caution, since any unsaved work (see below) is lost when a window is closed.
The right mouse button offers different options from the left button, usually allowing you to pull down a menu of options for the object at which the mouse is pointing. If you click it over your browser, you should see a menu with some choices, if you click it over your screen's background, you should see a menu with different choices. On this latter menu, note that some of the choices have a tiny arrow to their right -- if you move the mouse over that arrow, a secondary menu appears with more choices.
We will occaisionally use the right mouse button, but the left mouse button is used far more often. As a result, if we say "click the mouse button" without specifying which one, we will be referring to the left button. If we want you to click the right button, we will explicitly say so.
Before we explore, lets take a moment to make sure that your environment is configured in consistently with this exercise. While the customization in Windows-95 is convenient and user-friendly, covering every possible configuration is difficult and inefficient, so we will set up your environment to have a uniform look and feel.
Open (i.e., double-click) your My Computer icon. Then click on the View menu and make certain that selections Toolbar and Status bar both have check-marks beside them. If either of them does not, select it with the mouse, so that both of these features are enabled.
Next, select View -> Details to provide a detailed listing of the devices in your computer. This will provide more information than the other choices, including how much free space is available on each device.
Finally, select View -> Options and an Options dialog box will appear. Make sure the the File tab is selected in the box, and then make sure that the second radio button is selected:
Browse folders by using a single window that changes as you open each folder.This will help to avoid "screen clutter" by using a single window for navigation through your computer.
Ok! We're ready to explore! If you have a floppy disk, insert it into your computer's floppy drive, and let's get started.
At the top of the list of devices in the My Computer window should be 3-1/2 Floppy (A:) which refers to your floppy drive. Double-click on its icon or name and the window will change to display the contents of whatever disk you placed in the drive. Note that the title of the window changes to A:\, which is the short-name by which the system refers to your floppy drive.
To get "back" to your My Computer window, click on the small button that looks like a folder with an up-arrow inside it. This button always take you "up" to the folder containing the current window, and since A:\ is "inside" My Computer, clicking this button returns you from A:\ to My Computer.
The other icons in your My Computer window refer to the other storage devices in your computer. If your computer has a second floppy drive, its name is B:. Since A: and B: are commonly used for floppy drives, C: is the name of the hard disk on most Windows-95 computers, D: is the name of either a second hard disk or the CD-ROM drive. Your computer may have additional devices (e.g., network drives) depending on how it has been set up.
Each of these other devices can be explored in exactly the same way as your floppy drive -- by clicking on the icon for that device, and then in its window, clicking on whatever icon(s) you want to examine next.
Open your C: drive, and find the Temp folder, and open (i.e., double-click) it.
During this course, we'll create dozens of files, and so some means of organizing them is needed. Just as the documents in a filing cabinet are often kept in manila folders, Windows-95 lets us create a folder container in which we can store related files.
To do so, point the mouse at your C:\Temp window and click the right mouse button to display a menu. Move the mouse downwards until it points at the New choice, and wait while the secondary menu appears. Then move the mouse again until you are pointing at the Folder choice, and click either button. You should see a folder icon labeled New Folder appear on your C:\Temp window.
When the new folder appears its name is automatically selected, so that you can give it a more descriptive name. Since we are creating a folder in which to store our labs, type labs to rename this folder appropriately.
As this indicates, the labs folder is within the C:\Temp folder. Now, suppose we want to get from C:\Temp\labs back to C:? We could click twice on the button with the folder-and-up-arrow icon, but when you want to jump "up" several folders at once, the white text window containing labs provides a faster way: Click on this box and a drop-down menu will appear showing that labs is within Temp which is within C:. Just click on the C: choice to return directly to C:.
For practice, navigate back to C:\Temp and make three other folders: one named "practice", one named "projects" and one named "myLib".
We made practice just for practice, to learn how to get rid of unwanted folders. Click on practice, drag it to the Recycle Bin icon (the icon will darken when the mouse is properly positioned over it) and drop it there. Your folder should disappear "into" the Recycle Bin, and if the Recycle Bin was empty, its icon should change to indicate that it is no longer empty.
If you throw something away and later decide you want to get it back, you can open the Recycle Bin by double-clicking on it and drag what you want to retrieve from the window back to your desktop. If you are certain that you will not want to retrieve anything from the Recycle Bin, you can empty the bin by pointing the mouse at the Recycle Bin icon, clicking the right mouse button to get its menu, and choosing the Empty Recycle Bin choice from the menu. This operation cannot be undone, so use it with caution.
As we shall see in a later lab exercise, this is a bit of a simplification, but it is sufficiently accurate to give you an idea of what is occuring. For now, just realize that the IDE's text editor is what you use to enter a program, and its compiler and linker are what you use to translate it.
To get started, invoke Visual C++ according to your instructor's directions. (This may involve double-clicking on an icon on your computer's desktop, or clicking on the Start menu and following the submenus through Programs -> Microsoft Visual C++ 5.0 -> Microsoft Visual C++ 5.0). A window should appear labeled Microsoft Developer Studio. If you are viewing these instructions through a web browser, you will want to use the "un-maximize" button to resize the window that appears so that you can view both it and your web browser simultaneously. If a "tip of the day" window is displayed, close it and continue.
Our first program will input a base-10 integer and display that same value in base-10 (decimal), base-8 (octal) and base-16 (hexadecimal). We will thus name the executable program bases.exe, and name the source program bases.cpp (C++ source programs end in .cpp by convention, and executable programs end in .exe in Windows-95.)
The Visual C++ IDE provides a convenient feature called a project for simplifying the translation of a source program into machine language. The normal procedure is to create such a project first, before we create any source files for our program.
To create a project, move the mouse within the Microsoft Developer Studio window and click on the File menu, and choose New from the menu that appears. This should cause a window to appear labelled New, containing "tabs" labelled Files, Projects, Workspaces, and Other Documents. Make sure that the Projects tab is selected, and then click on the Win32 Console Application choice. (Each of the exercises in this manual will use this same kind of project.)
First fill in the text box labelled Location: by clicking the ... button to the right of the box. In the window that appears, navigate to the C: drive, the TEMP folder there, and your labs folder within TEMP.
Then fill in the name of the project, which should always be the same as the name of our program. Since our program is to be called bases, type bases in the text box labelled Project Name:. Note that as you type, the name bases is also appended to the location C:\Temp\labs. Visual C++ will automatically create a folder named bases in which to store the work you do for this project. Click the Ok window and the Microsoft Developers Window should reappear, with bases prepended to its title.
Next, we want to create a new file named bases.cpp in which to store our program. To do so, move the mouse to the File menu within the Microsoft Developers Studio window and choose File -> New again. The same New window will appear as before. This time, make sure that the Files tab is selected, then choose C++ Source File from the list of options presented.
In the text box labelled File Name:, enter bases.cpp, and then click the Ok button. A subwindow titled bases.cpp will then appear within the Microsoft Developers Studio window, in which we can type our program.
Within the bases.cpp subwindow, enter (and personalize) the following C++ source program:
/* bases.cpp demonstrates basic I/O in C++. * * Author: Jane Doe. * Date: 2/29/99. * Purpose: Lab 0 in CS-1 at the University of Gallifrey. * * Specification: * Input(keyboard): aNumber, an integer; * Output(screen): the base 10, 8 and 16 representations of aNumber. ***********************************************************************/ #include <iostream> using namespace std; int main() { // 0. print a message explaining the purpose of the program. cout << "\nThis program inputs a base-10 integer" << "\n\tand displays its value in bases 8 and 16\n"; // 1a. ask the user to enter an integer. cout << "\nPlease enter an integer: "; // 1b.declare an integer container to hold the input number int aNumber; // 1c. input an integer, storing it in variable aNumber. cin >> aNumber; // 2. output the base-8 and base-16 representations of aNumber. cout << "\n\nThe base-8 representation of " << aNumber << " is " << oct << aNumber << ",\n\tand the base-16 representation is " << hex << aNumber << "\n\n"; // 3. terminate normally return 0; }One shortcut is to copy-and-paste the text above from your browser's window into the bases.cpp window. Let's learn how to do this next.
In Windows-95, a block of text can be selected by pointing the mouse at the top of the block of text, and dragging downward to the bottom of the block of text. To copy-and-paste the selected text:
Using this approach, copy the program shown above into the bases.cpp subwindow.
As you've probably figured out, you can use the mouse to position the cursor at an arbitrary point by pointing at that point and clicking the left mouse button. The arrow keys (or the mouse) can be used to reposition the cursor.
If you mistype something, it can be erased using the delete (or backspace) key. On many keyboards, the Delete key is set up to erase whatever is to the right of the cursor, while backspace erases whatever is to the cursor's left.
If you make a mistake, you can always undo your most recent typing using the undo command: Ctrl-z or by using the Edit -> Undo menu choice.
Compiling... bases.cpp Linking... bases.exe - 0 error(s), 0 warning(s)If you see anything else, then your program contains typographical errors which you must correct before proceeding.
When your program contains errors, the Build subwindow lists them for you. If you double-click on a given error message, Visual C++ will move the cursor to the line in bases.cpp where it discovered the error. Compare that line and its surround lines with those of the source program in your web browser and fix any discrepencies. Then re-translate your program. If you still have errors, continue this edit-translate cycle as many times as necessary until your program is error-free.
When it prompts you for input, enter an easy-to-check number (like 15, 16 or 17) and verify that you get the correct results. When you see the message
Press any key to continuedon't press a key -- instead, continue to the next part of the exercise.
A paper copy of electronic information is called a hard copy. It is often useful to have a hard copy of one's source program, which is in the file bases.cpp. As with much of Visual C++, this is quite easy: just make sure that bases.cpp is selected choose File -> Print, or use the keyboard shortcut Ctrl-p. If you must do anything beyond this (such as specify a printer), your instructor will inform you of the details.
It is often useful to be able to print a hard copy of the output from your program, especially for more complicated programs. Unfortunately, Visual C++ does not make this particularly easy. If you examine the bases.exe window, you'll note that there is no File menu or other means of printing its contents.
This forces us in a different direction. What we will do is (i) make a copy of our bases.exe window, (ii) paste that copy into a different application, and (iii) print the copy from that application.
For the first step, first make sure that the bases.exe window is selected, and then press Alt-Print Screen (hold down the Alt key and then press the Print Screen key). This copies the active window to a special system file called the clipboard.
To access that copy, we need a different program. Go to the Start menu (at the bottom of the screen) and choose Start -> Programs -> Accessories -> Paint. This will launch a new application called Paint. In the window that appears, use Edit -> Paste or Ctrl-v to paste what is on the clipboard (the image of your program's output) into the Paint window.
Once the copy of your bases.exe window appears there, you can use File -> Print (or Ctrl-p) to print the copy from within the Paint application.
Then modify bases.cpp as necessary to perform your experiment, re-translate bases.cpp into machine language, and run it. If the resulting behavior indicates that your hypothesis is false, repeat the preceding Observe-Hypothesis-Experiment steps until you form a hypothesis that you cannot prove to be false.
When you are unable to prove your experimental hypothesis to be false, print a hard copy of your modified bases.cpp. On that hard copy, write down your hypothesis, your experiment, and circle that part of the program that performs your experiment. Then print a hard copy of its output (using the Paint application) and note on it the effects of your experiment.
To avoid this inefficiency, once a file is compiled, a Visual C++ project stores a copy of the compiled version called an object file. The Build -> Execute ... command then recompiles any files that have been changed, and uses the existing object files of any files that have not been changed. By avoiding unnecessary recompilations, this saves lots of time.
Object files speed every Build -> Execute ... after the first one, but they also consume disk space. To save disk space, the object files should be removed from a project any time you are done working on it.
To remove these files, choose Build -> Clean, and Visual C++ will display
Deleting intermediate files and output files for project 'bases - Win32 Debug'.in the Build message window at the bottom of the screen.
Navigate back to C:\Temp\labs and select (without opening) bases. Then go to the File menu and choose File -> Properties and a box will appear telling you (among other things) how much disk space bases consumes (4.51 Mbytes on our system).
Next, open bases and then drag the Debug folder to the Recycle Bin. (The Debug folder is where your bases.exe is stored, which as a binary, is quite large.) Empty the Recycle Bin and then navigate back to C:\Temp\labs. There, select (again, without opening) bases and see how big it is now that we have deleted Debug. On our system, bases is now just 87 Kbytes -- the Debug folder was consuming about 98% of the space!
Since a floppy disk only stores 1.4 Mbytes, the morale of the story is, always delete the Debug folder before trying to save your work to a floppy disk.
If you brought a floppy disk with you, you can save a copy of your work by navigating to the C:\Temp folder, selecting your labs folder, and using Ctrl-c to copy labs. Then navigate to your floppy drive A: and use Ctrl-v to paste there. This will copy labs and everything in it to your floppy disk. When you drop the folders, you should hear the drive motor activate and then stop as the copy is performed. Note that this truly is a copy operation -- the original folder remains in C:\Temp. To avoid having someone else plagiarize your work, you should then drag C:\Temp\labs to the Recycle Bin, and then empty the bin.
Once you have cleaned up in this manner, end your session with the computer, following your instructor's instructions.
Note: If your head feels ready to explode, don't panic! This first lab covers a great deal of material, that you will use over and over again, and as you do so, you will begin to naturally memorize those commands that you use most frequently. You can speed up the process by reviewing each of the steps you took in this exercise and practicing in your free time.
Forward to the Homework Projects