OOPortal OOPortal

Computer Algorithms  «Prev 

Input and Output

Interaction in programming is described as input/output (I/O). Of course, this communication flows in two directions, one in the form of output, which is information the program provides to outside parties, and the other in the form of input, which is information users provide to the program or information the program reads in from the outside world. It is easy to imagine a multitude of cases where such functionality could be useful. Imagine a program asking the user's name, for instance, or a program asking if it should terminate or ignore an error when something unexpected happens. These aspects are all covered in this chapter.
Interaction can happen not only between a program and a human end user, but can also involve other sources of information. Consider, for example, the fact that so far, whenever you closed and restarted a program, all its previous data values were lost. When writing a budget tracking application, you cannot expect your users to leave the program running indefinitely (what if the power goes out?) or expect them to re-enter all the information once they reopen the program. As such, you will also deal with ways of handling I/O between your program and data sources. This chapter covers the most basic of data sources, namely that of a file.

Components of a Computer

CPU: This is the brains of the computer. The CPU executes the instructions contained with the computer programs.

RAM: Random Access Memory: RAM contains the programs being executed by the CPU along with the data being processed. The CPU can read from and write to RAM very quickly. RAM is volatile storage, the contents of RAM are lost when the power to the computer is turned off. RAM is also referred to as main memory or primary storage.

Long term storage: This includes hard disks, CD-ROMS, and DVDs. These are used for long-term storage of programs and data, and capable of holding vast amounts of information. Long term storage is non-volatile and the contents of long term storage are not lost when the power to the computer is turned off. Long term storage is also referred to as second storage.

I/O devices: Input and output devices. These devices allow you to communicate with the computer. An input device such as a keyboard, mouse or joystick allows you to input data to the computer, while an output device such as a monitor or printer allows you to see what the computer has done.