-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue_book.cpp
73 lines (65 loc) · 1.62 KB
/
issue_book.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
#include"header.h"
void student::show()
{
cout<<setw(3)<<id<<" "<<setw(25)<<showbookname()<<" "<<setw(15)<<stname<<" "<<setw(16)<<roll<<endl;
}
void issue_book()
{
system("cls");
ofstream fout("issue.txt",ios::app);
student s1;
books *b=&s1;
cout<<"Book ID: ";
cin>>s1.id;
if(checkid(s1.id))
{
cout<<"Book ID not found.....Enter a key to continue...: ";
char ab;
cin>>ab;
if(ab) issue_book();
}
else
{
b->getbookname(getnamebyid(s1.id)); //polymorphism
cin.clear();
cin.ignore(1000,'\n');
cout<<"Student Name: ";
getline(cin,s1.stname);
cout<<"Stdent roll: ";
cin>>s1.roll;
fout<<s1;
cout<<"\n\n Book ID Book Name Student Name Student Roll"<<endl;
cout<<"---------------------------------------------------------------"<<endl;
b->show(); //Runtime Polymorphism
cout<<"Enter m for main menu and Enter s for student info...";
char s;
cin>>s;
if(s=='m') menu();
else { system("cls");
template_use();
cout<<"Enter m for main menu...";
char m;
cin>>m;
if(m) menu();
}
}
}
string getnamebyid(int t)
{
ifstream fin;
fin.open("book.txt");
string line;
while(getline(fin,line))
{
stringstream sin(line);
int val;
string dummy1,dummy2;
sin>>val;sin>>dummy1;sin>>dummy2;
//cout<<val;
if(t==val)
{
return dummy2;
}
//return 1;
}
}