By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,107 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,107 IT Pros & Developers. It's quick & easy.

Help Needed in file handling

P: n/a
> > Hi, this is Abhas,
I had made a video library program in C++, but was facing a problem.
After entering 12 movies, i cannot enter any more movies.
Something gibberish comes instead.
Can somebody please tell whats wrong??
This is the code : :

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<dos.h>

/*
USE OF HEADER FILES :
FSTREAM.H = FOR DATABASE MANAGEMENT(STREAMS ETC...), IOSTREAM.H
CONIO.H = FOR TEXTCOLOR, CLRSCR(), GETCH() ETC...
STDIO.H = RENAME, REMOVE, GETS(), PUTS() ETC...
PROCESS.H = FOR EXIT()
STRING.H = FOR STRING RELATED FUNCTIONS
DOS.H = FOR _DOS_GETDATE FUNCTION
*/

void pass(); //TO INPUT A PASSWORD TO ACCESS THE PROGRAM

struct date1
{
int dd, mm, yyyy;
};
struct dosdate_t d; //TO GET CURRENT DATE

//************************************************** ********
//CLASS TO MAINTAIN MOVIE FILE
//************************************************** ********

class movie
{
public:
int mcode;
char mlang[20];
int mrelease;
char vtype[10];
char mname[40];
char issued;
movie (); //CONSTRUCTOR
int rec_no();
void input();
void display();
void modify();
friend void header(); //FRIEND FUNCTION
friend char upper(char*); //FRIEND FUNCTION
void madd();
void mshow();
void msearch();
void modmovie();
void modyear();
void modlang();
void modstat(char,char []);
int movieissued(char[]);
void mdelete();
} m1;
movie :: movie()
{
issued='f'; //ASSIGNS FALSE FIELD FOR UNISSUED MOVIES
}
int movie :: rec_no()
{
fstream mfile;
int recno;
mfile.open("movie.dat",ios::in);
mfile.seekg(0,ios::end);
int n=mfile.tellg();
mfile.close();
if (n<=0||mfile.eof())
{
recno=1;
return recno;
}
else
{
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
recno=m1.mcode;
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
return (recno+1);
}
}
int movie :: movieissued(char mname[])
{
fstream mfile;
int found;
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,mname)==0))
{
if(m1.issued=='f')
{
found=0;
}
}
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
return found;
}
void movie :: input()
{
cout<<"\n\t\t MOVIE CODE : ";
cout<<mcode<<endl ;
cout<<"\t\t ENTER THE MOVIE NAME : ";
gets(mname);
cout<<"\t\t ENTER THE MOVIE LANGUAGE : ";
cin>>mlang;
cout<<"\t\t ENTER THE RELEASE YEAR : ";
cin>>mrelease;
cout<<"\t\t ENTER THE VIDEO TYPE (CD/DVD/CASSETTE) : ";
cin>>vtype;
cout<<"\t\t ISSUED : ";
cout<< m1.issued;
}

//************************************************** ***************
//CODE FOR ADDING NEW MOVIES TO THE FILE
//************************************************** ***************

void movie :: madd()
{
fstream mfile;
char ans='y';
mcode=rec_no();
mfile.open("movie.dat",ios::out|ios::app) ;
while(ans=='y')
{
clrscr();
header();
cout<<"\n\n\n\n\t\t\t MOVIE DETAILS "<<endl;
cout<<"\t\t\t -------------"<< endl;
m1.input();
mfile.write((char*)&m1,sizeof(m1));
mcode=mcode+1;
cout<<"\n\t\t CONTINUE (Y/N) : ";
cin>>ans ;
}
mfile.close();
}
void movie :: mshow()
{
fstream mfile;
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
m1.display();
cout<<endl ;
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
}
void movie :: display()
{
cout<<"\n\t\t\t MOVIE CODE : ";
cout<<mcode<<endl ;
cout<<"\t\t\t MOVIE NAME : ";
puts(mname);
cout<<"\t\t\t MOVIE LANGUAGE : ";
cout<<mlang;
cout<<"\n\t\t\t RELEASE YEAR : ";
cout<<mrelease;
cout<<"\n\t\t\t VIDEO TYPE : ";
cout<<vtype;
cout<<"\n\t\t\t ISSUED : ";
cout<<m1.issued;
}

//************************************************** *****
//CODE TO SEARCH FOR A MOVIE
//************************************************** *****

void movie :: msearch()
{
fstream mfile;
char m[20];
int counter=0;
cout<<"\n\n\n\t\tENTER THE MOVIE TO BE SEARCHED:";
gets(m);
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,m)==0))
{
counter++;
m1.display();
}
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
if (counter==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
textcolor(WHITE);
}
}

//************************************************** *******
// CODE FOR MODIFYING INFO OF A MOVIE IN A FILE
//************************************************** *******

void movie :: modify()
{
int ch;
do
{
aa: clrscr();
header();
cout<<"\n\n\n\n\t\t\t MODIFY MENU ";
cout <<"\n\t\t\t ---------- ";
cout<<"\n\t\t\t 1: MODIFY MOVIE NAME ";
cout<<"\n\t\t\t 2: MODIFY RELEASE YEAR ";
cout<<"\n\t\t\t 3: MODIFY LANGUAGE ";
cout<<"\n\t\t\t 4: RETURN TO MAIN MENU";
cout<<"\n\t\t\t ENTER YOUR CHOICE : ";
cin>>ch;
switch(ch)
{
case 1 : clrscr();
header();
m1.modmovie();
break;
case 2 : clrscr();
header();
m1.modyear();
break;
case 3 : clrscr();
header();
m1.modlang();
break;
case 4 : break;
default : cout<<"\n\n\n\n\n\n\n\t\t\t INVALID CHOICE !!!!!!!!! ";
getch();
goto aa;
}
} while(ch>1 && ch<4);
}
void movie :: modmovie()
{
fstream mfile;
int found=0;
char name[20];
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
cout<<"\n\n\t\t ENTER THE MOVIE NAME TO BE MODIFIED:";
gets(name);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name)==0))
{
cout<<"\n\n\t\t ENTER THE NAME: ";
gets(m1.mname);
int n=mfile.tellg();
mfile.seekg(n-sizeof(m1));
mfile.write((char*)&m1,sizeof(m1));
found=1;
break;
}
mfile.read((char*)&m1,sizeof(m1));
}
if (found==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
getch();
textcolor(WHITE);
}
mfile.close();
}
void movie :: modyear()
{
fstream mfile;
int found=0;
char name[20];
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
cout<<"\n\n\t ENTER THE MOVIE NAME IN WHICH YEAR IS TO BE MODIFIED:";
gets(name);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name)==0))
{
cout<<"\n\n\t\t\t ENTER THE YEAR:";
cin>>m1.mrelease;
int n=mfile.tellg();
mfile.seekg(n-sizeof(m1));
mfile.write((char*)&m1,sizeof(m1));
found=1;
break;
}
mfile.read((char*)&m1,sizeof(m1));
}
if (found==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
getch();
textcolor(WHITE);
}
mfile.close();
}
void movie :: modlang()
{
fstream mfile;
int found=0;
char name[20];
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
cout <<"\n\n\t ENTER THE MOVIE NAME IN WHICH LANGUAGE TO BE
MODIFIED:";
gets(name);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name)==0))
{
cout<<"\n\n\t\t ENTER THE LANGUAGE: ";
gets(m1.mlang);
int n=mfile.tellg();
mfile.seekg(n-sizeof(m1));
mfile.write((char*)&m1,sizeof(m1));
found=1;
break;
}
mfile.read((char*)&m1,sizeof (m1));
}
if (found==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
getch () ;
textcolor(WHITE);
}
mfile.close();
}

//************************************************** **********
//MODIFIES THE STATUS ON RETURNING A MOVIE
//************************************************** **********

void movie :: modstat(char ch,char name[])
{
int found =0;
fstream mfile;
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name))==0)
{
m1.issued=ch;
found++;
int n=mfile.tellg() ;
mfile.seekg(n-sizeof(m1));
mfile.write((char*)&m1,sizeof(m1));
}
mfile.read((char*)&m1,sizeof(m1));
}
if (found==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
getch();
textcolor(WHITE);
}
mfile.close();
}

//************************************************** ************
//CODE FOR DELETING A MOVIE
//************************************************** ************

void movie :: mdelete()
{
fstream mfile,m1file;
char mname[20];
int count=0;
cout<<" \n\n\t\t\tENTER THE MOVIE TO BE DELETED: ";
gets(mname);
mfile.open("movie.dat",ios::in);
m1file.open("movie1.dat",ios::app|ios::out);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if(strcmp(m1.mname, mname)!=0)
{
m1file.write((char*)&m1,sizeof(m1));
count++;
}
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
m1file.close();
remove("movie.dat");
rename("movie1.dat","movie.dat");
if (count!=0)
{
gotoxy(27,25);
textcolor(RED+BLINK);
cprintf(" MOVIE DELETED !!!!");
textcolor(WHITE);
}
}

//************************************************** **********
//CLASS FOR MAINTAINING VIDEO PRICES
//************************************************** **********

class video
{
char vtype[15];
float vprice;
float vexch;
protected:
int vcode;
public:
void vinput();
void vdisplay();
void vadd();
int type_exist(char[]);
int type_check(char[]);
int rec_no();
int calexcharges(char [],int);
}v1;
int video :: calexcharges(char name[],int i)
{
fstream mfile,vfile;
char type[10];
int ch;
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name)==0))
{
strcpy(type,m1.vtype);
}
mfile.read((char*)&m1,sizeof(m1));
}

vfile.open("video.dat",ios::in);
vfile.seekg(0, ios::beg);
vfile.read((char*)&v1,sizeof(v1));
while(!vfile.eof())
{
if((strcmp(type,v1.vtype)==0))
{
ch=v1.vexch;
}
vfile.read((char*)&v1,sizeof(v1));
}
mfile.close();
vfile.close();
int exch=ch*i;
return exch;
}
void video :: vinput()
{
int check, found;
cout<<"\n\t\t ENTER THE VIDEO CODE :";
cin<<vcode;
cout<<"\t\t ENTER THE VIDEO TYPE (CD/DVD/CASSETTE) :";
cin>>vtype;
cout<<"\t\t ENTER THE VIDEO PRICE :Rs. ";
cin>>vprice;
cout<<"\t\t ENTER THE EXTRA CHARGES(PER DAY) :Rs. ";
cin>>vexch;
}

//************************************************** *********
//CODE FOR ADDING VIDEO TYPE TO A FILE
//************************************************** *********

void video :: vadd()
{
fstream vfile;
char ans='y';
vfile.open("video.dat",ios::in|ios::app);
while(ans=='y')
{
clrscr();
header();
cout<<"\n\n\n\t\t\t VIDEO DETAILS";
cout<<"\n\t\t\t -------------";
v1.vinput();
vfile.write((char*)&v1,sizeof(v1));
vcode=vcode+1;
cout<<"\t\t CONTINUE (Y/N) :";
cin>>ans;
}
vfile.close();
}

//************************************************** ************
//CLASS TRANSACTION:
// FOR MAINTAINING CUSTOMER FILE AND RELATED RECORDS
//************************************************** ************

class trans : public movie, public video
{
date1 curr_date,ret_date;
int id;
char cname[20];
char cadd[40];
float charges;
int days;
int nddays;
char ch;
public:
int cinput();
void cuadd();
void mcdisplay(char []);
void cdisplay(char []);
int rec_no();
void report();
void cdelete(char[]);
void search_menu();
void mcsearch();
void csearch();
void dheader();
void lmdisplay();
void d1header();
void lmadisplay();
void cshow();
void cheader();
void lmrdisplay();
int check_day(int,int);
void retdate();
void show_date(int,int,int,int);
void ddays();
int showdays(int,int);
friend int validate(date1 &da);
}t1;
int trans :: rec_no ()
{
fstream cfile;
int rno;
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
int n=cfile.tellg();
cfile.close() ;
if (n<=0||cfile.eof())
{
rno=1;
return rno;
}
else
{
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
cfile.read((char*)&t1,sizeof(t1));
while(!cfile.eof())
{
rno=t1.id;
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
return (rno+1);
}
}
int trans :: cinput()
{
int k;
cout<<"\n\t\t CUSTOMER ID : ";
cout<<id<<endl;
cout<<"\t\t ENTER THE CUSTOMER NAME : ";
gets(cname);
cout<<"\t\t ENTER THE ADDRESS : ";
gets(cadd);
cout<<"\t\t ENTER THE MOVIE NAME : ";
gets(mname);
k=m1.movieissued(mname);
if (k==0)
{
m1.modstat('t',mname);
cout<<"\t\t ENTER THE MOVIE CHARGES : Rs. ";
cin>>charges;
cout<<"\t\t ENTER NO.OF DAYS,MOVIE ISSUED : ";
cin>>days;
cout<<"\t\t ENTER THE ISSUE DATE(dd/mm/yyyy): ";
ll: cin>>curr_date.dd>>ch;
cin>>curr_date.mm>>ch;
cin>>curr_date.yyyy;
if (validate(curr_date)==0)
{
gotoxy(27,22);
textcolor(WHITE+BLINK);
cprintf("INVALID DATE!!! ");
getch() ;
textcolor(WHITE);
gotoxy(27,22);
clreol();
gotoxy(56,12);
clreol();
goto ll;
}
cout<<"\t\t RETURN DATE : ";
retdate();
cout<<"\t\t\t\t\tISSUED(T/F) : ";
cin>>issued;
}
else
{
gotoxy(25,20);
textcolor(WHITE+BLINK);
cprintf("MOVIE ALREADY ISSUED OR DOES NOT EXIST");
getch() ;
textcolor(WHITE);
gotoxy(25,20);
clreol();
}
return k;
}

//************************************************** *******************
//CODE FOR ADDING CUSTOMER RECORD TO A FILE OR ISSUE A MOVIE
//************************************************** *******************

void trans :: cuadd()
{
int aa;
fstream cfile;
char ans='y';
id=rec_no();
cfile.open("cust.dat",ios::out|ios::app) ;
while(ans=='y')
{
clrscr();
header();
cout<<"\n\n\t\t\t ISSUE DETAILS";
cout<<"\n\t\t\t -------------" ;
aa=t1.cinput();
if(aa==0)
{
cfile.write((char*)&t1,sizeof(t1));
id=id+1;
}
cout<<"\n\t\t\t CONTINUE (Y/N) : ";
cin>>ans;
}
cfile.close();
}
void trans :: cdisplay(char name[])
{
int tcharges;
cout<<"\n\t\t\t CUSTOMER ADDRESS : ";
puts(cadd);
cout<<"\t\t\t MOVIE NAME : ";
puts(mname);
cout<<"\t\t\t MOVIE CHARGES : Rs. "<<charges;
cout<<"\n\t\t\t ISSUED DAYS : "<<days;
cout<<"\n\t\t\t ISSUED DATE(DD/MM/YY) :
"<<curr_date.dd<<ch<<curr_date.mm<<ch<<curr_date.y yyy;
cout<<"\n\t\t\t RETURN DATE :
"<<ret_date.dd<<ch<<ret_date.mm<<ch<<ret_date.yyyy ;
cout<<"\n\t\t\t DUE DAYS : ";
ddays() ;
int exch=calexcharges(name,t1.nddays);
cout<<"\n\t\t\t EXTRA CHARGES : Rs. "<<exch;
tcharges=exch+t1.charges;
cout<<"\n\t\t\t TOTAL CHARGES : Rs. "<<tcharges;
}
void trans :: mcdisplay(char name[])
{
int tcharges;
cout<<"\n\t\t\t CUSTOMER NAME : ";
puts(cname);
cout<<"\t\t\t CUSTOMER ADDRESS : ";
puts(cadd);
cout<<"\t\t\t MOVIE CHARGES : Rs. "<<charges;
cout<<"\n\t\t\t ISSUED DAYS : "<<days;
cout<<"\n\t\t\t ISSUED DATE(DD/MM/YY) :
"<<curr_date.dd<<ch<<curr_date.mm<<ch<<curr_date.y yyy;
cout<<"\n\t\t\t RETURN DATE :
"<<ret_date.dd<<ch<<ret_date.mm<<ch<<ret_date.yyyy ;
cout<<"\n\t\t\t DUE DAYS : ";
ddays() ;
int exch=calexcharges(name,t1.nddays);
cout<<"\n\t\t\t EXTRA CHARGES : Rs. "<<exch;
tcharges=exch+t1.charges;
cout<<"\n\t\t\t TOTAL CHARGES : Rs. "<<tcharges;
}
int showdays(int,int);

void trans :: ddays()
{
struct dosdate_t d;
_dos_getdate(&d);
int ch=0;
int ddays=0;
int mm=ret_date.mm;
if(d.day<=ret_date.dd)
{
t1.nddays=ddays;
cout<<"-";
}
else
{
if(d.month==mm)
{
switch (mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays=d.day-ret_date.dd;
mm++;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays=d.day-ret_date.dd;
mm++;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays=d.day-ret_date.dd;
mm++ ;
}
else
{
ddays=d.day-ret_date.dd;
mm++;
}
break;
}
ch++;
}
else
{
switch (mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays=31-ret_date.dd;
mm++;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays=30-ret_date.dd;
mm++;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays=29-ret_date.dd;
mm++;
}
else
{
ddays=28-ret_date.dd;
mm++;
}
break;
}
ch++;
}

if(d.year==(ret_date.yyyy+1))
{
if (mm==13)
mm=1;
while(mm<d.month)
{
switch(mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays=showdays(ddays,31);
mm++ ;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays=showdays(ddays,30);
mm++ ;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays=showdays(ddays,29);
mm++ ;
}
else
{
ddays=showdays(ddays,28);
mm++;
}
break;
}
ch++;
}
if (mm==d.month)
goto ll;
}
}
{
if (ret_date.yyyy==d.year)
{
if(d.month==(ret_date.mm+1))
{
ll: switch (mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays+=d.day;
mm++;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays+=d.day;
mm++;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays+=d.day;
mm++;
}
else
{
ddays+=d.day;
mm++;
}
break;
}
ch++;
}
else
{
while(mm<d.month)
{
switch(mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays+=31;
mm++;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays+=30;
mm++;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays+=29;
mm++;
}
else
{
ddays+=28;
mm++;
}
break;
}
if (mm==d.month)
{
switch(mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays+=d.day;
mm++ ;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays+=d.day;
mm++ ;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays+=d.day;
mm++;
}
else
{
ddays+=d.day;
mm++;
}
break;
}
ch++;
}
}
}
}
t1.nddays=ddays;
cout<<t1.nddays;
}
}
int trans :: showdays(int duedays,int lastd)
{
duedays+=lastd;
return duedays;
}

//************************************************** ******************************
//CODE FOR SEARCHING A CUSTOMER RECORD AND DELETE IT,IN CASE OF
RETURNING
//THE MOVIE
//************************************************** ******************************

void trans :: search_menu()
{
int choice;
do
{
ac: clrscr();
header();
cout<<"\n\n\n\n\t\t\t SEARCH MENU ";
cout<<"\n\t\t\t ----------- ";
cout<<"\n\t\t\t 1: SEARCH BY CUSTOMER NAME ";
cout<<"\n\t\t\t 2: SEARCH BY MOVIE NAME ";
cout<<"\n\t\t\t 3: RETURN TO MAIN MENU ";
cout<<"\n\t\t\t ENTER YOUR CHOICE : ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
header();
t1.csearch();
getch();
break;
case 2: clrscr();
header();
t1.mcsearch();
getch() ;
break;
case 3: break;
default: cout <<"\n\n\n\n\n\n\t\t\t INVALID CHOICE !!!!!!!!! ";
getch () ;
goto ac;
}
}while(choice>=1&&choice<3);
}
void trans :: mcsearch()
{
char ans = 'y';
char name[20] ;
char pname[20];
fstream cfile;
cout<<"\n\t\tENTER THE MOVIE NAME TO BE SEARCHED: ";
gets(name);
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
while(!cfile.eof())
{
if((strcmp(t1.mname,name)==0))
{
t1.mcdisplay(name);
cout<<"\n\n\n\t\t DO YOU WISH TO DELETE?(Y/N): ";
cin>>ans;
if (ans=='y'||ans=='Y')
{
cdelete(t1.cname);
}
}
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
}
void trans :: csearch()
{
char ans = 'y' ;
char name[20];
char pname[20];
fstream cfile;
cout<<"\n\t\tENTER THE CUSTOMER NAME TO BE SEARCHED: ";
gets(name);
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
while(!cfile.eof())
{
if((strcmp(t1.cname,name)==0))
{
t1.cdisplay(t1.mname);
cout<<"\n\n\n\t\t DO YOU WISH TO DELETE?(Y/N): ";
cin>>ans;
if (ans=='y'||ans=='Y')
{
cdelete(name);
}
}
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
}
void trans :: cdelete(char name[])
{
fstream cfile,c1file;
char cname[20];
cfile.open("cust.dat",ios::in);
c1file.open("cust1.dat",ios::app|ios::out);
cfile.seekg(0, ios::beg);
cfile.read((char*)&t1, sizeof(t1));
while(!cfile.eof())
{
if(strcmp(t1.cname,name)!=0)
{
c1file.write((char*)&t1,sizeof(t1));
}
else
{
m1.modstat('f',t1.mname);
}
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
c1file.close();
remove("cust.dat");
rename("cust1.dat","cust.dat");
}

//************************************************** ****************
//CODE FOR CHECKING RECORDS
//************************************************** ****************

void trans :: report()
{
int choice;
do
{
ab1 : clrscr();
header() ;
cout<<"\n\n\n\n\t\t\t REPORT MENU";
cout<<"\n\t\t\t -----------";
cout<<"\n\t\t\t 1: LIST OF MOVIES ";
cout<<"\n\t\t\t 2: LIST OF MOVIES TO BE RETURNED ";
cout<<"\n\t\t\t 3: LIST OF MOVIES AVALAIBLE";
cout<<"\n\t\t\t 4: RETURN TO MAIN MENU ";
cout<<"\n\t\t\t ENTER YOUR CHOICE : ";
cin>>choice;
switch (choice)
{
case 1: clrscr();
header();
t1.dheader();
t1.lmdisplay();
getch();
break;
case 2: clrscr();
header();
t1.cheader();
t1.lmrdisplay();
getch() ;
break;
case 3: clrscr();
header();
t1.d1header();
t1.lmadisplay();
getch();
break;
case 4: break;
default: cout<<"\n\n\n\n\n\n\t\t\t INVALID CHOICE !!!!!!!!! ";
getch();
goto ab1;
}
}while(choice>=1 && choice<4);
}
void trans :: dheader()
{
gotoxy(2,4);
cout<<"MOVIE CODE NAME LANGUAGE VIDEO TYPE ";
gotoxy(2,5);
cout<<"---------- ---- -------- ---------- ";
}
void trans :: lmdisplay()
{
int n=5;
fstream mfile;
mfile.open("movie.dat",ios::in);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
n+=1;
gotoxy(7,n);
cout<<m1.mcode;
gotoxy(16,n);
puts(m1.mname);
gotoxy(37,n);
puts(m1.mlang);
gotoxy(50,n);
puts(m1.vtype);
cout<<endl;
mfile.read((char*)&m1, sizeof(m1));
}
mfile.close();
}
void trans :: d1header()
{
gotoxy(2,4);
cout<<"MOVIE CODE MOVIE NAME VIDEO TYPE ";
gotoxy(2,5);
cout<<"---------- ---------- ---------- ";
}
void trans :: lmadisplay()
{
int n=5;
fstream mfile;
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if(m1.issued=='f')
{
n+=1;
gotoxy(7,n);
cout<<m1.mcode;
gotoxy(16,n);
puts(m1.mname);
gotoxy(42,n);
puts(m1.vtype);
cout<<endl ;
}
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
}
void trans :: cheader()
{
gotoxy(2,4);
cout<<"CUSTOMER NAME MOVIE ISSUED ISSUE DATE RETURN DATE ";
gotoxy(2,5);
cout<<"------------- ------------ ----------
----------- ";
}
void trans :: lmrdisplay()
{
int n=5;
fstream cfile;
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
cfile.read((char*)&t1,sizeof(t1));
while(!cfile.eof())
{
n+=1;
gotoxy(2,n);
puts(t1.cname);
gotoxy(20,n);
puts(t1.mname);
gotoxy(43,n);
cout<<curr_date.dd<<"/"<<curr_date.mm<<"/"<<curr_date.yyyy;
gotoxy(57,n);
cout<<ret_date.dd<<"/"<<ret_date.mm<<"/"<<ret_date.yyyy;
cout<<endl ;
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
}
int validate(date1 &da)
{
int flag=1;
struct dosdate_t d;
_dos_getdate(&d);
if(da.yyyy!=d.year)
{
flag=0;
return flag;
}
else
{
if((da.yyyy<=0)||(da.mm<=0)||(da.dd<=0))
flag=0;
else
{
switch (da.mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:flag=t1.check_day(da.dd,31);
break;
case 4 :
case 6 :
case 9 :
case 11: flag=t1.check_day(da.dd,30);
break;
case 2 : if((da.yyyy%4==0))
flag=t1.check_day(da.dd,29);
else
flag=t1.check_day(da.dd,28);
break;
default: flag=0;
}
}
return flag;
}
}
void trans :: retdate()
{
char ch;
switch (curr_date.mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:show_date(curr_date.dd,curr_date.mm,curr_date.y yyy,31);
break;
case 4 :
case 6 :
case 9 :
case 11:show_date(curr_date.dd,curr_date.mm,curr_date.y yyy,30);
break;
case 2 : if((curr_date.yyyy%4==0))
show_date(curr_date.dd,curr_date.mm,curr_date.yyyy ,29);
else
show_date(curr_date.dd,curr_date.mm,curr_date.yyyy ,28);
break;
}
}
void trans :: show_date(int date,int mm,int yyyy,int lastd)
{
int rdate=t1.days;
rdate+=date;
if(rdate>lastd && mm==12)
{
mm=1;
cout<< (rdate-=lastd) <<"/"<<mm<<"/"<< (yyyy+=1) ;
getch();
}
else
{
if(rdate>lastd)
{
cout<< (rdate-=lastd) <<"/"<<(mm+=1)<<"/"<<yyyy;
getch();
}
else
{
cout<<rdate<<"/"<<mm<<"/"<<yyyy;
getch();
}
}
ret_date.dd=rdate;
ret_date.mm=mm;
ret_date.yyyy=yyyy;
}
int trans :: check_day(int day,int lastd)
{
if ((day>=1)&&(day<=lastd))
return 1;
else
return 0;
}

//************************************************** **************************
//CODE TO PRINT A BOX
//************************************************** **************************

void line_hor(int col1,int col2,int row, char c)
{
for(col1;col1<=col2;col1++)
{
gotoxy(col1,row);
cout<<c;
}
}
void line_ver(int row1,int row2,int col,char c)
{
for(row1;row1<=row2;row1++)
{
gotoxy(col,row1);
cout<<c;
}
}
void print_box()
{
clrscr();
line_hor(1,79,1,219);
line_hor(1,79,25,219);
line_ver(1,25,1,219);
line_ver(1,25,79,219);
delay(50);
line_hor(2,78,2,219);
line_hor(2,78,24,219);
line_ver(2,24,2,219);
line_ver(2,24,78,219);
delay(50);
line_hor(3,77,3,219);
line_hor(3,77,23,219);
line_ver(3,23,3,219);
line_ver(3,23,77,219);
delay(50);
line_hor(4,76,4,178);
line_hor(4,76,22,178);
line_ver(4,22,4,178);
line_ver(4,22,76,178);
delay(50);
line_hor(5,75,5,178);
line_hor(5,75,21,178);
line_ver(5,21,5,178);
line_ver(5,21,75,178);
delay(50);
line_hor(6,74,6,178);
line_hor(6,74,20,178);
line_ver(6,20,6,178);
line_ver(6,20,74,178);
delay(50);
line_hor(7,73,7,177);
line_hor(7,73,19,177);
line_ver(7,19,7,177);
line_ver(7,19,73,177);
delay(50);
line_hor(8,72,8,177);
line_hor(8,72,18,177);
line_ver(8,18,8,177);
line_ver(8,18,72,177);
delay(50);
line_hor(9,71,9,177);
line_hor(9,71,17,177);
line_ver(9,17,9,177);
line_ver(9,17,71,177);
delay(50);
line_hor(10,70,10,178);
line_hor(10,70,16,178);
line_ver(10,16,10,178);
line_ver(10,16,70,178);
delay(50);
line_hor(11,69,11,178);
line_hor(11,69,15,178);
line_ver(11,15,11,178);
line_ver(11,15,69,178);
delay(50);
_setcursortype(_NOCURSOR);
gotoxy(30,13);
textcolor(GREEN+BLINK);
cprintf("VIDEO LIBRARY SYSTEM");
getch();
gotoxy(30,13);
clreol() ;
textcolor(WHITE);
pass();
textcolor(WHITE);
}

//************************************************** ****************************
//CODE TO ACCEPT THE PASSWORD
//************************************************** ****************************

void pass()
{
char pass[]={"videolib"};
int s=strlen(pass);
char pass1[10];
int count=0;
clrscr();
line_hor(1,79,1,219);
line_hor(1,79,25,219);
line_ver(1,25,1,219);
line_ver(1,25,79,219);
delay(50);
line_hor(2,78,2,219);
line_hor(2,78,24,219);
line_ver(2,24,2,219);
line_ver(2,24,78,219);
delay(50);
line_hor(3,77,3,219);
line_hor(3,77,23,219);
line_ver(3,23,3,219);
line_ver(3,23,77,219);
delay(50);
line_hor(4,76,4,178);
line_hor(4,76,22,178);
line_ver(4,22,4,178);
line_ver(4,22,76,178);
delay(50);
line_hor(5,75,5,178);
line_hor(5,75,21,178);
line_ver(5,21,5,178);
line_ver(5,21,75,178);
delay(50);
line_hor(6,74,6,178);
line_hor(6,74,20,178);
line_ver(6,20,6,178) ;
line_ver(6,20,74,178);
delay(50);
line_hor(7,73,7,177);
line_hor(7,73,19,177);
line_ver(7,19,7,177);
line_ver(7,19,73,177);
delay(50);
line_hor(8,72,8,177);
line_hor(8,72,18,177);
line_ver(8,18,8,177);
line_ver(8,18,72,177);
delay(50);
line_hor(9,71,9,177);
line_hor(9,71,17,177);
line_ver(9,17,9,177);
line_ver(9,17,71,177);
delay(50);
line_hor(10,70,10,178);
line_hor(10,70,16,178);
line_ver(10,16,10,178);
line_ver(10,16,70,178);
delay(50);
line_hor(11,69,11,178);
line_hor(11,69,15,178);
line_ver(11,15,11,178);
line_ver(11,15,69,178);
delay(50);
gotoxy(27,13);
cout<<"ENTER THE PASSWORD:";
ll : for (int i=0; i<s; i++)
{
pass1[i]=getch();
cout<<"*";
}
if(strcmp(pass,pass1)==0)
{
count++;
return;
}
else
{
if(strcmp(pass,pass1)!=0)
{
gotoxy(27,13);
textcolor(RED+BLINK);
cprintf("SORRY! INVALID PASSWORD!!!!!");
textcolor(WHITE);
getch() ;
exit(0) ;
}
}
}
void print_box();

void header();

//************************************************** ***************
//main() starts from here
//************************************************** ***************

void main()
{
print_box();
clrscr();
int choice;
do
{
again : clrscr();
header();
cout<<"\n\n\n\n\t\t\t MAIN MENU ";
cout<<"\n\t\t\t --------- ";
cout<<"\n\t\t\t 1: REGISTER A NEW MOVIE ";
cout<<"\n\t\t\t 2: SEARCH FOR A MOVIE ";
cout<<"\n\t\t\t 3: MODIFY INFO OF A MOVIE ";
cout<<"\n\t\t\t 4: ISSUE A MOVIE ";
cout<<"\n\t\t\t 5: RETURN A MOVIE ";
cout<<"\n\t\t\t 6: DELETE A MOVIE ";
cout<<"\n\t\t\t 7: ADD A VIDEO TYPE ";
cout<<"\n\t\t\t 8: REPORTS ";
cout<<"\n\t\t\t 9: EXIT ";
cout<<"\n\t\t\t ENTER YOUR CHOICE : ";
cin>>choice;
switch (choice)
{
case 1 : m1.madd();
break;
case 2 : clrscr();
header();
m1.msearch();
getch () ;
break;
case 3 : clrscr();
header();
m1.modify();
break;
case 4 : clrscr();
header();
t1.cuadd();
break;
case 5 : clrscr();
header();
t1.search_menu();
getch () ;
break;
case 6 : clrscr();
header();
m1.mdelete();
getch();
break;
case 7 : clrscr();
header();
v1.vadd();
break;
case 8 : t1.report();
break;
case 9 : clrscr();
exit(0);
default : cout<<"\n\n\n\n\n\t\t\t INVALID CHOICE !!!!!!! ";
getch () ;
goto again;
}
}while(choice>=1&&choice<=9);
}
void header()
{
gotoxy(25,1);
cout<<" VIDEO LIBRARY SYSTEM "<<endl;
gotoxy(25,2);
cout<<" -------------------- ";
}

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I'm pretty sure you don't mind to tell us the menu selections leading
to the
error and to provide more detail on the error itself.

BTW: your determination of a leap year is wrong:
bool leapyear(int yy)
{
return yy % 4 == 0 && yy % 100 != 0 || yy % 400 == 0;
}

regards
Stephan Brönnimann
br****@osb-systems.com
Open source rating and billing engine for communication networks.

Jul 23 '05 #2

P: n/a
"Abhas" writes:

<scroll to end>
> I had made a video library program in C++, but was facing a problem.
> After entering 12 movies, i cannot enter any more movies.
> Something gibberish comes instead.
> Can somebody please tell whats wrong??
> This is the code : :

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<dos.h>

/*
USE OF HEADER FILES :
FSTREAM.H = FOR DATABASE MANAGEMENT(STREAMS ETC...), IOSTREAM.H
CONIO.H = FOR TEXTCOLOR, CLRSCR(), GETCH() ETC...
STDIO.H = RENAME, REMOVE, GETS(), PUTS() ETC...
PROCESS.H = FOR EXIT()
STRING.H = FOR STRING RELATED FUNCTIONS
DOS.H = FOR _DOS_GETDATE FUNCTION
*/

void pass(); //TO INPUT A PASSWORD TO ACCESS THE PROGRAM

struct date1
{
int dd, mm, yyyy;
};
struct dosdate_t d; //TO GET CURRENT DATE

//************************************************** ********
//CLASS TO MAINTAIN MOVIE FILE
//************************************************** ********

class movie
{
public:
int mcode;
char mlang[20];
int mrelease;
char vtype[10];
char mname[40];
char issued;
movie (); //CONSTRUCTOR
int rec_no();
void input();
void display();
void modify();
friend void header(); //FRIEND FUNCTION
friend char upper(char*); //FRIEND FUNCTION
void madd();
void mshow();
void msearch();
void modmovie();
void modyear();
void modlang();
void modstat(char,char []);
int movieissued(char[]);
void mdelete();
} m1;
movie :: movie()
{
issued='f'; //ASSIGNS FALSE FIELD FOR UNISSUED MOVIES
}
int movie :: rec_no()
{
fstream mfile;
int recno;
mfile.open("movie.dat",ios::in);
mfile.seekg(0,ios::end);
int n=mfile.tellg();
mfile.close();
if (n<=0||mfile.eof())
{
recno=1;
return recno;
}
else
{
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
recno=m1.mcode;
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
return (recno+1);
}
}
int movie :: movieissued(char mname[])
{
fstream mfile;
int found;
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,mname)==0))
{
if(m1.issued=='f')
{
found=0;
}
}
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
return found;
}
void movie :: input()
{
cout<<"\n\t\t MOVIE CODE : ";
cout<<mcode<<endl ;
cout<<"\t\t ENTER THE MOVIE NAME : ";
gets(mname);
cout<<"\t\t ENTER THE MOVIE LANGUAGE : ";
cin>>mlang;
cout<<"\t\t ENTER THE RELEASE YEAR : ";
cin>>mrelease;
cout<<"\t\t ENTER THE VIDEO TYPE (CD/DVD/CASSETTE) : ";
cin>>vtype;
cout<<"\t\t ISSUED : ";
cout<< m1.issued;
}

//************************************************** ***************
//CODE FOR ADDING NEW MOVIES TO THE FILE
//************************************************** ***************

void movie :: madd()
{
fstream mfile;
char ans='y';
mcode=rec_no();
mfile.open("movie.dat",ios::out|ios::app) ;
while(ans=='y')
{
clrscr();
header();
cout<<"\n\n\n\n\t\t\t MOVIE DETAILS "<<endl;
cout<<"\t\t\t -------------"<< endl;
m1.input();
mfile.write((char*)&m1,sizeof(m1));
mcode=mcode+1;
cout<<"\n\t\t CONTINUE (Y/N) : ";
cin>>ans ;
}
mfile.close();
}
void movie :: mshow()
{
fstream mfile;
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
m1.display();
cout<<endl ;
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
}
void movie :: display()
{
cout<<"\n\t\t\t MOVIE CODE : ";
cout<<mcode<<endl ;
cout<<"\t\t\t MOVIE NAME : ";
puts(mname);
cout<<"\t\t\t MOVIE LANGUAGE : ";
cout<<mlang;
cout<<"\n\t\t\t RELEASE YEAR : ";
cout<<mrelease;
cout<<"\n\t\t\t VIDEO TYPE : ";
cout<<vtype;
cout<<"\n\t\t\t ISSUED : ";
cout<<m1.issued;
}

//************************************************** *****
//CODE TO SEARCH FOR A MOVIE
//************************************************** *****

void movie :: msearch()
{
fstream mfile;
char m[20];
int counter=0;
cout<<"\n\n\n\t\tENTER THE MOVIE TO BE SEARCHED:";
gets(m);
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,m)==0))
{
counter++;
m1.display();
}
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
if (counter==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
textcolor(WHITE);
}
}

//************************************************** *******
// CODE FOR MODIFYING INFO OF A MOVIE IN A FILE
//************************************************** *******

void movie :: modify()
{
int ch;
do
{
aa: clrscr();
header();
cout<<"\n\n\n\n\t\t\t MODIFY MENU ";
cout <<"\n\t\t\t ---------- ";
cout<<"\n\t\t\t 1: MODIFY MOVIE NAME ";
cout<<"\n\t\t\t 2: MODIFY RELEASE YEAR ";
cout<<"\n\t\t\t 3: MODIFY LANGUAGE ";
cout<<"\n\t\t\t 4: RETURN TO MAIN MENU";
cout<<"\n\t\t\t ENTER YOUR CHOICE : ";
cin>>ch;
switch(ch)
{
case 1 : clrscr();
header();
m1.modmovie();
break;
case 2 : clrscr();
header();
m1.modyear();
break;
case 3 : clrscr();
header();
m1.modlang();
break;
case 4 : break;
default : cout<<"\n\n\n\n\n\n\n\t\t\t INVALID CHOICE !!!!!!!!! ";
getch();
goto aa;
}
} while(ch>1 && ch<4);
}
void movie :: modmovie()
{
fstream mfile;
int found=0;
char name[20];
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
cout<<"\n\n\t\t ENTER THE MOVIE NAME TO BE MODIFIED:";
gets(name);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name)==0))
{
cout<<"\n\n\t\t ENTER THE NAME: ";
gets(m1.mname);
int n=mfile.tellg();
mfile.seekg(n-sizeof(m1));
mfile.write((char*)&m1,sizeof(m1));
found=1;
break;
}
mfile.read((char*)&m1,sizeof(m1));
}
if (found==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
getch();
textcolor(WHITE);
}
mfile.close();
}
void movie :: modyear()
{
fstream mfile;
int found=0;
char name[20];
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
cout<<"\n\n\t ENTER THE MOVIE NAME IN WHICH YEAR IS TO BE MODIFIED:";
gets(name);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name)==0))
{
cout<<"\n\n\t\t\t ENTER THE YEAR:";
cin>>m1.mrelease;
int n=mfile.tellg();
mfile.seekg(n-sizeof(m1));
mfile.write((char*)&m1,sizeof(m1));
found=1;
break;
}
mfile.read((char*)&m1,sizeof(m1));
}
if (found==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
getch();
textcolor(WHITE);
}
mfile.close();
}
void movie :: modlang()
{
fstream mfile;
int found=0;
char name[20];
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
cout <<"\n\n\t ENTER THE MOVIE NAME IN WHICH LANGUAGE TO BE
MODIFIED:";
gets(name);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name)==0))
{
cout<<"\n\n\t\t ENTER THE LANGUAGE: ";
gets(m1.mlang);
int n=mfile.tellg();
mfile.seekg(n-sizeof(m1));
mfile.write((char*)&m1,sizeof(m1));
found=1;
break;
}
mfile.read((char*)&m1,sizeof (m1));
}
if (found==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
getch () ;
textcolor(WHITE);
}
mfile.close();
}

//************************************************** **********
//MODIFIES THE STATUS ON RETURNING A MOVIE
//************************************************** **********

void movie :: modstat(char ch,char name[])
{
int found =0;
fstream mfile;
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name))==0)
{
m1.issued=ch;
found++;
int n=mfile.tellg() ;
mfile.seekg(n-sizeof(m1));
mfile.write((char*)&m1,sizeof(m1));
}
mfile.read((char*)&m1,sizeof(m1));
}
if (found==0)
{
gotoxy(27,25);
textcolor(WHITE+BLINK);
cprintf("MOVIE NOT FOUND !!!!");
getch();
textcolor(WHITE);
}
mfile.close();
}

//************************************************** ************
//CODE FOR DELETING A MOVIE
//************************************************** ************

void movie :: mdelete()
{
fstream mfile,m1file;
char mname[20];
int count=0;
cout<<" \n\n\t\t\tENTER THE MOVIE TO BE DELETED: ";
gets(mname);
mfile.open("movie.dat",ios::in);
m1file.open("movie1.dat",ios::app|ios::out);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if(strcmp(m1.mname, mname)!=0)
{
m1file.write((char*)&m1,sizeof(m1));
count++;
}
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
m1file.close();
remove("movie.dat");
rename("movie1.dat","movie.dat");
if (count!=0)
{
gotoxy(27,25);
textcolor(RED+BLINK);
cprintf(" MOVIE DELETED !!!!");
textcolor(WHITE);
}
}

//************************************************** **********
//CLASS FOR MAINTAINING VIDEO PRICES
//************************************************** **********

class video
{
char vtype[15];
float vprice;
float vexch;
protected:
int vcode;
public:
void vinput();
void vdisplay();
void vadd();
int type_exist(char[]);
int type_check(char[]);
int rec_no();
int calexcharges(char [],int);
}v1;
int video :: calexcharges(char name[],int i)
{
fstream mfile,vfile;
char type[10];
int ch;
mfile.open("movie.dat",ios::in);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if((strcmp(m1.mname,name)==0))
{
strcpy(type,m1.vtype);
}
mfile.read((char*)&m1,sizeof(m1));
}

vfile.open("video.dat",ios::in);
vfile.seekg(0, ios::beg);
vfile.read((char*)&v1,sizeof(v1));
while(!vfile.eof())
{
if((strcmp(type,v1.vtype)==0))
{
ch=v1.vexch;
}
vfile.read((char*)&v1,sizeof(v1));
}
mfile.close();
vfile.close();
int exch=ch*i;
return exch;
}
void video :: vinput()
{
int check, found;
cout<<"\n\t\t ENTER THE VIDEO CODE :";
cin<<vcode;
cout<<"\t\t ENTER THE VIDEO TYPE (CD/DVD/CASSETTE) :";
cin>>vtype;
cout<<"\t\t ENTER THE VIDEO PRICE :Rs. ";
cin>>vprice;
cout<<"\t\t ENTER THE EXTRA CHARGES(PER DAY) :Rs. ";
cin>>vexch;
}

//************************************************** *********
//CODE FOR ADDING VIDEO TYPE TO A FILE
//************************************************** *********

void video :: vadd()
{
fstream vfile;
char ans='y';
vfile.open("video.dat",ios::in|ios::app);
while(ans=='y')
{
clrscr();
header();
cout<<"\n\n\n\t\t\t VIDEO DETAILS";
cout<<"\n\t\t\t -------------";
v1.vinput();
vfile.write((char*)&v1,sizeof(v1));
vcode=vcode+1;
cout<<"\t\t CONTINUE (Y/N) :";
cin>>ans;
}
vfile.close();
}

//************************************************** ************
//CLASS TRANSACTION:
// FOR MAINTAINING CUSTOMER FILE AND RELATED RECORDS
//************************************************** ************

class trans : public movie, public video
{
date1 curr_date,ret_date;
int id;
char cname[20];
char cadd[40];
float charges;
int days;
int nddays;
char ch;
public:
int cinput();
void cuadd();
void mcdisplay(char []);
void cdisplay(char []);
int rec_no();
void report();
void cdelete(char[]);
void search_menu();
void mcsearch();
void csearch();
void dheader();
void lmdisplay();
void d1header();
void lmadisplay();
void cshow();
void cheader();
void lmrdisplay();
int check_day(int,int);
void retdate();
void show_date(int,int,int,int);
void ddays();
int showdays(int,int);
friend int validate(date1 &da);
}t1;
int trans :: rec_no ()
{
fstream cfile;
int rno;
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
int n=cfile.tellg();
cfile.close() ;
if (n<=0||cfile.eof())
{
rno=1;
return rno;
}
else
{
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
cfile.read((char*)&t1,sizeof(t1));
while(!cfile.eof())
{
rno=t1.id;
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
return (rno+1);
}
}
int trans :: cinput()
{
int k;
cout<<"\n\t\t CUSTOMER ID : ";
cout<<id<<endl;
cout<<"\t\t ENTER THE CUSTOMER NAME : ";
gets(cname);
cout<<"\t\t ENTER THE ADDRESS : ";
gets(cadd);
cout<<"\t\t ENTER THE MOVIE NAME : ";
gets(mname);
k=m1.movieissued(mname);
if (k==0)
{
m1.modstat('t',mname);
cout<<"\t\t ENTER THE MOVIE CHARGES : Rs. ";
cin>>charges;
cout<<"\t\t ENTER NO.OF DAYS,MOVIE ISSUED : ";
cin>>days;
cout<<"\t\t ENTER THE ISSUE DATE(dd/mm/yyyy): ";
ll: cin>>curr_date.dd>>ch;
cin>>curr_date.mm>>ch;
cin>>curr_date.yyyy;
if (validate(curr_date)==0)
{
gotoxy(27,22);
textcolor(WHITE+BLINK);
cprintf("INVALID DATE!!! ");
getch() ;
textcolor(WHITE);
gotoxy(27,22);
clreol();
gotoxy(56,12);
clreol();
goto ll;
}
cout<<"\t\t RETURN DATE : ";
retdate();
cout<<"\t\t\t\t\tISSUED(T/F) : ";
cin>>issued;
}
else
{
gotoxy(25,20);
textcolor(WHITE+BLINK);
cprintf("MOVIE ALREADY ISSUED OR DOES NOT EXIST");
getch() ;
textcolor(WHITE);
gotoxy(25,20);
clreol();
}
return k;
}

//************************************************** *******************
//CODE FOR ADDING CUSTOMER RECORD TO A FILE OR ISSUE A MOVIE
//************************************************** *******************

void trans :: cuadd()
{
int aa;
fstream cfile;
char ans='y';
id=rec_no();
cfile.open("cust.dat",ios::out|ios::app) ;
while(ans=='y')
{
clrscr();
header();
cout<<"\n\n\t\t\t ISSUE DETAILS";
cout<<"\n\t\t\t -------------" ;
aa=t1.cinput();
if(aa==0)
{
cfile.write((char*)&t1,sizeof(t1));
id=id+1;
}
cout<<"\n\t\t\t CONTINUE (Y/N) : ";
cin>>ans;
}
cfile.close();
}
void trans :: cdisplay(char name[])
{
int tcharges;
cout<<"\n\t\t\t CUSTOMER ADDRESS : ";
puts(cadd);
cout<<"\t\t\t MOVIE NAME : ";
puts(mname);
cout<<"\t\t\t MOVIE CHARGES : Rs. "<<charges;
cout<<"\n\t\t\t ISSUED DAYS : "<<days;
cout<<"\n\t\t\t ISSUED DATE(DD/MM/YY) :
"<<curr_date.dd<<ch<<curr_date.mm<<ch<<curr_date.y yyy;
cout<<"\n\t\t\t RETURN DATE :
"<<ret_date.dd<<ch<<ret_date.mm<<ch<<ret_date.yyyy ;
cout<<"\n\t\t\t DUE DAYS : ";
ddays() ;
int exch=calexcharges(name,t1.nddays);
cout<<"\n\t\t\t EXTRA CHARGES : Rs. "<<exch;
tcharges=exch+t1.charges;
cout<<"\n\t\t\t TOTAL CHARGES : Rs. "<<tcharges;
}
void trans :: mcdisplay(char name[])
{
int tcharges;
cout<<"\n\t\t\t CUSTOMER NAME : ";
puts(cname);
cout<<"\t\t\t CUSTOMER ADDRESS : ";
puts(cadd);
cout<<"\t\t\t MOVIE CHARGES : Rs. "<<charges;
cout<<"\n\t\t\t ISSUED DAYS : "<<days;
cout<<"\n\t\t\t ISSUED DATE(DD/MM/YY) :
"<<curr_date.dd<<ch<<curr_date.mm<<ch<<curr_date.y yyy;
cout<<"\n\t\t\t RETURN DATE :
"<<ret_date.dd<<ch<<ret_date.mm<<ch<<ret_date.yyyy ;
cout<<"\n\t\t\t DUE DAYS : ";
ddays() ;
int exch=calexcharges(name,t1.nddays);
cout<<"\n\t\t\t EXTRA CHARGES : Rs. "<<exch;
tcharges=exch+t1.charges;
cout<<"\n\t\t\t TOTAL CHARGES : Rs. "<<tcharges;
}
int showdays(int,int);

void trans :: ddays()
{
struct dosdate_t d;
_dos_getdate(&d);
int ch=0;
int ddays=0;
int mm=ret_date.mm;
if(d.day<=ret_date.dd)
{
t1.nddays=ddays;
cout<<"-";
}
else
{
if(d.month==mm)
{
switch (mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays=d.day-ret_date.dd;
mm++;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays=d.day-ret_date.dd;
mm++;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays=d.day-ret_date.dd;
mm++ ;
}
else
{
ddays=d.day-ret_date.dd;
mm++;
}
break;
}
ch++;
}
else
{
switch (mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays=31-ret_date.dd;
mm++;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays=30-ret_date.dd;
mm++;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays=29-ret_date.dd;
mm++;
}
else
{
ddays=28-ret_date.dd;
mm++;
}
break;
}
ch++;
}

if(d.year==(ret_date.yyyy+1))
{
if (mm==13)
mm=1;
while(mm<d.month)
{
switch(mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays=showdays(ddays,31);
mm++ ;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays=showdays(ddays,30);
mm++ ;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays=showdays(ddays,29);
mm++ ;
}
else
{
ddays=showdays(ddays,28);
mm++;
}
break;
}
ch++;
}
if (mm==d.month)
goto ll;
}
}
{
if (ret_date.yyyy==d.year)
{
if(d.month==(ret_date.mm+1))
{
ll: switch (mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays+=d.day;
mm++;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays+=d.day;
mm++;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays+=d.day;
mm++;
}
else
{
ddays+=d.day;
mm++;
}
break;
}
ch++;
}
else
{
while(mm<d.month)
{
switch(mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays+=31;
mm++;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays+=30;
mm++;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays+=29;
mm++;
}
else
{
ddays+=28;
mm++;
}
break;
}
if (mm==d.month)
{
switch(mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:ddays+=d.day;
mm++ ;
break;
case 4 :
case 6 :
case 9 :
case 11:ddays+=d.day;
mm++ ;
break;
case 2 :if((ret_date.yyyy%4==0))
{
ddays+=d.day;
mm++;
}
else
{
ddays+=d.day;
mm++;
}
break;
}
ch++;
}
}
}
}
t1.nddays=ddays;
cout<<t1.nddays;
}
}
int trans :: showdays(int duedays,int lastd)
{
duedays+=lastd;
return duedays;
}

//************************************************** ******************************
//CODE FOR SEARCHING A CUSTOMER RECORD AND DELETE IT,IN CASE OF
RETURNING
//THE MOVIE
//************************************************** ******************************

void trans :: search_menu()
{
int choice;
do
{
ac: clrscr();
header();
cout<<"\n\n\n\n\t\t\t SEARCH MENU ";
cout<<"\n\t\t\t ----------- ";
cout<<"\n\t\t\t 1: SEARCH BY CUSTOMER NAME ";
cout<<"\n\t\t\t 2: SEARCH BY MOVIE NAME ";
cout<<"\n\t\t\t 3: RETURN TO MAIN MENU ";
cout<<"\n\t\t\t ENTER YOUR CHOICE : ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
header();
t1.csearch();
getch();
break;
case 2: clrscr();
header();
t1.mcsearch();
getch() ;
break;
case 3: break;
default: cout <<"\n\n\n\n\n\n\t\t\t INVALID CHOICE !!!!!!!!! ";
getch () ;
goto ac;
}
}while(choice>=1&&choice<3);
}
void trans :: mcsearch()
{
char ans = 'y';
char name[20] ;
char pname[20];
fstream cfile;
cout<<"\n\t\tENTER THE MOVIE NAME TO BE SEARCHED: ";
gets(name);
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
while(!cfile.eof())
{
if((strcmp(t1.mname,name)==0))
{
t1.mcdisplay(name);
cout<<"\n\n\n\t\t DO YOU WISH TO DELETE?(Y/N): ";
cin>>ans;
if (ans=='y'||ans=='Y')
{
cdelete(t1.cname);
}
}
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
}
void trans :: csearch()
{
char ans = 'y' ;
char name[20];
char pname[20];
fstream cfile;
cout<<"\n\t\tENTER THE CUSTOMER NAME TO BE SEARCHED: ";
gets(name);
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
while(!cfile.eof())
{
if((strcmp(t1.cname,name)==0))
{
t1.cdisplay(t1.mname);
cout<<"\n\n\n\t\t DO YOU WISH TO DELETE?(Y/N): ";
cin>>ans;
if (ans=='y'||ans=='Y')
{
cdelete(name);
}
}
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
}
void trans :: cdelete(char name[])
{
fstream cfile,c1file;
char cname[20];
cfile.open("cust.dat",ios::in);
c1file.open("cust1.dat",ios::app|ios::out);
cfile.seekg(0, ios::beg);
cfile.read((char*)&t1, sizeof(t1));
while(!cfile.eof())
{
if(strcmp(t1.cname,name)!=0)
{
c1file.write((char*)&t1,sizeof(t1));
}
else
{
m1.modstat('f',t1.mname);
}
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
c1file.close();
remove("cust.dat");
rename("cust1.dat","cust.dat");
}

//************************************************** ****************
//CODE FOR CHECKING RECORDS
//************************************************** ****************

void trans :: report()
{
int choice;
do
{
ab1 : clrscr();
header() ;
cout<<"\n\n\n\n\t\t\t REPORT MENU";
cout<<"\n\t\t\t -----------";
cout<<"\n\t\t\t 1: LIST OF MOVIES ";
cout<<"\n\t\t\t 2: LIST OF MOVIES TO BE RETURNED ";
cout<<"\n\t\t\t 3: LIST OF MOVIES AVALAIBLE";
cout<<"\n\t\t\t 4: RETURN TO MAIN MENU ";
cout<<"\n\t\t\t ENTER YOUR CHOICE : ";
cin>>choice;
switch (choice)
{
case 1: clrscr();
header();
t1.dheader();
t1.lmdisplay();
getch();
break;
case 2: clrscr();
header();
t1.cheader();
t1.lmrdisplay();
getch() ;
break;
case 3: clrscr();
header();
t1.d1header();
t1.lmadisplay();
getch();
break;
case 4: break;
default: cout<<"\n\n\n\n\n\n\t\t\t INVALID CHOICE !!!!!!!!! ";
getch();
goto ab1;
}
}while(choice>=1 && choice<4);
}
void trans :: dheader()
{
gotoxy(2,4);
cout<<"MOVIE CODE NAME LANGUAGE VIDEO TYPE ";
gotoxy(2,5);
cout<<"---------- ---- -------- ---------- ";
}
void trans :: lmdisplay()
{
int n=5;
fstream mfile;
mfile.open("movie.dat",ios::in);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
n+=1;
gotoxy(7,n);
cout<<m1.mcode;
gotoxy(16,n);
puts(m1.mname);
gotoxy(37,n);
puts(m1.mlang);
gotoxy(50,n);
puts(m1.vtype);
cout<<endl;
mfile.read((char*)&m1, sizeof(m1));
}
mfile.close();
}
void trans :: d1header()
{
gotoxy(2,4);
cout<<"MOVIE CODE MOVIE NAME VIDEO TYPE ";
gotoxy(2,5);
cout<<"---------- ---------- ---------- ";
}
void trans :: lmadisplay()
{
int n=5;
fstream mfile;
mfile.open("movie.dat",ios::in|ios::out);
mfile.seekg(0, ios::beg);
mfile.read((char*)&m1,sizeof(m1));
while(!mfile.eof())
{
if(m1.issued=='f')
{
n+=1;
gotoxy(7,n);
cout<<m1.mcode;
gotoxy(16,n);
puts(m1.mname);
gotoxy(42,n);
puts(m1.vtype);
cout<<endl ;
}
mfile.read((char*)&m1,sizeof(m1));
}
mfile.close();
}
void trans :: cheader()
{
gotoxy(2,4);
cout<<"CUSTOMER NAME MOVIE ISSUED ISSUE DATE RETURN DATE ";
gotoxy(2,5);
cout<<"------------- ------------ ----------
----------- ";
}
void trans :: lmrdisplay()
{
int n=5;
fstream cfile;
cfile.open("cust.dat",ios::in);
cfile.seekg(0, ios::beg);
cfile.read((char*)&t1,sizeof(t1));
while(!cfile.eof())
{
n+=1;
gotoxy(2,n);
puts(t1.cname);
gotoxy(20,n);
puts(t1.mname);
gotoxy(43,n);
cout<<curr_date.dd<<"/"<<curr_date.mm<<"/"<<curr_date.yyyy;
gotoxy(57,n);
cout<<ret_date.dd<<"/"<<ret_date.mm<<"/"<<ret_date.yyyy;
cout<<endl ;
cfile.read((char*)&t1,sizeof(t1));
}
cfile.close();
}
int validate(date1 &da)
{
int flag=1;
struct dosdate_t d;
_dos_getdate(&d);
if(da.yyyy!=d.year)
{
flag=0;
return flag;
}
else
{
if((da.yyyy<=0)||(da.mm<=0)||(da.dd<=0))
flag=0;
else
{
switch (da.mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:flag=t1.check_day(da.dd,31);
break;
case 4 :
case 6 :
case 9 :
case 11: flag=t1.check_day(da.dd,30);
break;
case 2 : if((da.yyyy%4==0))
flag=t1.check_day(da.dd,29);
else
flag=t1.check_day(da.dd,28);
break;
default: flag=0;
}
}
return flag;
}
}
void trans :: retdate()
{
char ch;
switch (curr_date.mm)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:show_date(curr_date.dd,curr_date.mm,curr_date.y yyy,31);
break;
case 4 :
case 6 :
case 9 :
case 11:show_date(curr_date.dd,curr_date.mm,curr_date.y yyy,30);
break;
case 2 : if((curr_date.yyyy%4==0))
show_date(curr_date.dd,curr_date.mm,curr_date.yyyy ,29);
else
show_date(curr_date.dd,curr_date.mm,curr_date.yyyy ,28);
break;
}
}
void trans :: show_date(int date,int mm,int yyyy,int lastd)
{
int rdate=t1.days;
rdate+=date;
if(rdate>lastd && mm==12)
{
mm=1;
cout<< (rdate-=lastd) <<"/"<<mm<<"/"<< (yyyy+=1) ;
getch();
}
else
{
if(rdate>lastd)
{
cout<< (rdate-=lastd) <<"/"<<(mm+=1)<<"/"<<yyyy;
getch();
}
else
{
cout<<rdate<<"/"<<mm<<"/"<<yyyy;
getch();
}
}
ret_date.dd=rdate;
ret_date.mm=mm;
ret_date.yyyy=yyyy;
}
int trans :: check_day(int day,int lastd)
{
if ((day>=1)&&(day<=lastd))
return 1;
else
return 0;
}

//************************************************** **************************
//CODE TO PRINT A BOX
//************************************************** **************************

void line_hor(int col1,int col2,int row, char c)
{
for(col1;col1<=col2;col1++)
{
gotoxy(col1,row);
cout<<c;
}
}
void line_ver(int row1,int row2,int col,char c)
{
for(row1;row1<=row2;row1++)
{
gotoxy(col,row1);
cout<<c;
}
}
void print_box()
{
clrscr();
line_hor(1,79,1,219);
line_hor(1,79,25,219);
line_ver(1,25,1,219);
line_ver(1,25,79,219);
delay(50);
line_hor(2,78,2,219);
line_hor(2,78,24,219);
line_ver(2,24,2,219);
line_ver(2,24,78,219);
delay(50);
line_hor(3,77,3,219);
line_hor(3,77,23,219);
line_ver(3,23,3,219);
line_ver(3,23,77,219);
delay(50);
line_hor(4,76,4,178);
line_hor(4,76,22,178);
line_ver(4,22,4,178);
line_ver(4,22,76,178);
delay(50);
line_hor(5,75,5,178);
line_hor(5,75,21,178);
line_ver(5,21,5,178);
line_ver(5,21,75,178);
delay(50);
line_hor(6,74,6,178);
line_hor(6,74,20,178);
line_ver(6,20,6,178);
line_ver(6,20,74,178);
delay(50);
line_hor(7,73,7,177);
line_hor(7,73,19,177);
line_ver(7,19,7,177);
line_ver(7,19,73,177);
delay(50);
line_hor(8,72,8,177);
line_hor(8,72,18,177);
line_ver(8,18,8,177);
line_ver(8,18,72,177);
delay(50);
line_hor(9,71,9,177);
line_hor(9,71,17,177);
line_ver(9,17,9,177);
line_ver(9,17,71,177);
delay(50);
line_hor(10,70,10,178);
line_hor(10,70,16,178);
line_ver(10,16,10,178);
line_ver(10,16,70,178);
delay(50);
line_hor(11,69,11,178);
line_hor(11,69,15,178);
line_ver(11,15,11,178);
line_ver(11,15,69,178);
delay(50);
_setcursortype(_NOCURSOR);
gotoxy(30,13);
textcolor(GREEN+BLINK);
cprintf("VIDEO LIBRARY SYSTEM");
getch();
gotoxy(30,13);
clreol() ;
textcolor(WHITE);
pass();
textcolor(WHITE);
}

//************************************************** ****************************
//CODE TO ACCEPT THE PASSWORD
//************************************************** ****************************

void pass()
{
char pass[]={"videolib"};
int s=strlen(pass);
char pass1[10];
int count=0;
clrscr();
line_hor(1,79,1,219);
line_hor(1,79,25,219);
line_ver(1,25,1,219);
line_ver(1,25,79,219);
delay(50);
line_hor(2,78,2,219);
line_hor(2,78,24,219);
line_ver(2,24,2,219);
line_ver(2,24,78,219);
delay(50);
line_hor(3,77,3,219);
line_hor(3,77,23,219);
line_ver(3,23,3,219);
line_ver(3,23,77,219);
delay(50);
line_hor(4,76,4,178);
line_hor(4,76,22,178);
line_ver(4,22,4,178);
line_ver(4,22,76,178);
delay(50);
line_hor(5,75,5,178);
line_hor(5,75,21,178);
line_ver(5,21,5,178);
line_ver(5,21,75,178);
delay(50);
line_hor(6,74,6,178);
line_hor(6,74,20,178);
line_ver(6,20,6,178) ;
line_ver(6,20,74,178);
delay(50);
line_hor(7,73,7,177);
line_hor(7,73,19,177);
line_ver(7,19,7,177);
line_ver(7,19,73,177);
delay(50);
line_hor(8,72,8,177);
line_hor(8,72,18,177);
line_ver(8,18,8,177);
line_ver(8,18,72,177);
delay(50);
line_hor(9,71,9,177);
line_hor(9,71,17,177);
line_ver(9,17,9,177);
line_ver(9,17,71,177);
delay(50);
line_hor(10,70,10,178);
line_hor(10,70,16,178);
line_ver(10,16,10,178);
line_ver(10,16,70,178);
delay(50);
line_hor(11,69,11,178);
line_hor(11,69,15,178);
line_ver(11,15,11,178);
line_ver(11,15,69,178);
delay(50);
gotoxy(27,13);
cout<<"ENTER THE PASSWORD:";
ll : for (int i=0; i<s; i++)
{
pass1[i]=getch();
cout<<"*";
}
if(strcmp(pass,pass1)==0)
{
count++;
return;
}
else
{
if(strcmp(pass,pass1)!=0)
{
gotoxy(27,13);
textcolor(RED+BLINK);
cprintf("SORRY! INVALID PASSWORD!!!!!");
textcolor(WHITE);
getch() ;
exit(0) ;
}
}
}
void print_box();

void header();

//************************************************** ***************
//main() starts from here
//************************************************** ***************

void main()
{
print_box();
clrscr();
int choice;
do
{
again : clrscr();
header();
cout<<"\n\n\n\n\t\t\t MAIN MENU ";
cout<<"\n\t\t\t --------- ";
cout<<"\n\t\t\t 1: REGISTER A NEW MOVIE ";
cout<<"\n\t\t\t 2: SEARCH FOR A MOVIE ";
cout<<"\n\t\t\t 3: MODIFY INFO OF A MOVIE ";
cout<<"\n\t\t\t 4: ISSUE A MOVIE ";
cout<<"\n\t\t\t 5: RETURN A MOVIE ";
cout<<"\n\t\t\t 6: DELETE A MOVIE ";
cout<<"\n\t\t\t 7: ADD A VIDEO TYPE ";
cout<<"\n\t\t\t 8: REPORTS ";
cout<<"\n\t\t\t 9: EXIT ";
cout<<"\n\t\t\t ENTER YOUR CHOICE : ";
cin>>choice;
switch (choice)
{
case 1 : m1.madd();
break;
case 2 : clrscr();
header();
m1.msearch();
getch () ;
break;
case 3 : clrscr();
header();
m1.modify();
break;
case 4 : clrscr();
header();
t1.cuadd();
break;
case 5 : clrscr();
header();
t1.search_menu();
getch () ;
break;
case 6 : clrscr();
header();
m1.mdelete();
getch();
break;
case 7 : clrscr();
header();
v1.vadd();
break;
case 8 : t1.report();
break;
case 9 : clrscr();
exit(0);
default : cout<<"\n\n\n\n\n\t\t\t INVALID CHOICE !!!!!!! ";
getch () ;
goto again;
}
}while(choice>=1&&choice<=9);
}
void header()
{
gotoxy(25,1);
cout<<" VIDEO LIBRARY SYSTEM "<<endl;
gotoxy(25,2);
cout<<" -------------------- ";
}

--------------
I wandered around in your code for a while but reached no firm conclusions.
But I have the *impression* that you want one file to be created for a
collection of movies. All with the same file name. IOW, do you, by chance,
want an *array* of movies - all in one file?

I wouldn't expect you to get much help here. You use non-standard headers,
which means that a lot of users *couldn't* compile your program, even if
they wanted to. You use global variables - a no no. You have no
indentation - at least as viewed on my mail program. There are no really
useful comments. The thing you posted has got a lot of extraneous stuff,
not related to your current problem. The program is improperly structured
since the variables in movie are all public. Some of the names of the
functions look misleading to me. You ignore status values returned from
system functions, such as open().

If my guess is right you need substantial re-thinking and you might want to
start over. If you do, I suggest you start small and grow the program.
Compile often - just because you compile doesn't mean you have to run the
result.
Jul 23 '05 #3

P: n/a
Enter 12 movies in menu no 1.
After that, When I try to enter a movie, it shows some crap in menu no
8-1.
it shows only 12 movies in menu no 8-3.
check for yourself, thats the problem i was facing.
Bye

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.