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

What's hot

Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handling
sparkishpearl
 
C++ hello world
C++ hello worldC++ hello world
C++ hello world
AL- AMIN
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyYasuharu Nakano
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
Swarup Boro
 
PHP in 2018 - Q1 - AFUP Limoges
PHP in 2018 - Q1 - AFUP LimogesPHP in 2018 - Q1 - AFUP Limoges
PHP in 2018 - Q1 - AFUP Limoges
✅ William Pinaud
 
20151224-games
20151224-games20151224-games
20151224-games
Noritada Shimizu
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
Noritada Shimizu
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
Luis Vendrame
 
Node.js - iJS 2019
Node.js - iJS 2019Node.js - iJS 2019
Node.js - iJS 2019
NilsMehlhorn
 
Program Kasir c++(case ROti88)
Program Kasir c++(case ROti88)Program Kasir c++(case ROti88)
Program Kasir c++(case ROti88)
Achmad Sidik
 
File handling complete programs in c++
File handling complete programs in c++File handling complete programs in c++
File handling complete programs in c++
zain ul hassan
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with go
Hean Hong Leong
 
Asphalt8.ifgiovanni
Asphalt8.ifgiovanniAsphalt8.ifgiovanni
Asphalt8.ifgiovanni
201419942010
 
Владимир Мигуро "Дао Node.js"
Владимир Мигуро "Дао Node.js"Владимир Мигуро "Дао Node.js"
Владимир Мигуро "Дао Node.js"EPAM Systems
 
Sample file processing
Sample file processingSample file processing
Sample file processingIssay Meii
 
Programming in c
Programming in cProgramming in c
Programming in c
edmspjp
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp
 

What's hot (20)

Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handling
 
C++ hello world
C++ hello worldC++ hello world
C++ hello world
 
Arp
ArpArp
Arp
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
 
PHP in 2018 - Q1 - AFUP Limoges
PHP in 2018 - Q1 - AFUP LimogesPHP in 2018 - Q1 - AFUP Limoges
PHP in 2018 - Q1 - AFUP Limoges
 
20151224-games
20151224-games20151224-games
20151224-games
 
Queue oop
Queue   oopQueue   oop
Queue oop
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
Node.js - iJS 2019
Node.js - iJS 2019Node.js - iJS 2019
Node.js - iJS 2019
 
Program Kasir c++(case ROti88)
Program Kasir c++(case ROti88)Program Kasir c++(case ROti88)
Program Kasir c++(case ROti88)
 
File handling complete programs in c++
File handling complete programs in c++File handling complete programs in c++
File handling complete programs in c++
 
timingExercise
timingExercisetimingExercise
timingExercise
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with go
 
Asphalt8.ifgiovanni
Asphalt8.ifgiovanniAsphalt8.ifgiovanni
Asphalt8.ifgiovanni
 
Владимир Мигуро "Дао Node.js"
Владимир Мигуро "Дао Node.js"Владимир Мигуро "Дао Node.js"
Владимир Мигуро "Дао Node.js"
 
Sample file processing
Sample file processingSample file processing
Sample file processing
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223
 

Viewers also liked

Files in c++
Files in c++Files in c++
Files in c++
Selvin Josy Bai Somu
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
 
File handling
File handlingFile handling
File handling
Nilesh Dalvi
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
Ashwin Francis
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Self-employed
 

Viewers also liked (9)

Files in c++
Files in c++Files in c++
Files in c++
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
File handling in c
File handling in cFile handling in c
File handling in c
 
File handling
File handlingFile handling
File handling
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
file handling c++
file handling c++file handling c++
file handling c++
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12
 

Similar to File Handling Program

So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdf
arjuncollection
 
Cmptr ass
Cmptr assCmptr ass
Cmptr ass
mohit273595
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
Mohammad Shaker
 
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
Language is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docxLanguage is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docx
rennaknapp
 
Usp
UspUsp
Latihan C++ menggunakan setConsoleCursorPosition
Latihan C++ menggunakan setConsoleCursorPositionLatihan C++ menggunakan setConsoleCursorPosition
Latihan C++ menggunakan setConsoleCursorPosition
Achmad Sidik
 
ch5_additional.ppt
ch5_additional.pptch5_additional.ppt
ch5_additional.ppt
LokeshK66
 
C++ practical
C++ practicalC++ practical
C++ practical
Rahul juneja
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
KamranAli649587
 
File & Exception Handling in C++.pptx
File & Exception Handling in C++.pptxFile & Exception Handling in C++.pptx
File & Exception Handling in C++.pptx
RutujaTandalwade
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
ansariparveen06
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
Swarup Boro
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservationSwarup Kumar Boro
 
#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
inbox5
 

Similar to File Handling Program (20)

Sbaw091006
Sbaw091006Sbaw091006
Sbaw091006
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdf
 
Cmptr ass
Cmptr assCmptr ass
Cmptr ass
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
Managing console
Managing consoleManaging console
Managing console
 
Language is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docxLanguage is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docx
 
Usp
UspUsp
Usp
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Latihan C++ menggunakan setConsoleCursorPosition
Latihan C++ menggunakan setConsoleCursorPositionLatihan C++ menggunakan setConsoleCursorPosition
Latihan C++ menggunakan setConsoleCursorPosition
 
ch5_additional.ppt
ch5_additional.pptch5_additional.ppt
ch5_additional.ppt
 
C++ practical
C++ practicalC++ practical
C++ practical
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
 
File & Exception Handling in C++.pptx
File & Exception Handling in C++.pptxFile & Exception Handling in C++.pptx
File & Exception Handling in C++.pptx
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
Opp compile
Opp compileOpp compile
Opp compile
 
C++ programs
C++ programsC++ programs
C++ programs
 
#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
 

Recently uploaded

somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
Howard Spence
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
Vladimir Samoylov
 
María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024
eCommerce Institute
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Matjaž Lipuš
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
OECD Directorate for Financial and Enterprise Affairs
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Orkestra
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
IP ServerOne
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
Sebastiano Panichella
 
Media as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern EraMedia as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern Era
faizulhassanfaiz1670
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
OWASP Beja
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
khadija278284
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Sebastiano Panichella
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Sebastiano Panichella
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
Access Innovations, Inc.
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
Faculty of Medicine And Health Sciences
 
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdfSupercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Access Innovations, Inc.
 

Recently uploaded (16)

somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
 
María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
 
Media as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern EraMedia as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern Era
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
 
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdfSupercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
 

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