Resources | Subject Notes | Computer Science
In programming, input and output are fundamental concepts. Input refers to the data that a program receives from the user or an external source. Output refers to the data that a program produces as a result of processing the input. This section explores various methods for handling input and output in a program.
Programs need ways to get data to work with. Here are common input methods:
getch()
(in some languages) or dedicated input libraries to read keystrokes.Once a program has processed data, it needs to present the results to the user or another system. Common output methods include:
print()
or display()
to show text, numbers, and graphics on the screen.Consider a program that asks the user for their name and then greets them.
Step | Input | Processing | Output |
---|---|---|---|
1. Prompt User | Display a message like "Please enter your name: " | ||
2. Read Input | The user types their name and presses Enter. | Store the entered name in a variable (e.g., name ). |
|
3. Greet User | Combine a greeting message with the stored name. | Create a greeting string (e.g., "Hello, " + name + "!") |
Display the greeting string on the screen. |
The data type of the input affects how it can be processed and displayed. For example:
Data Type | Example | Input Method | Output Method |
---|---|---|---|
Text (String) | "Alice" | Keyboard Input | Screen Output, File Output |
Integer (Whole Number) | 10 | Keyboard Input, File Input | Screen Output, File Output |
Decimal (Floating-Point Number) | 3.14 | Keyboard Input, File Input | Screen Output, File Output |
When designing programs that handle input and output, it's important to consider:
Explore different input and output functions available in various programming languages. Experiment with reading data from files and writing data to files. Investigate how to handle user input effectively and provide informative output to the user.