The document describes a C++ program that demonstrates file input/output operations. The program allows the user to enter employee data including name, employee ID, and salary. This data is written to an output file. The file is then closed and reopened as an input file to read and display the stored employee information. The program accepts data for multiple employees defined by the user and stores it in an output file, then reads the data from the file and displays it.
The document describes a C++ program that demonstrates file input/output operations. The program allows the user to enter employee data including name, employee ID, and salary. This data is written to an output file. The file is then closed and reopened as an input file to read and display the stored employee information. The program accepts data for multiple employees defined by the user and stores it in an output file, then reads the data from the file and displays it.
The document describes a C++ program that demonstrates file input/output operations. The program allows the user to enter employee data including name, employee ID, and salary. This data is written to an output file. The file is then closed and reopened as an input file to read and display the stored employee information. The program accepts data for multiple employees defined by the user and stores it in an output file, then reads the data from the file and displays it.
Roll no - 24 Pract no: 08 Group: A(1) Title: Demonstrate various file operations using C++. Objectives: 1) To learn and understand streams and files in object oriented paradigm. 2) To demonstrate file operations like create, open, read, write and close a file. Problem Statement: Write a C++ program that creates an output file, writes information to it, closes the file and open it again as an input file and read the information from the file. */ #include<iostream> #include<fstream> using namespace std; class file{ char name[20]; int emp_id; float salary; public: void accept() { cin>>name; cin>>emp_id; cin>>salary; } void display() { cout<<"\n"<<name<<"\t"<<emp_id<<"\t"<<salary; } }; int main() { file o[5]; fstream f; int i,n; f.open("input1.txt"); cout<<"\n How many employee information wanted to store"; cin>>n; cout<<"\n Enter information of employees(Enter name,emp_id,salary)"; for(i=0;i<n;i++) { cout<<"\n enter information of" <<i<< "employee:\n "; o[i].accept(); //accept input foem user f.write((char*) &o[i],sizeof(o[i])); //write object in file } f.close(); f.open("input",ios::in); cout<<"\n Information of employee is as follows"; for(i=0;i<n;i++) { f.read((char*) &o[i],sizeof(o[i])); //read data form file o[i].display(); //display data } f.close(); return 0; } /* How many employee information wanted to store3
Enter information of employees(Enter name,emp_id,salary)
enter information of0employee: ms 123 12000
enter information of1employee:
sc 234 11000
enter information of2employee:
sm 124 10000
Information of employee is as follows
ms 123 12000 sc 234 11000 sm 124 10000[student@localhost ~]$