CS-409
Presentation
Report
BSIT (3rd Semester)
Section A
Submitted to :
Ms. Iqra Aslam
GROUP D
Usman Ali 2024-ag-3710
Rabia Adeel 2024-ag-3715
Kinza Neyab 2024-ag-4182
Muhammad Waqas Akram 2024-ag-10198
Hira Maqsood 2024-ag-8346
Laiba Murtaza 2024-ag-8075
Zeeshan Saleem 2024-ag-3713
Aaila 2024-ag-3702
Maheen Akhtar 2024-ag-8638
Muhammad Ammar 2024-ag-4512
Contents
Topic: File Processing and Object Stream ..................................................................................................... 1
Introduction .............................................................................................................................................. 1
FILE PROCESSING .......................................................................................................................................... 1
Definition .................................................................................................................................................. 1
Types of Files in C++ .................................................................................................................................. 1
Text Files ................................................................................................................................................... 1
Binary Files ................................................................................................................................................ 2
C++ Libraries for File Processing ............................................................................................................... 3
File Operations .......................................................................................................................................... 4
File Processing in OOP............................................................................................................................... 4
Example of File Processing (C++) .............................................................................................................. 5
Advantages of File Processing ................................................................................................................... 5
Disadvantages of File Processing .............................................................................................................. 5
OBJECT STREAM ............................................................................................................................................ 6
Definition: ................................................................................................................................................. 6
Explanation ............................................................................................................................................... 6
Types of Object Streams ........................................................................................................................... 6
Purpose of Object Stream ......................................................................................................................... 7
Working of Object Stream ........................................................................................................................ 7
Object Stream in C++ – Core Functions .................................................................................................... 8
Example of Object Stream (C++) ............................................................................................................... 8
Explanation of the program ...................................................................................................................... 9
Advantages of Object Stream ................................................................................................................... 9
Disadvantages of Object Stream ............................................................................................................... 9
Applications............................................................................................................................................. 10
Conclusion ................................................................................................................................................... 10
[File Processing and Object Stream]
Topic: File Processing and Object Stream
Introduction
File Processing is an important concept in Object Oriented Programming. It is used to store data
permanently in files so that data is not lost when the program ends. Instead of storing data only in
memory (RAM), file processing allows data to be saved on secondary storage like hard disk.
Object Stream is an advanced concept of file handling which allows complete objects to be stored
and retrieved from files.
FILE PROCESSING
Definition
File processing means reading data from a file and writing data into a file. It helps in permanent
data storage and data reuse.
Types of Files in C++
Text Files
A text file is a file that stores data in the form of readable characters. The data is saved as plain
text, which can be easily opened and read using text editors like Notepad or Notepad++.
Examples:
.txt
.csv
.html
GROUP D | CS-409 PRESENTATION REPORT 1
[File Processing and Object Stream]
.java
.xml
Characteristics of Text Files
Data is stored in human-readable form.
Each character is stored using ASCII or Unicode.
Easy to create, read, and edit
Takes more storage space compared to binary files
Slower in processing
Uses of Text Files
Storing simple data
Configuration files
Source code files
Logs and reports
Example (Conceptual)
Name: Ali
Age: 20
Department: IT
Binary Files
A binary file stores data in binary format (0s and 1s). The data is not human-readable and can only
be understood by a program.
Examples of Binary Files
.dat
.bin
.exe
.class
.jpg
.mp3
GROUP D | CS-409 PRESENTATION REPORT 2
[File Processing and Object Stream]
Characteristics of Binary Files
Data is stored in machine-readable form
Cannot be read using simple text editors
Faster processing
Uses less storage space
More secure than text files
Uses of Binary Files
Storing objects in OOP
Multimedia files (images, audio, video)
Executable programs
Databases
C++ Libraries for File Processing
1. <fstream>
Main library for file input/output in C++.
It provides classes to handle files:
ifstream → Input File Stream (for reading files)
ofstream → Output File Stream (for writing files)
fstream → File Stream (for both reading and writing)
2. <iostream>
Standard input/output library.
Used along with <fstream> for displaying messages on console (cout, cin).
3. <string>
Used for handling strings while reading/writing text from/to files.
GROUP D | CS-409 PRESENTATION REPORT 3
[File Processing and Object Stream]
File Operations
1. Create a File
Creating a file means making a new file to store data. A file is created when we want to save
information permanently.
2. Open a File
Opening a file means accessing an existing file so that data can be read from it or written into it.
3. Write Data into a File
Writing data into a file means storing information such as text, numbers, or records in a file.
4. Read Data from a File
Reading data from a file means retrieving or viewing the data that is already stored in the file.
5. Close a File
Closing a file means ending the file operation. It ensures that all data is saved properly and system
resources are released.
File Processing in OOP
Object Oriented Programming (OOP), file processing is very important because it allows programs
to save object data and reuse it later. Without file processing, all data would be lost when the
program ends. Therefore, file processing plays a vital role in building reliable and efficient
software systems.
GROUP D | CS-409 PRESENTATION REPORT 4
[File Processing and Object Stream]
Example of File Processing (C++)
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream file("[Link]");
file << "Welcome to File Processing";
[Link]();
return 0;
}
Explanation
This program creates a file named "[Link]" and writes text into it.
Advantages of File Processing
Permanent data storage
Large amount of data can be stored
Data can be reused
Backup is possible
Disadvantages of File Processing
File handling is complex
Security issues
Slower than memory operations
GROUP D | CS-409 PRESENTATION REPORT 5
[File Processing and Object Stream]
OBJECT STREAM
Definition:
Object Stream is used to store complete objects into a file. Instead of saving individual variables,
object stream saves the whole object with its data and structure.
Explanation
An Object Stream is a type of stream in Java that allows you to read and write objects to and from
a file. Unlike regular file streams that handle only primitive data types (like int, float, char), object
streams can directly store objects with their complete state (all attributes) in a file. This is a key
feature in Object-Oriented Programming (OOP) for persisting objects.
Types of Object Streams
1. ObjectOutputStream
Used to write objects into a file.
Converts the object into a byte stream so it can be saved.
Example: Saving a Student object into a file.
2. ObjectInputStream
Used to read objects from a file.
Reconstructs the object from the byte stream.
Example: Loading a Student object from a file.
GROUP D | CS-409 PRESENTATION REPORT 6
[File Processing and Object Stream]
Purpose of Object Stream
Store Objects in Files:
The main purpose of an Object Stream is to save Java objects to a file, preserving the complete
object with all its attributes.
Retrieve Objects from Files:
It allows you to read objects back from a file so they can be reused in the program.
Serialization and Deserialization:
Serialization: Converting an object into bytes to store it in a file.
Deserialization: Reading bytes from a file and converting them back into the original object.
Ease of Handling Complex Data:
Object Streams make it easy to save and retrieve complex data structures like arrays, lists, or
custom objects without manually converting them to text or binary.
Data Persistence:
Object Streams ensure that data persists even after the program ends, allowing objects to be reused
later.
Working of Object Stream
1. Object is created in the program
2. Object data is converted into a stream
3. Stream is written into a file
4. File can be read later to reconstruct the object
GROUP D | CS-409 PRESENTATION REPORT 7
[File Processing and Object Stream]
Object Stream in C++ – Core Functions
Object Stream in C++ is used to read and write objects to a binary file. Its core functions are:
1. write() – Used to write an object to a binary file.
2. read() – Used to read an object from a binary file into memory.
3. open() – Opens a file in read, write, or read/write mode.
4. close() – Closes the file after operations are completed.
5. reinterpret_cast<char*> – Converts an object pointer to char* for use with read() and write().
6. ios::binary – Opens the file in binary mode so that data is stored exactly as bytes.
Example of Object Stream (C++)
#include <iostream>
#include <fstream>
using namespace std;
class Student {
public:
int rollNo;
char name[30];
float marks;
};
int main() {
Student s;
// Assigning values
GROUP D | CS-409 PRESENTATION REPORT 8
[File Processing and Object Stream]
[Link] = 101;
strcpy([Link], "Ahmed Ali");
[Link]=85.5;
//wrting object to file
ofstream outFile("[Link]", ios::binary);
[Link]((char*)&s, sizeof(s));
[Link]();
cout << "Student object saved successfully.";
return 0;
}
Explanation of the program
This program demonstrates object stream in C++.
A Student class is created with roll number, name, and marks.
The complete object is written into a binary file using ofstream.
This method allows storing the entire object at once, which is efficient and secure.
Advantages of Object Stream
Complete object is stored
Easy to manage data
Maintains object structure
Disadvantages of Object Stream
Only serializable objects can be saved
File size is large
Language dependent
GROUP D | CS-409 PRESENTATION REPORT 9
[File Processing and Object Stream]
Applications
Student record system
Banking systems
Inventory management systems
Conclusion
File processing is used for permanent data storage, while object stream makes it easy to store and
retrieve complete objects. Both concepts are very important in Object Oriented Programming and
are widely used in real-life [Link] conclusion, file processing and object stream are both
important techniques for storing data in files, but they differ in their approach. File processing
deals with simple data such as text and numbers and works at the data level, where the programmer
has to manage the format of the data manually. On the other hand, object stream works at the object
level and allows complete objects of a class to be stored and retrieved directly from files. Object
stream supports object-oriented programming concepts and makes data handling easier, more
organized, and efficient. Therefore, file processing is suitable for simple data storage, while object
stream is more suitable for complex applications that require saving and restoring objects.
GROUP D | CS-409 PRESENTATION REPORT 10