-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15. File.cpp
50 lines (49 loc) · 1.16 KB
/
15. File.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class student_info{
public:
char name[20];
int age;
char sex;
float height;
float weight;
void read(ofstream &);
void write(ifstream &);
};
void student_info::read(ofstream &fout){
cout<<"\nEnter Name:";cin>>name;
cout<<"Enter Age:";cin>>age;
cout<<"Enter Sex (F/M):";cin>>sex;
cout<<"Enter Height:";cin>>height;
cout<<"Enter Weight:";cin>>weight;
fout<<"\nName : "<<name<<endl;
fout<<"Age :"<<age<<endl;
fout<<"Sex :"<<sex<<endl;
fout<<"Height :"<<height<<endl;
fout<<"Weight :"<<weight<<endl;
}
void student_info::write(ifstream &fin){
string line;
while(getline(fin,line)){
cout<<line<<endl;
}
}
int main(){
cout<<"Enter the No. of Records:";
int n;
cin>>n;
student_info student;
ofstream fout;
fout.open("data1.txt");
for(int i=0;i<n;i++)
student.read(fout);
fout.close();
cout<<"----Displaying Contents of the file---- \n";
ifstream fin;
fin.open("data1.txt");
student.write(fin);
fin.close();
return 0;
}