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<string>
using namespace std;
void read();
void write();
void update();
int main()
{
read();
write();
update();
}
void read()
{
ofstream f;
int itemnumber,availability,n;
string author,title;
f.open("file.txt");
cout<<"Enter number of books: ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter item number: ";
cin>>itemnumber;
cin.get();
cout<<"Enter title: ";
getline(cin,title);
cout<<"Enter author: ";
getline(cin,author);
cout<<"Enter availability:";
cin>>availability;
f<<itemnumber<<" "<<title<<", "<<author<<", "<<availability<<endl;
}
f.close();
}
void write()
{
ifstream f;
int itemnumber,availability;
string author,title;
f.open("file.txt");
while(!f.eof())
{
f>>itemnumber;
getline(f,title,',');
getline(f,author,',');
f>>availability;
cout<<itemnumber<<" "<<title<<" "<<author<<" "<<availability<<endl;
}
f.close();
}
void update()
{
ifstream f;
ofstream t;
int itemnumber,availability,choose;
string author,title,searching;
f.open("file.txt");
t.open("temp.txt");
cout<<"Enter title for search: ";
cin.get();
getline(cin,searching,',');
while(!f.eof())
{
f>>itemnumber;
f.get();
getline(f,title,',');
f.get();
getline(f,author,',');
f>>availability;
if(searching==title)
{cout<<"Enter 0 for renting and 1 for returning ";
cin>>choose;
if(choose==0)
availability --;
if(choose==1)
availability ++;
else
cout<<"Invalid choice "; break;
}
else
cout<<"There isnt a book with this name "; break;
t<<itemnumber<<" "<<title<<", "<<author<<", "<<availability<<endl;
}
t.close();
f.close();
ifstream d;
ofstream a;
d.open("temp.txt");
a.open("file.txt");
while(!t.eof());
{
d>>itemnumber;
getline(d,title,',');
getline(d,author,',');
d>>availability;
a<<itemnumber<<" "<<title<<", "<<author<<", "<<availability<<endl;
}
}
|