Anda di halaman 1dari 14

#include<iostream>

#include<cstdlib>
#include <string>
#include<fstream.>
#include<iomanip>
#include<conio.h>
using namespace std;
int
int
int
int

n,n1; //global variables


i;
count=0;
count1=0;

//CLASSES USED IN PROJECT


class book
{
public:
char bookcode;
char bookname[20];
char authorname[20];
char bookpub[20];
int bookprice;
int status;
public:
void addbook()
//function declared for adding books
{
system("cls");
status=1;
cout<<"\t\t\t YOU HAVE CHOSEN TO ADD BOOK DETAILS"<<endl;
cout<<"\t\t\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<endl;
count++;
bookcode=100+count;
cout<<"\n\tBook code
:"<<bookcode;
cout<<endl;
cout<<"\n\tEnter book name
:";
cin>>bookname;
cout<<"\n\tEnter author name
:";
cin>>authorname;
cout<<"\n\tEnter publishing company :";
cin>>bookpub;
cout<<"\n\tEnter book price
:";
cin>>bookprice;
}
void dispbook()
//function to display all the books
{
cout<<bookcode<<"\t\t"<<bookname<<"\t\t"<<authorname<<"\t\t"<<bookpub<<"\t\t"<
<bookprice<<endl;
}
void modify_book()
{
cout<<"\nEnter Book code : "<<bookcode;
cout<<"\nModify Book Name : ";
gets(bookname);
cout<<"\nModify Author's Name of Book : ";

gets(authorname);
}
char retbookcode()
{
return bookcode;
}
void bookrecord()
//function to display book records
{
cout<<"\t\tbookcode<<<<bookname<<authorname"<<endl;
}
void listbook()
//function to check availability of the
book
{
if(status==1)
{
cout<<"\t\tBookcode:"<<bookcode<<"\t\tStatus:Available"<<endl;
cout<<endl;
}
else
{
cout<<"\t\tBookcode:"<<bookcode<<"\t\tStatus:Issued"<<endl;
cout<<endl;
}
}
};book b[10];
class student
{
public:
int studid;
char studname[20];
char coursename[20];
int bookcount;
int flag;
public:
void addstud()
{
system("cls");
cout<<"\t\tYOU HAVE CHOSEN TO ADD STUDENT DETAILS"<<endl;
cout<<"\t\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<endl;
cout<<endl;
count1++;
studid=100+count1;
cout<<"\t\tStudent Id
:"<<studid;
cout<<endl;
cout<<endl;
cout<<"\t\tEnter Student Name
:";
cin>>studname;
cout<<endl;
cout<<"\t\tEnter Course Name :";
cin>>coursename;
cout<<endl;
bookcount=2;
cout<<endl;
cout<<"\t\tMaximum books allowed for a student:"<<bookcount<<endl;
cout<<endl;

}
void dispstud()
{
cout<<"\t"<<studid<<"\t\t"<<studname<<"\t\t"<<coursename<<endl;
//bookcount=2;
cout<<endl;
}
void modify_student()
{
cout<<"\n Course Name : "<<coursename;
cout<<"\nModify Student Name : ";
gets(studname);
}
char retcoursename()
{
return coursename;
}
char retstudid()
{
return studid;
}
int retflag()
{
return flag;
}
void addflag()
{flag=1;}
void resettoken()
{flag=0;}
void getstudid(char t[])
{
strcpy(studid,t);
}
void report()
{cout<<"\t"<<studid<<studname<<flag<<endl;}
};student s[10];

//class ends here

//global declaration of stream objects


fstream fp,fp1;
book bk;
student st;
//function to write in file
void write_book()
{
char ch;

fp.open("book.txt",ios::out|ios::app);
do
{
system("cls");
bk.addbook();
fp.write((char*)&bk,sizeof(book));
cout<<"do you want to add more record(y/n)?"<<endl;
cin>>ch;
}
while(ch=='y'||ch=='Y');
fp.close();
}
void write_student()
{
char ch;
fp.open("student.txt",ios::out|ios::app);
do
{
st.addstud();
fp.write((char*)&st,sizeof(student));
cout<<"do you want to add more record..(y/n)?";
cin>>ch;
}
while(ch=='y'||ch=='Y');
fp.close();
}
void display_book(char n[])
{
cout<<"\nBOOK DETAILS\n";
int flag=0;
fp.open("book.txt",ios::in);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbookcode(),n)==0)
{
bk.dispbook();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nBook does not exist";
getch();
}
void display_student(char n[])
{
cout<<"\nSTUDENT DETAILS\n";
int flag=0;
fp.open("student.txt",ios::in);
while(fp.read((char*)&st,sizeof(student)))
{
if((strcmpi(st.retstudid(n))==0))
{
st.dispstud();

flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nStudent does not exist";
getch();
}
// function to modify details
void modify_book()
{
char n[6];
int found=0;
system("cls");
cout<<"\n\n\tMODIFY BOOK REOCORD.... ";<<endl;
cout<<"\n\n\tEnter the bookcode";endl;
cin>>n;
fp.open("book.txt",ios::in|ios::out);
while(fp.read((char*)&bk,sizeof(book)) && found==0)
{
if(strcmp(bk.retbookcode(),n)==0)
{
bk.dispbook();
cout<<"\nEnter The New Details of book"<<endl;
bk.modify_book();
int pos=-1*sizeof(bk);
fp.seekp(pos,ios::cur);
fp.write((char*)&bk,sizeof(book));
cout<<"\n\n\t Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<"\n\n Record Not Found ";
getch();
}
void modify_student()
{
char n[6];
int found=0;
system("cls");
cout<<"\n\n\tMODIFY STUDENT RECORD... ";
cout<<"\n\n\tEnter the student ID";
cin>>n;
fp.open("student.txt",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmp(st.retstudid(),n)==0)
{
st.dispstud();
cout<<"\nEnter The New Details of student"<<endl;
st.modify_student();
int pos= -1*sizeof(st);

fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<"\n\n\t Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<"\n\n Record Not Found ";
getch();
}
//

function to delete record of file

void delete_student()
{
char n[6];
int flag=0;
system("cls");
cout<<"\n\n\n\tDELETE STUDENT...";<<endl;
cout<<"\n\nEnter the Student ID of the Student You Want To Delete : "<<e
ndl;
cin>>n;
fp.open("student.txt",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&st,sizeof(student)))
{
if(strcmp(st.retstudid(),n)!=0)
fp2.write((char*)&st,sizeof(student));
else
flag=1;
}
fp2.close();
fp.close();
remove("student.txt");
rename("Temp.txt","student.txt");
if(flag==1)
cout<<"\n\n\tRecord Deleted .."<<endl;
else
cout<<"\n\nRecord not found";<<endl;
getch();
}
void delete_book()
{
char n[6];
system("cls");
cout<<"\n\n\n\tDELETE BOOK ..."<<endl;
cout<<"\n\nEnter The Bookcode of the Book You Want To Delete : "<<endl;
cin>>n;
fp.open("book.txt",ios::in|ios::out);
fstream fp2;

fp2.open("Temp.txt",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbookcode(),n)!=0)
{
fp2.write((char*)&bk,sizeof(book));
}
}
fp2.close();
fp.close();
remove("book.txt");
rename("Temp.txt","book.txt");
cout<<"\n\n\tRecord Deleted ..";
getch();
}

//***************************************************************
//
function to display all students list
//****************************************************************
void display_studlist()
{
system("cls");
fp.open("student.txt",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN "<<endl;
getch();
return;
}
cout<<"\n\n\t\tSTUDENT LIST\n\n"<<endl;
cout<<"=================================================================
=\n"<<endl;
cout<<"\tStudent ID"<<"Student Name"<<"Course Name\n"<<endl;
cout<<"=================================================================
=\n"<<endl;
while(fp.read((char*)&st,sizeof(student)))
{
st.report();
}
fp.close();
getch();
}
//***************************************************************
//
function to display Books list
//****************************************************************
void display_booklist()
{
system("cls");
fp.open("book.txt",ios::in);

if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
cout<<"\n\n\t\tBook LIST\n\n"<<endl;
cout<<"=================================================================
========\n"<<endl;
cout<<"Book Code"<<"Book Name"<<"Author\n"<<endl;
cout<<"=================================================================
========\n"<<endl;
while(fp.read((char*)&bk,sizeof(book)))
{
bk.report();
}
fp.close();
getch();
}

class issue
// CLASS FOR ISSUE BOOK
{
public:
int day,month,year;
int day2,month2,year2;
int issueday,issuemon,issueyear;
int returnday,returnmon,returnyear;
int ext_day,ext_mon,ext_year;
int yr1,yr2,m1,m2,d1,d2,mons1,mons2,mons,days,yrs,sum,j;
int loop;
int fine;
public:
void isdatecalc()
{
cout<<"\t\tEnter day:"<<endl;
cin>>day;
cout<<"\t\tEnter month:"<<endl;
cin>>month;
cout<<"\t\tEnter year:"<<endl;
cin>>year;
day2=day;
month2=month;
year2=year;
day2=day2+20;
if(((month2==1)||(month2==3)||(month2==5)||(month2==7
)||(month2==8)||(month2==10)||(month2==12))&&((day2>31)))
{
day2=day2-31;
month2=month2+1;
if(month2==13)
{
year2++;
month2=1;
}

}
else if(((month2==4)||(month2==6)||(month2==9)||(mont
h2==11))&&((day2>30)))
{
day2=day2-30;
month2++;
}
else if(((year2%4==0)||(year2%400==0))&&(day2>29)&&(
month==2))
{
day2= day2-29;
month2++;
}
else if(((year2%4!=0)||(year2%100!=0)||(year2%400!=0
))&&(day2>28)&&(month2==2))
{
day2-=28;
month2++;
}
cout<<endl;
}
void isdate()
{
issueday=day;
issuemon=month;
issueyear=year;
cout<<"\t\tIssued date:"<<issueday<<"/"<<issuemon<<"/"<<issueyear;
cout<<endl;
}
void retdate()
{
returnday=day2;
returnmon=month2;
returnyear=year2;
cout<<"\t\tReturn Date:"<<returnday<<"/"<<returnmon<<"/"<<returnyear<<endl;
cout<<endl;
}
void edatecalc()
{
ext_day=returnday;
ext_mon=returnmon;
ext_year=returnyear;
ext_day=ext_day+20;
if(((ext_mon==1)||(ext_mon==3)||(ext_mon==5)||(ext_mon==7)||(ex
t_mon==8)||(ext_mon==10)||(ext_mon==12))&&((ext_day>31)))
{
ext_day=ext_day-31;
ext_mon=ext_mon+1;
if(ext_mon==13)
{
ext_year++;
ext_mon=1;
}
}
else if(((ext_mon==4)||(ext_mon==6)||(ext_mon==9)||(e
xt_mon==11))&&((ext_day>30)))
{
ext_day-=30;
ext_mon++;

}
else if(((ext_year%4==0)||(ext_year%100==0)||(ext_ye
ar%400==0))&&(ext_day>29)&&(ext_mon==2))
{
ext_day-=29;
ext_mon++;
}
else if(((ext_year%4!=0)||(ext_year%100!=0)||(ext_ye
ar%400!=0))&&(ext_day>28)&&(ext_mon==2))
{
ext_day-=28;
ext_mon++;
}
cout<<endl;
cout<<endl;
cout<<"\t\tYour extended due date is:"<<ext_day<<"/"<<ext_mon<<
"/"<<ext_year<<endl;
}
void finecalc();
}; issue is;
void issue::finecalc()
{
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
loop=365;
sum=0;
d1=returnday;
m1=returnmon;
yr1=returnyear;
cout<<endl;
cout<<"\t\tYour actual return Date Is: "<<d1<<"/"
<<m1<<"/"<<yr1<<endl;
cout<<endl;
cout<<"\t\tEnter the date of return below.."<<endl
;
cout<<endl;
cout<<"\t\tEnter day:";
cin>>d2;
cout<<endl;
cout<<"\t\tEnter month:";
cin>>m2;
cout<<endl;
cout<<"\t\tEnter year:";
cin>>yr2;
cout<<endl;
days=d2-d1;
yrs=yr2-yr1;
if(m2>=m1)
{
mons=m1-m2;
mons2=abs(mons);
}
else
{
mons=m2-m1;
mons2=abs(mons);
}
sum=yrs*loop+mons+days+mons2;
if(m2>m1)

{
j=m1;
}
else
{
j=m2;
}
if(mons2!=0)
{
for(i=0;i<mons2;i++)
{
sum=sum+mon[j];
j++;
}
}
cout<<endl;
cout<<"\t\tYour date of return:"<<d2<<"/"<<m2<<"/"<<yr2<<endl;
cout<<endl;
fine=(sum+mons)*1;
if((yr1%4==0)||(yr1%400==0)&&(m1==2))
{
fine=fine+1;
}
/* if((m1==2)&&(yr1%4!=0)||(yr1%400!=0))
{
fine=fine-1;
}*/
cout<<"\t\t\tFine amount:Rs."<<fine<<endl;
cout<<"\t\t\t*****************"<<endl;
}
void login()
{
system("cls");
string a[20],b[20];
system("cls");
cout<<"@@@@@@@@@@@@@@@ LOGIN HERE !! @@@@@@@@@@@@@@@@\n\t"<<endl;
cout<<"\n\n\t ENTER USERNAME \n\n\t"<<endl;
gets(a);
if (strcmp(a,"apiit")!=0)
{
cout<<"\n\n Not a valid username! Try again!<<endl;
getch();
{
cout<<"\n\n\tENTER PASSWORD\n\t"<<endl;
gets(b);
if(strcmp(b,"admin")!=0
{
cout<<"\n\t Wrong password!! Try again\n\t"<<endl;
getch();

}
cout<<"\n\n\t$$$$$$$$$$$ WELCOME !! $$$$$$$$$$$$$"<<endl;
getch();
}

void main_menu()
//Function to display main men
u
{
system("cls");
int choice;
cout<< "\n\n\n\t****************MAIN MENU******************"<<endl;
cout<<"\n\n\t1.ADD STUDENT RECORD";
cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD";
cout<<"\n\n\t3.DISPLAY SPECIFIC STUDENT RECORD ";
cout<<"\n\n\t4.MODIFY STUDENT RECORD";
cout<<"\n\n\t5.DELETE STUDENT RECORD";
cout<<"\n\n\t6.ADD BOOK ";
cout<<"\n\n\t7.DISPLAY ALL BOOKS ";
cout<<"\n\n\t8.DISPLAY SPECIFIC BOOK ";
cout<<"\n\n\t9.MODIFY BOOK ";
cout<<"\n\n\t10.DELETE BOOK ";
cout<<"\n\n\t11.BACK TO MAIN MENU";
cout<<"\n\n\t 0. EXIT";
cout<<"\n\n\t PLEASE ENTER YOUR CHOICE : "<<endl;
cin>>choice;
switch(choice)
{
case 1: system("cls");
write_student();break;
case 2: display_studlist();break;
case 3:
char num[6];
system("cls");
cout<<"\n\n\tPlease Enter The Admission No. ";
cin>>num;
display_studlist(num);
break;
case 4: modify_student();break;
case 5: delete_student();break;
case 6: system("cls");
write_book();break;
case 7: display_allb();break;
case 8: {
char num[6];
system("cls");
cout<<"\n\n\tPlease Enter The book No. ";
cin>>num;
display_booklist(num);
break;
}
case 9: modify_book();break;
case 10: delete_book();break;
case 11: return;
default:cout<<"\a";
}
main_menu();

void main()
{
char opt
do
{
system("cls");
cout<<"\n\n\t01. ISSUE BOOK";
cout<<"\n\n\t02. RETURN BOOK";
cout<<"\n\n\t03. MAIN MENU";
cout<<"\n\n\t04. EXIT";
cout<<"\n\n\tPlease Select Your Option : ";
ch=getche();
switch(opt)
{
case '1':system("cls");
book_issue();
break;
case '2':book_deposit();
break;
case '3':main_menu();
break;
case '4':exit(0);
default :cout<<"\a";
}
while(ch!='4');
}
}
}

Anda mungkin juga menyukai