-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOP_Prac04.cpp
80 lines (77 loc) · 1.56 KB
/
OOP_Prac04.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
#include <iostream>
#include <fstream>
using namespace std;
class student
{
private:
string name;
int rollno;
public:
void add_info()
{
fstream fs;
fs.open("main.txt", ios::app);
if (!fs)
cout << "File Creation failed";
else
{
cout << "enter name of student :";
cin >> name;
cout << "enter roll no.:";
cin >> rollno;
fs << name << " ";
fs << rollno << "\n";
fs.close();
}
}
void display()
{
fstream fs;
fs.open("main.txt", ios::in);
if (!fs)
cout << "No Such file";
else
{
while (!fs.eof())
{
fs >> name;
fs >> rollno;
if (!fs.eof())
{
cout << name << " ";
cout << rollno << " ";
}
cout << "\n";
}
}
fs.close();
}
};
int main()
{
student s1;
int ch;
fstream fs;
do
{
cout << "\n Student database:";
cout << "\n Menu";
cout << "\n 1. Add student Information";
cout << "\n 2. Display student Information";
cout << "\n 3. Exit";
cout << "\n Enter your choice";
cin >> ch;
switch (ch)
{
case 1:
s1.add_info();
break;
case 2:
s1.display();
break;
case 3:
exit(0);
}
} while (ch != 3);
return 0;
}