Module 3: Input & Output Operations
Learn input, output, formatting, type casting, mathematical calculations and interactive programs in C, C++, Java and Python with selectable working examples.
Language
Example
Code
Output
3.1 Module Overview
Input and output operations allow a program to communicate with users. Input means receiving data from the user, while output means displaying results back to the user.
This upgraded tutorial teaches the same concepts in C, C++, Java and Python. Each working demo allows the learner to select a language and then view the matching implementation code together with the simulated output.
3.2 Language Comparison
| Concept | C | C++ | Java | Python |
|---|---|---|---|---|
| Input | scanf() | cin | Scanner | input() |
| Output | printf() | cout | System.out.println() | print() |
| Type Casting | (int), (float) | (int), static_cast | Integer.parseInt() | int(), float() |
| Format Decimal | %.2f | fixed & setprecision(2) | printf("%.2f") | f"{value:.2f}" |
3.3 User Input
User input allows a program to receive data during execution.
Online Working Example: Greeting Program
3.4 Display Output
Output displays messages, variable values and calculation results.
Online Working Example: Course Details
3.5 Formatting Output
Formatted output makes reports and calculations clearer. Decimal formatting is especially important for marks, fees and money.
Online Working Example: Student Marks Formatting
3.6 Type Casting
Type casting converts input from one type to another. It is commonly required when converting text input into numbers for calculations.
Online Working Example: Age Calculator
3.7 Mathematical Calculations
Programs often use input values for business calculations such as fees, salaries, discounts and student marks.
Online Working Example: Training Fee Calculator
3.8 Interactive Programs
An interactive program receives input, processes it and displays useful output.
Online Working Example: Calculator with Language Selection
3.9 Important Notes
3.10 Practical Activities
Activity 1: Greeting Program
Create a program in all four languages that asks for a name and displays a welcome message.
Activity 2: Fee Calculator
Create a program in all four languages that calculates training fee from participants and fee per participant.
Activity 3: Marks Formatter
Create a program that displays marks with two decimal places in C, C++, Java and Python.
Mini Project
Create a student result system in all four languages using input, output, type casting and mathematical calculations.
3.11 Interactive Final Assessment Quiz
Each correct answer gives +1 mark. Each wrong answer gives -0.5 mark.
1. Python uses input() to receive user input.
2. C commonly uses which function for formatted output?
3. C++ commonly uses cin for input.
4. Java can use Scanner to receive input.
5. In Python, input() returns text by default.
6. Which Python function converts text to decimal number?
7. %.2f can be used for two decimal formatting in C.
8. System.out.println() is used in Java output.
9. Type casting is useful when converting input into numbers.
10. Interactive programs do not need input or output.
Your Score: 0
3.12 Module Summary
This module explained input and output operations using C, C++, Java and Python. Learners practiced user input, display output, formatting, type casting, mathematical calculations and interactive programs through selectable language examples.