473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help Needed in file handling

> > 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
3 2674
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: GAR | last post by:
I recently set up ampache so I can have an mp3 server. I dont like how they display album covers so I decided to try and change it a little. Instead of taking the album cover from the mp3s...
3
by: H Brown New To It | last post by:
I am very new to Java. How would you go about making Java program that reads in a fixed length text file and pass the data into a table in an sql table? The text file data looks something like...
2
by: nephish | last post by:
Hey there, i am trying to write an online application using the cgi module. what i want to do is have an html form display a drop-down list and have the values of that list be the lines of text...
14
by: StumpY | last post by:
HI, I have set up a page with a form which appends data to a .csv file on my asp server, this is to enable a limited number of users to add news threads to this file, which contains the data in...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: Mike | last post by:
Greetings, Having a major problem here. running version 8.2 on win2003 server. The problem I am having is backing up a database seems to get to the last part of the backup and then fails. This...
5
by: NG | last post by:
Hi, We are having DB2-V7.2 DB on AIX 5.2 machine. Recently we upgraded our system to fixpack 13 and activated activate AIX asynchronous IO function. Our DB is going to crash recovery with...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
36
by: felixnielsen | last post by:
What i really wanna do, is defining my own types, it doesnt really matter why. Anyway, i have run into some problems 1) typedef unsigned short U16; U16 test = 0xffffffff; // There should be a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.