-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.cpp
103 lines (92 loc) · 2.38 KB
/
person.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
class person
{
int p_id;
char fname[20], mname[20], lname[20];
int age_ason_1Jan2000;
char disability;
char gender;
public:
void enter_infilep()
{
person p;
ofstream ofs("people.txt", ios :: app);
ofs<<p_id<<'\t'<<fname<<'\t'<<mname<<'\t'<<lname<<'\t'<<age_ason_1Jan2000<<'\t'<<disability<<'\t'<<gender<<'\n';
ofs.close();
}
void enter_newp()
{
char c;
do
{
cout<<"Enter p_id:\n";
cin>>p_id;
cout<<"Enter name: <fname mname lname>\n";
cin>>fname>>mname>>lname;
cout<<"Enter age as on 1st January 2000\n";
cin>>age_ason_1Jan2000;
cout<<"Enter disability status:('n'->no;'s'->severe;)\n";
cin>>disability;
cout<<"Enter gender:('m'->male; 'f'->female)\n";
cin>>gender;
cout<<"Please enter the following information. Once entered, it cannot be updated.\n\n";
displayp();
cout<<"Is the above information correct?(y/n):\t";
cin>>c;
}while(c=='n');
enter_infilep();
}
void displayp()
{
cout<<"ID:\t"<<p_id<<endl
<<"First Name:\t"<<fname<<endl
<<"Middle Name:\t"<<mname<<endl
<<"Last Name:\t"<<lname<<endl
<<"Age as on 1 January 2000:\t"<<age_ason_1Jan2000<<endl
<<"Disability Status:('n'-> no; 's'->severe;)\t"<<disability<<endl
<<"Gender:('m'->male; 'f'->female)\t"<<gender<<endl;
}
friend person getp(int d);
};
person getp(int d)
{
person p;
ifstream ifs("people.txt");
int i=0;
try
{
do
{
i++;
ifs>>p.p_id>>p.fname>>p.mname>>p.lname>>p.age_ason_1Jan2000>>p.disability>>p.gender;
if(i>99)
{
cout<<"Wrong p_id :(\n";
throw 0;
}
}while(p.p_id != d);
}
catch(int a)
{
ifs.close();
throw 0;
}
ifs.close();
return p;
}
main()
{
person p, g;
//p.enter_newp();
try{
g= getp(8);
g.displayp();
}
catch(int a)
{
cout<<"no id matches\n";
}
}