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.

CC++JavaPythonInteractive Code Viewer
Select
Language
Run
Example
View
Code
See
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.

Learning Outcome: Develop interactive programs using input, output formatting, type casting and mathematical calculations in C, C++, Java and Python.

3.2 Language Comparison

ConceptCC++JavaPython
Inputscanf()cinScannerinput()
Outputprintf()coutSystem.out.println()print()
Type Casting(int), (float)(int), static_castInteger.parseInt()int(), float()
Format Decimal%.2ffixed & 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

Click Run Example.
Selected language code will appear here.

3.4 Display Output

Output displays messages, variable values and calculation results.

Online Working Example: Course Details

Click Run Example.
Selected language code will appear here.

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

Click Run Example.
Selected language code will appear here.

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

Click Run Example.
Selected language code will appear here.

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

Click Run Example.
Selected language code will appear here.

3.8 Interactive Programs

An interactive program receives input, processes it and displays useful output.

Online Working Example: Calculator with Language Selection

Click Run Calculator.
Selected language code will appear here.

3.9 Important Notes

Important: The examples on this HTML page simulate execution in the browser and display the matching language implementation code. Actual C, C++ and Java compilation must be done in a compiler or online IDE. Python can be tested in Python IDLE, VS Code, Jupyter Notebook or online Python interpreters.

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.

Remember: The syntax differs across languages, but the logic remains the same: receive input, process data and display output.