Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

File Operation Program

Posted By: Easy Tutor     Category: C++ Programming     Views: 14891

Write a program which explains how to write Menu Driven Program in C++. This Menu Driven Program explains how to take get data from user, how to append data, how to modify record and how to display records. It explains complex file concepts in Menu driven fashion. Program also demonstrate File Operation such as How to add record to file, How to append records to file, How to modify records of file and displaying all records from File.

Code for File Operation Program in C++ Programming

/*www.DailyFreeCode.comDownload Projects, Sourcecodes, Tips and Tricks, Interview FAQs, Hotlinks and more....Logon to www.DailyFreeCode.com*///MAKING FILE PROGRAM WITH USING ALL MODES

#include <iostream.h>
#include <fstream.h>
#include <conio.h>

staticint totrec=0;    //totrec variable keep track for total variable entered//Initially Record scanned are Zerovoid main()
{
int choice;
while(1)
{
clrscr();
cout<<"Choose your choice\nNOTE : one choice for one record(except viewing data)\n";
cout<<"1) Scanning intial records\n";
cout<<"2) Appending records\n";
cout<<"3) Modifying or append records\n";
cout<<"4) Viewing records\n";
cout<<"5) Exit\n";
cout<<"Enter your choice : ";
cin>>choice;
switch (choice)
{
  case 1 :   {
         ofstream outfile;
         outfile.open("emp",ios::out);
         cout<<"\n\nPlease enter the details as per demanded\n";
         cout<<"\nEnter the name : ";
         char name[20];
         cin>>name;
         outfile<<name<<endl;
         cout<<"Enter Age : ";
         int age;
         cin>>age;
         outfile<<age<<endl;
         cout<<"Enter programming language known by him\her : ";
         char lang[25];
         cin>>lang;
         outfile<<lang<<endl;
         totrec= totrec + 1;
         outfile.close();
         }
         break;
  case 2 :   {
         ofstream outfile;
         outfile.open("emp",ios::app);
         cout<<"\n\nPlease enter the details as per demanded\n";
         cout<<"\nEnter the name : ";
         char name[20];
         cin>>name;
         outfile<<name<<endl;
         cout<<"Enter Age : ";
         int age;
         cin>>age;
         outfile<<age<<endl;
         cout<<"Enter programming language known by him : ";
         char lang[25];
         cin>>lang;
         outfile<<lang<<endl;
         totrec = totrec + 1;
         outfile.close();
         }
         break;
  case 3 :   {
         ofstream outfile;
         outfile.open("emp",ios::ate);
         cout<<"Are you interested in adding record\nenter y or n\n";
         char ans;
         cin>>ans;
         if(ans=='y' || ans=='Y')
         {
         cout<<"\n\nPlease enter the details as per demanded\n";
         cout<<"\nEnter the name : ";
         char name[20];
         cin>>name;
         outfile<<name<<endl;
         cout<<"Enter Age : ";
         int age;
         cin>>age;
         outfile<<age<<endl;
         cout<<"Enter programming language known by him : ";
         char lang[25];
         cin>>lang;
         outfile<<lang<<endl;
         totrec = totrec + 1;
         }
         outfile.close();
         }
         break;
  case 4 :   {
         ifstream infile;
         infile.open("emp",ios::in);
         constint size=80;
         char line[size];
         int counter=totrec;
         while(counter > 0)
         {
         infile.getline(line,size);
         cout<<"\n\nNAME     : "<<line<<endl;
         infile.getline(line,size);
         cout<<"AGE      : "<<line<<endl;
         infile.getline(line,size);
         cout<<"LANGUAGE : "<<line<<endl;
         counter--;
         }
         infile.close();
         }
         getch();
         break;
  case 5  :  gotoout;
  default :  cout<<"\nInvalid Choice\nTRY AGAIN\n";
  }
}
out:
}
  
Share: 


Didn't find what you were looking for? Find more on File Operation Program Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of File Operation Program is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!