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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
#include<conio.h>
#include<iostream>
#include<fstream>
#include<string>
#include<windows.h>
#include<vector>
using namespace std;
string line,line1,line3,line4;
char c;
int d,j,x;
int count=0;
vector<string> line2(100);
int status[100];
int sum;
void gotoxy (short row, short col)
{
COORD coord = {row,col};
SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
}
struct book {
string bname;
string aname;
string bnumber;
};
struct stud
{
string Name;
string Number;
string Course;
string Year;
};
stud p1;
char case1();
char case2();
char case3();
char mainmenu();
int main ()
{
cout<< "\n\n\nWelcome to Library Books Management System\n\n\n";
system ("pause");
system ("cls");
mainmenu();
_getch();
return 0;
}
char case1()
{
{
fstream si;
si.open("books.txt");
char buffer [225];
ifstream fin("books.txt");
if(fin)
{
char ff;
while(fin.get(ff))
cout<<ff;
}
fin.close();
ofstream fout("books.txt",ios::app);
if (!fout)
{
cout<<"unable to open for appending.\n";
return (1);
}
int a,b,c=0;
cout<<"\n--------"<<endl;
cout<<"ADD BOOK";
cout<<"\n--------"<<endl;
cout<<"How many books will you add?: "<<endl;
cin>>a;
book p[300];
for (b=0; b<a; b++) {
cout<<endl;
cout<<"Enter book name: ";
do {
getline (cin,p[b].bname);
}
while
(p[b].bname =="");
cout<<"Enter author name: ";
do {
getline (cin,p[b].aname);
}
while
(p[b].aname =="");
cout<<"Enter book number: ";
cin>>p[b].bnumber;
}
cout<<"\n\nYou added "<<a<<" books\n\n";
for (b=0; b<a; b++) {
fout<<"> Book name: "<<p[b].bname<<endl;
fout<<"] Author name: "<<p[b].aname<<endl;
fout<<"# Book number: "<<p[b].bnumber<<endl;
fout<<endl;
}
cin.ignore(0,'\n');
cin.getline(buffer,225);
fout<<buffer<<"\n";
fout.close();
fin.open("books.txt");
if (!fin)
{
cout<<"Unable to open for reading.\n";
return (1);
}
char ff;
while (fin.get(ff))
cout<<ff;
fin.close();
cout<<"\n\nDo you want another transaction? (Y/N) ";
char character;
cin>>character;
if (character=='y' || character=='Y') {
system ("cls");
mainmenu();
}
else if (character=='n'||character=='N')
exit(0);
else if(character!='y'||character!='Y'||character!='n'||character!='N')
{
cout<<"pls..."<<endl<<"just answer yes or no..";
system("pause");
}
else
exit (0);
}
_getch();
return 0;
}
//INSERT CASE2 CODE HERE//
char case3()
{
{
ifstream si ("books.txt");
if (si.is_open())
{
while (si.good())
{
getline(si,line);
cout<<line<<endl;
}
si.close();
}
else
{
cout<<"Unable to open file";
}
cout<<"\n\nDo you want another transaction? (Y/N) ";
cin>>c;
if (c=='y' || c=='Y') {
system ("cls");
mainmenu();
}
else
exit (0);
}
_getch();
return 0;
}
char mainmenu()
{
cout<<"\n--------------------------------------------------------------------------------"<<endl;
gotoxy (31,2);
cout<<"Library Book System"<<endl;
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"\n[1] Add book\n[2] Borrow book\n[3] Check available books\n[4] Quit";
cout<<"\n\nSelect Transaction: ";
cin>>d;
system ("cls");
book p[200];
switch (d) {
case 1:
case1();
case 2:
case2();
case 3:
case3();
case 4:
exit (0);
break;
}
_getch ();
return 0;
}
|