-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObj_Filing.cpp
83 lines (56 loc) · 1.87 KB
/
Obj_Filing.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;
class Student
{
int roll;
char name[25];
float marks;
void getdata()
{
cout<<"\n\nEnter Roll : ";
cin>>roll;
cout<<"\nEnter Name : ";
cin>>name;
cout<<"\nEnter Marks : ";
cin>>marks;
}
void fetchdata()
{
cout<<"\n\t"<<roll<<"\t"<<name<<"\t"<<marks;
}
public:
void AddRecord()
{
fstream f;
Student Stu;
f.open("Student1.txt",ios::app|ios::binary);
Stu.getdata();
f.write( (char *) &Stu, sizeof(Stu) );
f.close();
}
void Display()
{
fstream f;
Student Stu;
f.open("Student.txt",ios::in|ios::binary);
cout<<"\n\tRoll\tName\tMarks\n";
while( (f.read((char*)&Stu,sizeof(Stu))) != NULL )
Stu.fetchdata();
f.close();
}
};
int main()
{
Student S;
char ch='n';
do
{
S.Display();
cout<<"\n\nDo you want to add another data (y/n) : ";
ch = getche();
} while(ch=='y' || ch=='Y');
cout<<"\nData written successfully...";
S.Display();
}