SlideShare a Scribd company logo
oop_1
#include <iostream>
#include <fstream>
using namespace std;
class inventory
{
char name[20];
int qty;
double price,total;
public:
void getdata()
{
cout<<"enter Name "; cin>>name;
cout<<"Enter Qty ";cin>>qty;
cout<<"Enter price ";cin>>price;
total=qty*price;
}
void putdata()
{
cout.setf(ios::left,ios::adjustfield);
cout.width(15);
cout<<name;
cout.width(10);
cout<<price;
cout.width(10);
cout<<qty;
cout.width(10);
cout<<total;
cout<<endl;
}
};
int main()
{
int i=0;int ch;
fstream inout;
inventory item[5];
//inout.open("stock.txt",ios::in|ios::out);
do
{
cout<<"File Handling with Class"<<endl;
cout<<"Menu for File Operation"<<endl;
cout<<"1. Write Data into File"<<endl;
cout<<"2. Read Data From File"<<endl;
cout<<"3. Exit "<<endl;
cout<<"Enter your Choice "; cin>>ch;
switch(ch)
Page 1
oop_1
{
case 1:
{
inout.open("stock.txt",ios::in|ios::out|ios::ate);
//cout<<tellp();
item[i].getdata();
inout.write((char *)& item[i], sizeof(item[i]));
i++;
inout.clear();
inout.close();
break;
}
case 2:
{
inout.open("stock.txt",ios::in);
inout.seekg(0,ios::beg);
cout.setf(ios::left,ios::adjustfield);
cout.width(15);cout<<"Item Name";
cout.width(10);cout<<"Price";cout.width(10);cout<<"Qty";cout.width(15);cout<<"Total
Amt"<<endl;
cout.width(55);
cout.fill('-');
cout<<"-"<<endl;
cout.fill(' ');
for(int j=0;j<=i;j++)
{
while(inout.read((char *)& item[i],sizeof(item[i])))
{
item[i].putdata();
}
}
inout.close();
break;
}
case 3:
{
return 0;
}
default:
{
cout<<"Enter valid choice "<<endl;
break;
}
}
}while(true);
return 0;
Page 2
oop_1
}
Page 3

More Related Content

PDF
The Big Three
DOCX
file handling
TXT
Problemas de Arreglos en c++
KEY
サイ本 文
PPTX
Php 7.x 8.0 and hhvm and
PPTX
Extending php (7), the basics
The Big Three
file handling
Problemas de Arreglos en c++
サイ本 文
Php 7.x 8.0 and hhvm and
Extending php (7), the basics

What's hot (20)

DOCX
Exmaples of file handling
PPTX
C++ hello world
DOCX
PDF
JavaSE7 Launch Event: Java7xGroovy
DOCX
Array using recursion
PPTX
PHP in 2018 - Q1 - AFUP Limoges
PDF
20151224-games
PPTX
Queue oop
PDF
2016 gunma.web games-and-asm.js
PDF
JavaScript - Agora nervoso
PDF
Node.js - iJS 2019
DOCX
Program Kasir c++(case ROti88)
TXT
File handling complete programs in c++
DOCX
timingExercise
PDF
Go serving: Building server app with go
TXT
Asphalt8.ifgiovanni
PPT
Владимир Мигуро "Дао Node.js"
PPT
Sample file processing
PPTX
Programming in c
DOCX
Jarmo van de Seijp Shadbox ERC223
Exmaples of file handling
C++ hello world
JavaSE7 Launch Event: Java7xGroovy
Array using recursion
PHP in 2018 - Q1 - AFUP Limoges
20151224-games
Queue oop
2016 gunma.web games-and-asm.js
JavaScript - Agora nervoso
Node.js - iJS 2019
Program Kasir c++(case ROti88)
File handling complete programs in c++
timingExercise
Go serving: Building server app with go
Asphalt8.ifgiovanni
Владимир Мигуро "Дао Node.js"
Sample file processing
Programming in c
Jarmo van de Seijp Shadbox ERC223
Ad

Viewers also liked (9)

PPSX
Files in c++
PPTX
basics of file handling
PPT
File handling in c
PPT
File handling
PDF
file handling c++
DOCX
12th CBSE Practical File
PDF
Computer Science Investigatory Project Class 12
Files in c++
basics of file handling
File handling in c
File handling
file handling c++
12th CBSE Practical File
Computer Science Investigatory Project Class 12
Ad

Similar to File Handling Program (20)

KEY
Sbaw091006
PDF
So I already have most of the code and now I have to1. create an .pdf
DOCX
Cmptr ass
PDF
C++ L05-Functions
DOCX
Oop lab report
PPTX
Managing console
DOCX
Language is C++ I'm having trouble making my code meet these requireme.docx
DOCX
File handling in c++
PDF
Latihan C++ menggunakan setConsoleCursorPosition
PPT
ch5_additional.ppt
PDF
C++ practical
PPT
C++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPT
PPT
C++InputOutput.PPT
PPTX
File & Exception Handling in C++.pptx
PPTX
C++InputOutput.pptx
TXT
c++ program for Railway reservation
TXT
Railway reservation
DOCX
Opp compile
PDF
C++ programs
Sbaw091006
So I already have most of the code and now I have to1. create an .pdf
Cmptr ass
C++ L05-Functions
Oop lab report
Managing console
Language is C++ I'm having trouble making my code meet these requireme.docx
File handling in c++
Latihan C++ menggunakan setConsoleCursorPosition
ch5_additional.ppt
C++ practical
C++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPT
C++InputOutput.PPT
File & Exception Handling in C++.pptx
C++InputOutput.pptx
c++ program for Railway reservation
Railway reservation
Opp compile
C++ programs

Recently uploaded (20)

DOCX
"Project Management: Ultimate Guide to Tools, Techniques, and Strategies (2025)"
PPTX
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
PPTX
Sustainable Forest Management ..SFM.pptx
DOCX
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
PDF
Instagram's Product Secrets Unveiled with this PPT
PPTX
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
PPTX
Intro to ISO 9001 2015.pptx wareness raising
PPTX
Self management and self evaluation presentation
PPTX
2025-08-10 Joseph 02 (shared slides).pptx
PPTX
Introduction-to-Food-Packaging-and-packaging -materials.pptx
PPTX
Anesthesia and it's stage with mnemonic and images
PDF
oil_refinery_presentation_v1 sllfmfls.pdf
PPTX
Relationship Management Presentation In Banking.pptx
PPTX
water for all cao bang - a charity project
PDF
Microsoft-365-Administrator-s-Guide_.pdf
PDF
Presentation1 [Autosaved].pdf diagnosiss
PPTX
nose tajweed for the arabic alphabets for the responsive
PPTX
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
_ISO_Presentation_ISO 9001 and 45001.pptx
PPTX
Human Mind & its character Characteristics
"Project Management: Ultimate Guide to Tools, Techniques, and Strategies (2025)"
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
Sustainable Forest Management ..SFM.pptx
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
Instagram's Product Secrets Unveiled with this PPT
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
Intro to ISO 9001 2015.pptx wareness raising
Self management and self evaluation presentation
2025-08-10 Joseph 02 (shared slides).pptx
Introduction-to-Food-Packaging-and-packaging -materials.pptx
Anesthesia and it's stage with mnemonic and images
oil_refinery_presentation_v1 sllfmfls.pdf
Relationship Management Presentation In Banking.pptx
water for all cao bang - a charity project
Microsoft-365-Administrator-s-Guide_.pdf
Presentation1 [Autosaved].pdf diagnosiss
nose tajweed for the arabic alphabets for the responsive
The Effect of Human Resource Management Practice on Organizational Performanc...
_ISO_Presentation_ISO 9001 and 45001.pptx
Human Mind & its character Characteristics

File Handling Program

  • 1. oop_1 #include <iostream> #include <fstream> using namespace std; class inventory { char name[20]; int qty; double price,total; public: void getdata() { cout<<"enter Name "; cin>>name; cout<<"Enter Qty ";cin>>qty; cout<<"Enter price ";cin>>price; total=qty*price; } void putdata() { cout.setf(ios::left,ios::adjustfield); cout.width(15); cout<<name; cout.width(10); cout<<price; cout.width(10); cout<<qty; cout.width(10); cout<<total; cout<<endl; } }; int main() { int i=0;int ch; fstream inout; inventory item[5]; //inout.open("stock.txt",ios::in|ios::out); do { cout<<"File Handling with Class"<<endl; cout<<"Menu for File Operation"<<endl; cout<<"1. Write Data into File"<<endl; cout<<"2. Read Data From File"<<endl; cout<<"3. Exit "<<endl; cout<<"Enter your Choice "; cin>>ch; switch(ch) Page 1
  • 2. oop_1 { case 1: { inout.open("stock.txt",ios::in|ios::out|ios::ate); //cout<<tellp(); item[i].getdata(); inout.write((char *)& item[i], sizeof(item[i])); i++; inout.clear(); inout.close(); break; } case 2: { inout.open("stock.txt",ios::in); inout.seekg(0,ios::beg); cout.setf(ios::left,ios::adjustfield); cout.width(15);cout<<"Item Name"; cout.width(10);cout<<"Price";cout.width(10);cout<<"Qty";cout.width(15);cout<<"Total Amt"<<endl; cout.width(55); cout.fill('-'); cout<<"-"<<endl; cout.fill(' '); for(int j=0;j<=i;j++) { while(inout.read((char *)& item[i],sizeof(item[i]))) { item[i].putdata(); } } inout.close(); break; } case 3: { return 0; } default: { cout<<"Enter valid choice "<<endl; break; } } }while(true); return 0; Page 2