C++ class program – illestrate File operations

by Nideesh C on April 14, 2011 · 4 comments

in C++




AIM
Write a program to illustrate the write() member function which are usually used for transfer of data blocks to the file.

ALGORITHM

1. Start the process
2. Invoke the class
a. Create two inline member functions .ie, getdata() and dispdata()
i. getdata() for input
ii. dispdata() for display
3. Open the file in fstream mode
4. Write the data in to the file
5. Slose the file
6. Stop the process

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class student
{
private:
int rno;
char name[10];
float fees;
public:
void getdata()
{
cout<<"roll number";
cin>>rno;
cout<<endl;
cout<<"enter name:";
cin>>name;
cout<<endl<<"enter fees:";
cin>>fees;
}
void dispdata()
{
cout<<"Roll number"<<rno<<endl;
cout<<"Name"<<name<<endl;
cout<<"Fees"<<fees;
}
};
 
void main()
{
student s1;
clrscr();
ofstream stdfile("c:\\std.txt");
//fstream stdfile;
//stdfile.open("c:\\std.txt",ios::out|ios::in);  //open file for output
char wish;
//writing to the file
do
{
s1.getdata();
stdfile.write((char*)&s1,sizeof(student));
cout<<"continue ? y/n";
cin>>wish;
}
while(wish=='y'||wish=='Y');
stdfile.close();   //close the file
 
getch();
}



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C++ program – Using class to generate mark sheet using multiple inheritance
  2. C++ class program – perform rational number arithmetic
  3. C++ program to implement Binary Search Tree(BST) and its Operations
  4. C++ program to implement Shell sort using class
  5. C++ program – Perform complex arithmetic using operator overloading

{ 3 comments… read them below or add one }

1 Ligila April 18, 2011 at 9:07 pm

This is what i am looking for, awsome website – C++ class program – illestrate File operations

Reply

2 Anonymous May 20, 2011 at 2:13 pm

I like theonlinetutorials.com (C++ class program – illestrate File operations) , bookmarked for future reference

Reply

3 Winstrol May 20, 2011 at 8:12 pm

I love theonlinetutorials.com , bookmarked for future reference

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: