Configuring WEP or WPA Encryption on a Networked Mac

You can set up either WEP (Wireless Encryption Protocol) or WPA (Wi-Fi Protected Access) encryption to make your wireless network more secure. WPA encryption is much more secure than WEP encryption. You should use WPA-PSK or WPA Personal encryption on your home wireless network unless you have computers that only support WEP encryption.

Setting up WEP encryption
Use the following steps to set up WEP encryption on a Mac:

1. Choose Apple --> System Preferences to open the System Preferences window.

2. Click the Network icon to open the Network dialog box.

3. Choose AirPort in the Show menu and choose Preferred Networks in the By Default, Join menu.

4. Select a network in the list of networks and click Edit.

5. In the Wireless Security menu, choose a WEP option. Choose ASCII or HEX as appropriate for your network.

If you're not sure whether to choose ASCII or HEX, or if your network uses 64-bit WEP encryption, choose WEP Password instead.


6. Enter the WEP key in the password text box.

7. Click OK and then quit Network Preferences.

To make sure you're typing the WEP key correctly, temporarily select the Show Password check box so that you can see the characters you are typing. Make sure no one is looking over your shoulder when you do this.


Configuring WPA encryption
Follow these steps to configure WPA encryption:

1. Choose Apple --> System Preferences to open the System Preferences window.

2. Click the Network icon to open the Network dialog box.

3. Choose AirPort in the Show drop-down menu and choose Preferred Networks in the By Default, Join menu.

4. Select a network in the list of networks and click Edit.

5. In the Wireless Security menu, choose WPA Personal.

WPA Personal is equivalent to WPA-PSK, which is used by many wireless access points. WPA Enterprise requires that a RADIUS server be running on your network, something your home network is not likely to have.


6. Enter the WPA password in the password text box.

7. Click OK and then quit Network Preferences.

Special Wi-Fi Considerations for Macs

Macintosh computers have been at the forefront of wireless networking with AirPort, Apple's name for the Wi-Fi technology used in modern Macs. Most new Macs have AirPort Extreme — a newer, faster version of AirPort — built right in. If you buy a new Mac without AirPort Extreme you may be able to install a card. By using AirPort or AirPort Extreme, you can connect your Mac to any 802.11b/g Wi-Fi network.

Some Macs —such as the Mac mini — can only be upgraded by an Apple repair professional. When you buy a new Mac, spend a little extra money to get an AirPort Extreme card preinstalled — it's worth it.


Installing an AirPort card in an iBook
Follow these steps to install an AirPort card in an iBook:

1. Shut down your iBook and remove the battery.

To remove the battery, use a coin to turn the lock screw on the bottom of the iBook to the unlocked position.

2. On the front of your iBook, push the keyboard release tabs (see Figure 1) towards the front of the iBook and gently lift the keyboard out of the chassis. You don't need to disconnect the keyboard; simply rest it upside down on the touch pad.




Figure 1: The keyboard release tabs.

3. Locate the built-in AirPort antenna in the space provided for the AirPort card.

If you don't see a space for the AirPort card, your iBook either is not compatible with AirPort or it already has AirPort installed.

4. Connect the antenna to the antenna port on the AirPort card.

5. Insert the AirPort card into the slot, ensuring that the connector pins seat firmly in the AirPort card socket.

Do not force the card into position. If the AirPort card and the port on your computer don't match, you probably have the wrong kind of card for your iBook model.


6. Seat the AirPort card wire retention clasp and replace the keyboard and battery.

Installing an AirPort card in an eMac
Follow these steps to install an AirPort card in an eMac:

1. Open the DVD-ROM disc tray and leave it open.

2. Shut down your computer and make sure that the power is off.

Disconnect the power cable to make sure that the computer doesn't accidentally turn on while you are installing the card.


3. Remove the two Philips-head screws on the cover inside the disc tray to reveal the AirPort card slot (see Figure 2).



Figure 2: The AirPort card slot.

4. Disconnect the antenna from the cover and then press the antenna into the AirPort card's antenna port.

5. Insert the AirPort card firmly into the slot until it seats and then reinstall the cover inside the disc tray.

Connecting to a Wi-Fi access point
To connect to a Wi-Fi access point, follow these steps:

1. If AirPort isn't already enabled, click the AirPort icon on the menu bar in the upper-right corner of the screen and choose Turn AirPort On.

2. Click the AirPort icon in the menu bar again and choose Other to connect to a new Wi-Fi network.

If the access point is set to broadcast its SSID, it may appear in the list of available networks in the AirPort menu. If you see the network to which you want to connect listed, click its name.


3. In the resulting Closed Network dialog box, enter the network's SSID in the Network Name text box.

4. Choose a Wireless Security method as needed for the network.

5. Click OK to connect to the network.

6. Check the status and signal strength of the Wi-Fi network by clicking the AirPort icon in the menu bar and choosing Open Internet Connect.

Managing Wi-Fi networks
Follow these steps to manage your Wi-Fi network:

1. Choose Apple --> System Preferences to open the System Preferences window.

2. Click the Network icon to open the Network dialog box.

3. Choose AirPort in the Show menu to reveal AirPort settings.

4. In the By Default, Join menu, choose Preferred Networks.

5. In the resulting list, rearrange the order by clicking and dragging networks up or down in the list.

6. To remove a network from the list, click the network to select it and then click the Remove (-) button.

7. Select a network and choose Edit to change encryption keys and other network details for a given network.

8. When you are done making changes, click the Apply Now button and then quit System Preferences.

To update the AirPort software, choose Apple --> Software Update to run the Software Update. Download and install any necessary updates to your computer.

Configuring a DHCP Client on a Windows PC or Mac

If you have one computer that connects directly to the Internet through a modem, you can share that computer's Internet connection using Windows ICS (Internet Connection Sharing). When you set up ICS, your computer — called the host computer — becomes a DHCP server for the rest of the network. After the host is set up, the rest of the computers on your network must be set up as clients. ICS clients can be Windows PCs or Macintosh computers.

Configuring a Windows PC as a DHCP client
Use these steps to configure a Windows PC as a DHCP client:

1. Open the Windows Control Panel and then double-click the Network Connections icon to open a list of network connections.

2. Double-click your current connection to the network.

3. In the resulting Status dialog box, click Properties.

4. In the Local Area Connection Properties dialog box, select Internet Protocol (TCP/IP) and then click the Properties button.

5. In the Internet Protocol (TCP/IP) Properties dialog box, select the Obtain an IP Address Automatically option.

6. Select the Obtain DNS server address automatically option.

7. Click OK and close all open dialog boxes.

When you set your computer to obtain an IP address automatically, it gets the address from either your router's built-in DHCP server, or from an ICS Host on another computer. You may need to restart your computer for your changes to take effect.


Configuring a Mac as a DHCP client
Follow these steps to configure a Mac as a DHCP client:

1. Open System Preferences from the Apple menu and click the Network icon.

2. In the resulting Network control panel, click the Show menu drop-down arrow and choose the network connection you use to connect to the network.

If your computer connects to the network using the built-in Ethernet network port, choose Built-In Ethernet in the Show menu. If you connect using an AirPort Card, choose AirPort in the Show menu instead.


3. Click the TCP/IP tab.

4. Click the Configure menu drop-down arrow and choose Using DHCP.

5. Click the Apply Now button and then close the Network control panel.

6. Press Command+Q to quit System Preferences and then restart your computer.

If you're using a portable Mac, you can use it to connect to several different networks. For example, at home you may connect it to your home network using an Ethernet cable, but at Wi-Fi hotspots you may connect using AirPort instead. Use the Location menu at the top of the Network control panel to specify connection settings for different network locations.

Macintosh OS X can obtain an IP address automatically from a DHCP server built in to any router, or from a Windows PC running Internet Connection Sharing.

Logging into a Windows PC from a Mac (and Vice Versa)

If your network is all Windows or all Macintosh, sharing files back and forth is easy. But if you have a mix of Windows PCs and Macs, you'll have to go through a special log in procedure before you can share files and folders.

Logging in to a Windows PC from a Mac
Follow these steps to log in to a Windows PC from a Mac:

1. In Mac OS 10.2 or 10.3, choose Go --> Connect to Server. In OS 10.4 and later, open Finder and then click Network.

You may need to wait several seconds for the list of computers to be populated. In some cases you may also see a Windows workgroup name listed. If you see the workgroup, double-click it to open it.

2. In the Connect to Server window (OS 10.2 or 10.3), click the name of the computer to which you want to connect. In OS 10.4 and later, double-click the folder bearing the name of your Windows workgroup to browse the workgroup.

By default, newer Macs are set with the default workgroup name "Workgroup." This probably isn't the correct workgroup name for your Windows workgroup. To check the workgroup name for your Windows network, go to a Windows PC, right-click the My Computer icon, and choose Properties from the menu that appears. In the System Properties window, click the Computer Name tab to bring it to the front. The workgroup name is listed on this tab. Click OK or Cancel to close the System Properties window.


3. Double-click the computer to which you want to connect.

4. In the resulting SMB/CIFS Filesystem Authentication dialog box, type a username and password for an account on the Windows computer to which you are trying to connect and click OK.

If you only want to access shared items on the Windows PC, just enter any user name and leave the password field empty. Doing so gives you access to public items on the Windows PC.


5. Choose a volume that you want to mount.

Items in the list of things you can mount include shared folders, as well as folders owned by the user account you are using to log in to the Windows PC.

6. Click OK. The selected item mounts on your computer as if it were a disk drive or volume.

7. Double-click the network volume's desktop icon to browse its contents.

In Mac OS 10.4 and later, you can also access mounted volumes directly from Finder. In the Finder window, simply click the volume's icon in the upper-left corner.

8. Click and drag files to copy them between computers.

If you only want to access shared folders on the Windows PC, enter any user name in Step 4 and leave the password blank. You will still be able to log in to the Windows PC, although you will only be able to access shared folders.


Logging in to a Mac from a Windows PC
Follow these steps to log in to a Mac from a Windows PC:

1. Open My Network Places from the Windows Start menu.

2. Click View Workgroup Computers under Network Tasks on the left side of the screen to display the list of workgroup computers on the right.

Macintosh computers may have the word Samba in front of their names in the list of workgroup computers. Samba is the Mac OS X software that allows Windows and Macintosh PCs to network with each other.


3. Double-click a Macintosh computer in the list.

4. In the resulting Connect To dialog box, enter the user name and password for the Windows user account on the Mac.

5. Click OK to log in. After you are logged in, you can see a list of available files and folders on the Mac.

You can only access items that are owned by the Windows user account on the Mac. If you want to share items with other user accounts on the Mac, store them in the Public folder. Each user's Public folder in Mac OS X is shared with other users.

Creating a User Account on Your Wi-Fi Network

Chances are you have two main reasons for setting up a home network: you want to share an Internet connection between your computers and you want to be able to copy files between computers. If you use a Mac and want to allow access to the network from Windows PCs, you must first create a Windows user account.

Follow these steps on the Mac to create the Windows user account:

1. Open System Preferences from the Apple menu.

2. Click the Accounts icon to open the Accounts window.

3. Click New User (OS 10.3 and earlier) or the plus sign in the lower-left corner of the Accounts window (OS 10.4 and later).

4. Enter a name, short name, and password for the user (see Figure 1).

For example, you can name the account Windows to help you remember the purpose of the account later.




Figure 1: Name the Windows user account.

5. Select the Allow User to Log In from Windows check box if you see it.

As the name implies, this option enables users to log in using this account on Windows PCs. This option is not available (or required) in newer versions of Mac OS X.


6. Click Save or Create Account (depending on your OS X version) to save the new user account. The Windows account now appears in the list of user accounts, as shown in Figure 2.



Figure 2: The Windows account appears in the list.
Because Mac OS X is based on UNIX, user account names and passwords are case sensitive. Make sure that Windows users on your network know this, because if the user name is "Windows" and they try to log on using "windows," the log in attempt will be unsuccessful.

Sharing Folders on Wi-Fi Networks

Computer files are organized into folders on your hard drive. In Windows and Mac OS X, access to those folders is strictly controlled. If you own a folder, other computers on your network — and even other users on the same computer — can't access it. To copy files back and forth over the network, you can share folders with others.

Sharing a folder in Windows
Follow these steps to set up folder sharing in Windows:

1. Choose Start --> All Programs --> Accessories --> Communications --> Network Connections.

2. In the Network Connections window, right-click your network connection and choose Properties from the menu that appears.

3. In the Network Connection Properties dialog box, select the File and Printer Sharing for Microsoft Networks check box.

File and Printer Sharing may already be enabled on your computer, but you should double-check it to make sure.


4. Click OK to close the dialog box.

5. Open My Computer or Windows Explorer.

6. Locate the Shared Documents folder. Right-click the Shared Documents folder and choose Sharing and Security from the menu that appears.

7. In the resulting Properties dialog box, select the Share This Folder on the Network check box.

8. Type a descriptive name for the folder in the Share Name field.

9. Click OK to close the Properties dialog box.

10. To share files or folders, copy them into the Shared Documents folder using My Computer or Windows Explorer.

To create a new subfolder in the Shared Documents folder, open Shared Documents and then choose File --> New --> Folder. Give the new folder a descriptive name.


Accessing a shared network folder in Windows
To access a shared networks folder in Windows, follow these steps:

1. Choose Start --> My Network Places.

You can also access My Network Places from My Computer or Windows Explorer. In My Computer, click My Network Places under Other Places on the left side of the screen. In Windows Explorer, click My Network Places near the bottom of the folder tree on the left side of the screen.

2. In the My Network Places window that appears, double-click the network place that you want to open.

If you don't see a network folder that you think should be available, make sure that the computer containing the network folder is turned on and connected to the network. Also, double-check the file sharing settings on the other computer.


3. Browse the network folder.

4. To copy an item to a shared network folder, simply click and drag it to the shared folder's window. (You can also use Cut, Copy, and Paste commands when browsing shared network drives.)

When you share a folder, anyone on your network can access it. Do not store private or sensitive files in shared folders.


Enabling file sharing in OS X
If you are using a Mac, follow these steps to enable file sharing in Mac OS X:

1. Open System Preferences from the Apple menu and then click Sharing.

2. In the resulting Sharing control panel, provide a descriptive name for your computer. (Other computers will see this name over the network.)

3. Select the Personal File Sharing check box. If you will be sharing folders with Windows PCs, check the Windows File Sharing option as well.

4. Close the Sharing control panel.

These steps assume that you have Mac OS Version 10.2 or better. Windows File Sharing is only available in Mac OS 10.2 or better. Sharing files between Windows and older versions of Mac OS requires special third-party programs.


Changing the workgroup name in OS X
Follow these steps to change the workgroup name in Mac OS X.

1. Open the Applications folder on your hard drive and then open the Utilities subfolder.

2. Double-click the Directory Access utility to open it.

3. Click the lock icon at the bottom of the Directory Access utility and then enter an administrator name and password.

4. Select SMB/CIFS on the Services tab and then click the Configure button.

5. Enter your Windows workgroup name in the Workgroup field and click OK.

Choosing a Network Access Mode and Finding a Wireless Network

You can choose between three network access modes when locating available Wi-Fi networks within range of your computer. Each network access mode offers a different level of security.

After you've connected to a network, the Wireless Network Connection window enables you to manage your network connections. Using this window you can connect or disconnect from networks, or change the order of preferred networks when more than one is available.

Choosing a network access mode
Follow these steps to choose a network access mode:

1. Double-click the wireless connection icon in the Windows system tray (in the lower-right corner of the screen).

If you don't see a wireless connection icon in the system tray, choose Start --> All Programs --> Accessories --> Communications --> Network Connections. Right-click your wireless connection and choose Properties. Select the Show Icon in Notification Area When Connected check box and click OK.


2. In the Wireless Network Connection Status dialog box, click the Properties button.

3. In the Wireless Network Connection Properties dialog box, click the Wireless Networks tab.

4. Click the Advanced button to open the Advanced dialog box.

5. Choose a network access mode:

• Any Available Network (Access Point Preferred): The computer tries to connect to any wireless network that is detected.

• Access Point (Infrastructure) Networks Only: The computer tries to connect to networks using a wireless access point. This setting gives you more security, especially at Wi-Fi hotspots.

• Computer-to-Computer (Ad Hoc) Networks Only: The computer tries to connect to other computers, called ad hoc networking.

6. If you want to automatically log on to any available wireless network, select the Automatically Connect to Non-Preferred Networks check box.

Automatically logging on to any available network could leave your computer vulnerable to unknown and untrusted networks. Do not enable this option if your computer contains sensitive or personal information.


7. Click Close to close the Advanced dialog box and click OK to close all remaining dialog boxes.

Searching for wireless networks
Use these steps to search for a wireless network within range of your computer:

1. Double-click the wireless connection icon in the Windows system tray.

2. In the Wireless Network Connection Status dialog box, click the View Wireless Networks button.

3. In the resulting Wireless Network Connection window, click Refresh Network List in the Network Tasks menu on the left side of the screen.

Checking Out the Visual Basic .NET User Interface

Because a computer monitor can display only a limited amount of information on the screen at any given time, Visual Basic .NET provides several different windows for displaying vital information about your Visual Basic .NET program. After you understand the purpose of each window, you can use some of the following tips listed to make programming in Visual Basic .NET easier than before.

Playing with the Properties Windows (F4)
The Properties window enables you to modify the way objects, such as a button or a check box, look and behave. To help you find properties to change, the Properties window can display information alphabetically or by categories.

To display properties alphabetically, click on the Alphabetic icon in the Properties window. To display properties organized by category, click on the Categorized icon.

The Properties window displays all properties for a single object. If you want to view the properties for another object, you can click on that object or use the Object list box. Just click on the downward-pointing arrow of the Object list box to display a list of all objects and then click on the object that you want to modify.

Using the Solution Explorer (Ctrl+Alt+L)
The Solution Explorer displays all the files used to create a single Visual Basic .NET project. From within the Solution Explorer, you can edit a form, edit the code stored in a file, remove a file from a project, or delete that file altogether by right-clicking on the file you want to change and then clicking on one of the following:

View Code (to edit BASIC code)
View Designer (to modify your user interface)
Exclude From Project (to remove a file from the project without deleting that file)
Delete (to remove a file from a project and erase that file at the same time)
Customizing the Toolbox (Ctrl+Alt+X)
The Toolbox displays all the different types of objects you can add to your user interface such as radio buttons, check boxes, or text boxes, which are stored under the Windows Forms tab. For quick access to your most commonly used objects, you can create your own tab and store your favorite objects on that tab.

Customizing a Tab in the Toolbox
To create a tab in the Toolbox, follow these steps:

1. Right-click on any tab (such as the Windows Forms tab) in the Toolbox.

A pop-up menu appears.

2. Click on Add Tab.

The Toolbox displays a blank tab.

3. Type a descriptive name for your tab and press Enter.

The Toolbox displays your tab name in the Toolbox.

Adding Objects to a Custom Tab in the Toolbox
To add objects to your custom tab in the Toolbox, follow these steps:

1. Right-click on an object that you want, such as TextBox or RadioButton.

A pop-up menu appears.

2. Click on Copy.

3. Click on the tab where you want to store the object you chose in Step 1.

4. Right-click and choose Paste.

The Toolbox displays your chosen object under your Toolbox tab.

Deleting a Tab in the Toolbox
To delete a tab in the Toolbox, follow these steps:

1. Right-click on the tab you want to delete.

A pop-up menu appears.

2. Click on Delete Tab.

If you have any objects stored under your chosen tab, a dialog box appears, asking if you want to continue.

3. Click Yes.

Visual Basic .NET deletes your chosen Toolbox tab.

Looking at the Class View (Ctrl+Alt+C)
The Class View lists all the variables, methods, and properties used by class files that make up your Visual Basic .NET project. By using the Class View window, you can quickly jump to the part of a class file that you need to examine or modify.

To view a variable, method, or property, follow these steps:

1. Choose View --> Class View (or press Ctrl+Alt+C) to open the Class View window.

The Class View window appears.

2. Double-click on the variable, method, or property that you want to examine or modify.

Visual Basic .NET displays your chosen variable, method, or property in the Code Editor.

Avoiding Bugs in Your C++ Program

Don't start debugging your code until you remove or at least understand all the warnings generated during compilation. Enabling all the warning messages if you then ignore them does you no good. If you don't understand the warning, look it up. What you don't know will hurt you.

Adopt a clear and consistent coding style
Coding in a clear and consistent style not only enhances the readability of the program but also results in fewer coding mistakes. Remember, the less brain power you have to spend deciphering C++ syntax, the more you have left over for thinking about the logic of the program at hand. A good coding style enables you to do the following with ease:

Differentiate class names, object names, and function names
Know something about the object based on its name
Differentiate preprocessor symbols from C++ symbols (that is, #defined objects should stand out)
Identify blocks of C++ code at the same level (this is the result of consistent indentation)
In addition, you need to establish a standard module header that provides information about the functions or classes in the module, the author (presumably, that's you), the date, the version of the compiler you're using, and a modification history.

Finally, all programmers involved in a single project should use the same style. Trying to decipher a program with a patchwork of different coding styles is confusing.


Comment your code as you write it
You can avoid errors if you comment your code while you write it rather than wait until everything works and then go back and add comments. Not taking the time to write voluminous headers and function descriptions until later is understandable, but you always have time to add short comments while writing the code.

Short comments should be enlightening. If they're not, they aren't worth much and you should be doing something else instead. You need all the enlightenment you can get while you're trying to make your program work. When you look at a piece of code you wrote a few days ago, comments that are short, descriptive, and to the point can make a dramatic contribution to helping you figure out exactly what it was you were trying to do.

In addition, consistent code indentation and naming conventions make the code easier to understand. It's all very nice when the code is easy to read after you're finished with it, but it's just as important that the code be easy to read while you're writing it. That's when you need the help.

Single-step every path at least once
As a programmer, it's important for you to understand what your program is doing. Nothing gives you a better feel for what's going on under the hood than single-stepping the program with a good debugger. (The debuggers included in the IDE of interactive compilers work just fine.)

Beyond that, as you write a program, you sometimes need raw material to figure out some bizarre behavior. Nothing gives you that material better than single-stepping new functions as they come into service.

Finally, when a function is finished and ready to be added to the program, every logical path needs to be traveled at least once. Bugs are much easier to find when the function is examined by itself rather than after it's been thrown into the pot with the rest of the functions — and your attention has gone on to new programming challenges.

Avoid overloading operators
Other than using the two stream I/O operators operator<<() and operator>>() and the assignment operator operator=(), you should probably hold off overloading operators until you feel comfortable with C++. Although a good set of overloaded operators can increase the utility and readability of a new class, overloading operators (other than the three just listed) is almost never necessary and can add significantly to your debugging woes as a new programmer. You can get the same effect by defining and using the proper public member functions instead.

After you've been C-Plus-Plussing for a few months, feel free to return and start overloading operators to your heart's content.

Balance heap handling
Generally, programmers should allocate and release heap memory at the same "level." If a member function MyClass::create() allocates a block of heap memory and returns it to the caller, then there should be a member function MyClass::release() that returns the memory to the heap. Specifically, MyClass::create() should not require the parent function to release the memory itself. This certainly doesn't avoid all memory problems — the parent function may forget to call MyClass::release() — but it does reduce the possibility somewhat.

Use exceptions to handle errors
The exception mechanism in C++ is designed to handle errors conveniently and efficiently. Now that this feature has been standardized, you should use it. The resulting code is easier to write, easier to read, and easier to maintain. Besides, other programmers have come to expect it — you wouldn't want to disappoint them, would you?

Avoid multiple inheritance
Multiple inheritance, like operator overloading, adds another level of complexity that you don't need to deal with when you're just starting out. Fortunately, most real-world relationships can be described with single inheritance.

Feel free to use multiple-inherited classes from commercial libraries, such as the Microsoft MFC classes. Microsoft has spent a considerable amount of time setting up its classes, and it knows what it's doing.

After you feel comfortable with your level of understanding of C++, experiment with setting up some multiple inheritance hierarchies. That way, you'll be ready if you need it.

Working with Functions in C++

Developers often need the ability to break programs up into smaller chunks that are easier to develop. "Real world" programs can be many of thousands (or millions!) of lines long. Without this ability to divide the program into parts, developing such large programs would quickly become impossible.

C++ allows programmers to divide their code up into chunks known as functions. A function with a simple description and a well-defined interface to the outside world can be written and debugged without worrying about the code that surrounds it.

Overloading function names
C++ allows the programmer to assign the same name to two or more functions. This multiple use of names is known as overloading functions or, simply, overloading.

In general, two functions in a single program cannot share the same name. If they did, C++ would have no way to distinguish them.

However, the name of the function includes the number and type of its arguments. (The name of the function does not include its return argument.) Thus, the following are not the same functions:

void someFunction(void)
{
// ....perform some function
}
void someFunction(int n)
{
// ...perform some different function
}
void someFunction(double d)
{
// ...perform some very different function
}
void someFunction(int n1, int n2)
{
// ....do something different yet
}

C++ still knows that the functions someFunction(void), someFunction(int), someFunction(double), and someFunction(int, int) are not the same. Like so many things that deal with computers, this has an analogy in the human world.

void as an argument type is optional. sumFunction(void) and sumFunction() are the same function. A function has a shorthand name, such as someFunction(). As long as we use the entire name, no one gets confused — no matter how many someFunctions there may be. The full name for one of the someFunctions()is someFunction(int). As long as this full name is unique, no confusion occurs.

A typical application may appear as follows:

int intVariable1, intVariable2; // equivalent to
// int Variable1;
// int Variable2;
double doubleVariable;
// functions are distinguished by the type of
// the argument passed
someFunction(); // calls someFunction(void)
someFunction(intVariable1); // calls someFunction(int)
someFunction(doubleVariable); // calls someFunction(double)
someFunction(intVariable1, intVariable2); // calls
// someFunction(int, int)
// this works for constants as well
someFunction(1); // calls someFunction(int)
someFunction(1.0); // calls someFunction(double)
someFunction(1, 2); // calls someFunction(int, int)

In each case, the type of the arguments matches the full name of the three functions.

The return type is not part of the extended name (also known as the function signature) of the function. The following two functions have the same name and, thus, cannot be part of the same program:


int someFunction(int n); // full name of the function
// is someFunction(int)
double someFunction(int n); // same name

The following is acceptable:


int someFunction(int n);
double d = someFunction(10); // promote returned value

The int returned by someFunction() is promoted into a double. Thus, the following would be confusing:

int someFunction(int n);
double someFunction(int n);
double d = someFunction(10);// promote returned int?
// or use returned double as is

C++ would know whether to use the value returned from the double version of someFunction() or promote the value returned from int version.

Defining function prototypes
The programmer may provide the remainder of a C++ source file, or module, the extended name (the name and functions) during the definition of the function.

A function may be defined anywhere in the module. (A module is another name for a C++ source file.) However, something has to tell main() the full name of the function before it can be called. Consider the following code snippet:

int main(int argc, char* pArgs[])
{
someFunc(1, 2);
}
int someFunc(double arg1, int arg2)
{
// ...do something
}

The call to someFunc() from within main() doesn't know the full name of the function. It may surmise from the arguments that the name is someFunc(int, int) and that its return type is void; however, as you can see, this is incorrect.

C++ could be less lazy and look ahead to determine the full name of someFunc()s on its own, but it doesn't. What is needed is some way to inform main() of the full name of someFunc() before it is used. What is needed is a before use function declaration. Some type of prototype is necessary.

A prototype declaration appears the same as a function with no body. In use, a prototype declaration appears as follows:

int someFunc(double, int);
int main(int argc, char* pArgs[])
{
someFunc(1, 2);
}
int someFunc(double arg1, int arg2)
{
// ...do something
}

The prototype declaration tells the world (at least that part of the world after the declaration), that the extended name for someFunc() is someFunction(double, int). The call in main() now knows to cast the 1 to a double before making the call. In addition, main() knows that the value returned by someFunc() is an int.

A function call that returns a value is an expression. As with any other provide expression, you are allowed to throw the value returned by a function.


Variable storage types
Function variables are stored in three different places. Variables declared within a function are said to be local. In the following example, the variable localVariable is local to the function fn():

int globalVariable;
void fn()
{
int localVariable;
static int staticVariable;
}

The variable localVariable doesn't exist until the function fn() is called. localVariable ceases to exist when the function returns. Upon return, whatever value that is stored in localVariable is lost. In addition, only fn() has access to localVariable — other functions cannot reach into the function to access it.

By comparison, the variable globalVariable exists as long as the program is running. All functions have access to globalVariable all of the time.

The static variable staticVariable is something of a mix between a local and a global variable. The variable staticVariable is created when execution first reaches the declaration (roughly, when the function fn() is called). In addition, staticVariable is only accessible within fn(). Unlike localVariable, however, staticVariable continues to exist even after the program returns from fn(). If fn() assigns a value to staticVariable once, it will still be there the next time that fn() is called.

In case anyone asks, there is a fourth type, auto, but today it has the same meaning as local, so just ignore them.

Expressing Binary Numbers in C++

C++ variables are stored internally as so-called binary numbers. Binary numbers are stored as a sequence of 1 and 0 values known as bits. Most of the time, you don't really need to deal with numbers at the bit level; however, there are occasions when doing so is convenient. C++ provides a set of operators for this purpose.

The so-called bitwise logical operators operate on their arguments at the bit level. To understand how they work, examine how computers store variables.

The decimal number system
The numbers that you are familiar with are known as decimal numbers because they are based on the number 10. In general, the programmer expresses C++ variables as decimal numbers. Thus, you would say that the value of var is 123, for example.

A number such as 123 refers to 1 * 100 + 2 * 10 + 3 * 1. Each of these base numbers — 100, 10, and 1 — is a power of 10.

123 = 1 * 100 + 2 * 10 + 3 * 1

Expressed in a slightly different but equivalent way:

123 = 1 * 102 + 2 * 101 + 3 * 100

Remember that any number to the zero power is 1.


Other number systems
The use of a base number of 10 for the counting system stems, in all probability, from the fact that humans have 10 fingers, the original counting tools. The alternative would have been base 20.

If dogs had invented our numbering scheme, it may well have been based on the numeral 8 (one digit of each paw is out of sight on the back part of the leg). Such an octal system would have worked just as well:

12310 = 1 * 82 + 7 * 81 + 3 * 80 = 1738

The small 10 and 8 here refer to the numbering system, 10 for decimal (base 10) and 8 for octal (base 8). A counting system may use any positive base.

The binary number system
Computers have essentially two fingers. (Maybe that's why computers are so stupid: Without an opposable thumb, they can't grasp anything. And then again, maybe not.) Computers prefer counting using base 2. The number 12310 would be expressed as:

12310 = 0*128 + 1*64 + 1*32 + 1*16 + 1*8 + 0*4 +1*2 + 1*1
= 011110112

It is always convention to express binary numbers by using 4, 8, 32, or 64 binary digits even if the leading digits are zero. This is also because of the way computers are built internally.

Because the term digit refers to a multiple of ten, a binary digit is called a bit. The term stems from binary (b-) digit (-it). Eight bits make up a byte. A word is usually either two or four bytes.


With such a small base, it is necessary to use a large number of bits to express numbers. It is inconvenient to use an expression such as 011110112 to express such a mundane value as 12310. Programmers prefer to express numbers by units of bytes, or eight bits.

A single, four-bit digit is essentially base 16, because four bits can express up to any value from 0 to 15. Base 16 is known as the hexadecimal counting system. Hexadecimal is often contracted to simply hex.

Hexadecimal uses the same digits for the numbers 0 through 9. For the digits between 9 and 16, hexadecimal uses the first six letters of the alphabet: A for 10, B for 11, and so on. Thus, 12310 becomes 7B16.

123 = 7 * 161 + B (i.e., 11) * 160 = 7B16

Because programmers prefer to express numbers in 4, 8, 32, or 64 bits, they similarly prefer to express hexadecimal numbers in 1, 2, 4, or 8 hexadecimal digits even when the leading digits are 0.

Finally, it is inconvenient to express a hexadecimal number such as 7B16 using a subscript, because terminals don't support subscripts. Even on a word processor, it is inconvenient to change fonts to and from subscript mode just to type two digits. Therefore, programmers use the convention of beginning a hexadecimal number with a 0x (the reason for such a strange conviction goes back to the early days of C). Thus, 7B becomes 0x7B. Using this convention, 0x7B is equal to 123 (while 0x123 is equal to 291.)

All of the mathematical operators can be performed on hexadecimal numbers in the same way that they are applied to decimal numbers. The reason that we can't perform a multiplication such as 0xC * 0xE in our heads has more to do with the multiplication tables we learned in school than on any limitation in the number system.

An Introduction to C++

The C++ programming language consists of the following:

A vocabulary of commands that humans can understand and that can be converted into machine language fairly easily
A language structure (or grammar) that allows humans to combine these C++ commands into a program that actually does something (well, maybe does something)
The vocabulary is often known as the semantics, while the grammar is the syntax.


What's a program?
A C++ program is a text file containing a sequence of C++ commands put together according to the laws of C++ grammar. This text file is known as the source file . A C++ source file carries the extension .CPP just as a Microsoft Word file ends in .DOC or an MS-DOS batch file ends in .BAT. The concept extension .CPP is just a convention, but it's used almost exclusively in the PC world.

The point of programming is to write a sequence of C++ commands that can be converted into a machine language program that does whatever it is that you want done. Such machine executable programs carry the extension .EXE. The act of creating an executable program from a C++ program is called compiling (or building — there is a difference, but it's small).

How do I program?
To write a program, you need two things: an editor to build your .CPP source file with and a program that converts your source file into a machine executable .EXE file to carry out your commands. The tool that does the conversion is known as a compiler.

Nowadays, tool developers generally combine the compiler with an editor into a single work-environment package. After entering your program, you need only click a button to create the executable file.

The most popular of all C++ environments is Microsoft's Visual C++, but the software is expensive. Fortunately, there are public domain C++ environments — the most popular of which is GNU C++. (Pronounce GNU like this: guh NEW). You can download public domain programs from the Internet. Some of these programs are not free — you are either encouraged to or required to pay some usually small fee. You do not have to pay to use GNU C++.

GNU stands for the circular definition "GNU is Not UNIX." This joke goes way back to the early days of C++ — just accept it as is. GNU is a series of tools built by the Free Software Foundation.


GNU C++ is not some bug-ridden, limited edition C++ compiler from some fly-by-night group of developers. GNU C++ is a full-fledged C++ environment. GNU C++ supports the entire C++ language and executes all C++ programs.

GNU C++ is not a Windows development package for the Windows environment. You'll have to break open the wallet and go for a commercial package like Visual C++.

Replacing Printer Toner or an Ink Cartridge

Printers need ink or toner to place images onto a page. When your pages start to look blotchy or faint, you probably need a new cartridge.

Various printers work differently, but here's the general rundown on replacing the cartridge:

1. Turn off the printer and open its cover.

Printers usually have a hood-release type of latch that pops up the cover. You might need to remove the paper tray first.

If your laser printer has been turned on, let it cool off for 15 minutes. Laser printers get hot enough inside to brand a steer. The parts that seem hot are hot, and they can burn your fingers.


2. Pull out the old cartridge.

The cartridge usually slides straight out. While the cartridge is out, wipe away any dust or dirt you see inside the printer. The printer's manual tells you the most appropriate places to clean. A little rubbing alcohol on a soft rag usually works well. Check your printer's manual first to make sure that alcohol won't damage any parts inside.

Color printers usually come with two ink cartridges, one for black and the other for colored ink. Because they're often completely enclosed in black plastic, they're usually labeled to avoid confusion. If you're in doubt, the smaller cartridge probably holds the black ink.


3. Slide in the new cartridge.

Before sliding in a laser printer's toner cartridge, gently rock it back and forth to evenly distribute the toner that lurks inside. Don't turn the cartridge upside down or completely on one end.

Some toner cartridges have a protective plastic strip you must remove before you install the cartridge. Better check your printer's instruction manual on this one.

4. When the new cartridge snaps in place, close the printer's cover and turn it back on.

You might need to put the paper tray back on the printer.

5. Run your printer's software, if it has any.

Some inkjet printers, for example, come with software that aligns a newly installed cartridge. The software prints several coded designs, and then asks you to examine them and choose the best-looking ones. The printer then knows the best way to print.

• You should check your laser printer's manual for mention of any fuser pads or corona wires that need to be changed or cleaned when you replace the toner cartridge.

• New toner cartridges are sometimes blotchy for the first few pages, so don't print any résumés right off the bat.