This projects creates a library of the casettes n cds of hindi/english n other films.It then creates the records of the customers/members subcribing to these casetted n cds. You can modify this project and add games CDs to it instead of films.
made by niket anand.
//**********************************************************
// PROJECT VIDEO LIBRARY
//**********************************************************
//**********************************************************
// INCLUDED HEADER FILES
//**********************************************************
#include <iostream.h>
#include <fstream.h>
#include <process.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
//**********************************************************
// THIS CLASS CONTAINS ALL THE DRAWING FUNCTIONS
//**********************************************************
class LINES
{
public :
void LINE_HOR(int, int, int, char) ;
void LINE_VER(int, int, int, char) ;
void BOX(int,int,int,int,char) ;
} ;
//**********************************************************
// THIS CLASS CONTROL ALL THE FUNCTIONS IN THE MENU
//**********************************************************
class MENU
{
public :
void MAIN_MENU() ;
char *CHOICE_MENU() ;
void introduction(void) ;
void HELP(void);
private :
void EDIT_MENU() ;
void EDIT_MENU1() ;
void EDIT_MENU2() ;
void DISPLAY_MENU() ;
} ;
//**********************************************************
// THIS CLASS CONTROL ALL THE FUNCTIONS RELATED TO CASSETTE
//**********************************************************
class CASSETTE
{
public :
void ADDITION() ;
void MODIFICATION() ;
void DELETION();
void LIST() ;
void DISPLAY() ;
char *CASNAME(char[], int) ;
void UPDATE(char[], int, int, char) ;
protected :
int ISSUED(char[], int) ;
int FOUND_CODE(char[], int) ;
void DISPLAY_RECORD(char[], int) ;
void DISPLAY_LIST(char[]) ;
private :
int RECORDNO(char[], int) ;
void ADD_RECORD(char[], int, char[], char,int) ;
int LASTCODE(char[]) ;
void DELETE_RECORD(char[], int) ;
int code, custcode ;
char name[36], status ;
} ;
//**********************************************************
// THIS CLASS CONTROL ALL THE FUNCTIONS RELATED TO CUSTOMER
//**********************************************************
class CUSTOMER
{
public :
void LIST() ;
void DISPLAY() ;
char *CUSTNAME(int) ;
protected :
void ADD_RECORD(int, char[], char[], char[], int, int, int, int) ;
void DELETE_RECORD(int) ;
int FOUND_CODE(int) ;
int LASTCODE() ;
void DISPLAY_RECORD(int) ;
int FINE(int) ;
private :
int code, cassette ;
char name[26], phone[10], fname[13] ;
int dd, mm, yy ; // DATE OF RETURN
} ;
//**********************************************************
// THIS CLASS CONTROL ALL THE FUNCTIONS RELATED TO ISSUE &
// RETURN & CALCULATING FINE ETC.
//**********************************************************
class ISSUE_RETURN : public CASSETTE, public CUSTOMER
{
public :
void ISSUE() ;
void RETURN() ;
int DIFF(int, int, int, int, int, int) ;
private :
void EXTEND_DATE(int,int,int,int) ;
int day, mon, year ;
} ;
//**********************************************************
// FUNCTION TO DISPLAY THE INTRODUCTION FOR THE PROJECT.
//**********************************************************
void MENU :: introduction(void)
{
LINES line ;
textmode(C40) ;
clrscr() ;
line.BOX(2,1,39,25,219) ;
gotoxy(13,5) ;
cout <<"COMPUTER PROJECT" ;
line.BOX(9,6,34,8,178) ;
gotoxy(10,7) ;
cout <<"VIDEO LIBRARY MANAGEMENT" ;
gotoxy(6,12) ;
cout <<"BY: NIKET ANAND && ASHISH PATRO" ;
gotoxy(10,14) ;
cout <<"XII-C" ;
gotoxy(6,17) ;
cout <<"Special Thanx To MR. MOHAN SINGH" ;
textcolor(BLACK+BLINK) ;
gotoxy(8,20); textbackground(WHITE) ;
cprintf("Press any key to continue..") ;
textcolor(RED) ;
getch() ;
}
//**********************************************************
// THIS FUNCTION CONTROL ALL THE FUNCTIONS IN THE MAIN MENU
//**********************************************************
void MENU :: MAIN_MENU()
{
char ch ;
LINES line ;
do
{
textmode(C40) ;
clrscr() ;
line.BOX(2,1,39,25,219) ;
line.BOX(6,5,35,21,218) ;
line.BOX(12,7,26,9,218) ;
gotoxy(13,8) ;
cout <<"VIDEO LIBRARY" ;
gotoxy(11,12) ;
cout <<"1: ISSUE CASSETTE" ;
gotoxy(11,13) ;
cout <<"2: RETURN CASSETTE" ;
gotoxy(11,14) ;
cout <<"3: DISPLAY" ;
gotoxy(11,15) ;
cout <<"4: EDIT" ;
gotoxy(11,16) ;
cout<<"5: HELP";
gotoxy(11,17);
cout <<"0: QUIT" ;
gotoxy(11,19) ;
cout <<"Enter your choice:" ;
ch = getch() ;
textmode(C80) ;
clrscr() ;
CASSETTE cas ;
ISSUE_RETURN ir ;
switch(ch)
{
case 27,'0' : break ;
case '1' :
ir.ISSUE() ;
break ;
case '2' :
ir.RETURN() ;
break ;
case '3' :
DISPLAY_MENU() ;
break ;
case '4' :
EDIT_MENU() ;
break ;
case '5' :
HELP();
break;
}
} while (ch != 27 && ch != '0') ;
}
//**********************************************************
// THIS FUNCTION DISPLAYS HELP MENU
//**********************************************************
void MENU :: HELP(void)
{
LINES line ;
textmode(C40) ;
clrscr() ;
line.BOX(2,1,39,25,219) ;
gotoxy(13,5) ;
cout <<"HELP" ;
line.BOX(9,6,34,8,178) ;
gotoxy(10,7) ;
cout <<"VIDEO LIBRARY MANAGEMENT" ;
gotoxy(4,12) ;
cout <<"This program issues cassettes to" ;
gotoxy(4,13);
cout<<"people for 5 days.A fine of RS. 20";
gotoxy(4,14);
cout<<"is imposed on custumer for late ";
gotoxy(4,15);
cout<<"return.It also offers customers to ";
gotoxy(4,16);
cout<<"issue cassettes under various ";
gotoxy(4,17);
cout<<"headings. ";
getch() ;
}
//**********************************************************
// THIS FUNCTION RETURNS THE NAME OF THE FILE SELECTED
//**********************************************************
char *MENU :: CHOICE_MENU(void)
{
char ch ;
LINES line ;
do
{
textmode(C40) ;
clrscr() ;
line.BOX(2,1,39,25,219) ;
line.BOX(6,5,35,21,218) ;
gotoxy(11,9) ;
cout <<"SELECT CASSETTE FOR..." ;
gotoxy(12,12) ;
cout <<"H: HINDI FILMS" ;
gotoxy(12,13) ;
cout <<"E: ENGLISH FILMS" ;
gotoxy(12,14) ;
cout <<"N: NON FILMS" ;
gotoxy(12,17) ;
cout <<"Enter your choice:" ;
ch = getch() ;
ch = toupper(ch) ;
textmode(C80) ;
clrscr() ;
switch(ch)
{
case 27,'0' :
break ;
case 'H' :
return "HINDI.DAT" ;
case 'E' :
return "ENGLISH.DAT" ;
case 'N' :
return "NONFILM.DAT" ;
}
} while (ch != 27 && ch != '0') ;
return "FAILED" ;
}
//**********************************************************
// THIS FUNCTION CONTROL ALL THE FUNCTIONS IN THE EDIT MENU FOR CASSETTE
// (MODIFICATION, DELETION).
//**********************************************************
void MENU :: EDIT_MENU1(void)
{
char ch ;
LINES line ;
do
{
textmode(C40) ;
clrscr() ;
line.BOX(2,1,39,25,219) ;
line.BOX(6,5,35,21,218) ;
line.BOX(14,8,24,10,218) ;
gotoxy(15,9) ;
cout <<"EDIT MENU" ;
gotoxy(10,12) ;
cout <<"1: ADD CASSETTE" ;
gotoxy(10,14) ;
cout <<"2: MODIFY CASSETTE" ;
gotoxy(10,16) ;
cout <<"3: DELETE CASSETTE" ;
gotoxy(10,18) ;
cout <<"Enter your choice:" ;
ch = getch() ;
textmode(C80) ;
clrscr() ;
CASSETTE cas ;
switch(ch)
{
case 27,'0' : break ;
case '1' :
cas.ADDITION();
break ;
case '2' :
cas.MODIFICATION() ;
break ;
case '3' :
cas.DELETION() ;
break ;
}
} while (ch != 27 && ch != '0') ;
}
//**********************************************************
// THIS FUNCTION CONTROL ALL THE FUNCTIONS IN THE EDIT MENU FOR custumer
// (MODIFICATION, DELETION).
//**********************************************************
void MENU :: EDIT_MENU2(void)
{
char ch ;
LINES line ;
do
{
textmode(C40) ;
clrscr() ;
line.BOX(2,1,39,25,219) ;
line.BOX(6,5,35,21,218) ;
line.BOX(14,8,24,10,218) ;
gotoxy(15,9) ;
cout <<"EDIT MENU" ;
gotoxy(10,12) ;
cout <<"1: ADD CASSETTE" ;
gotoxy(10,14) ;
cout <<"2: MODIFY CASSETTE" ;
gotoxy(10,16) ;
cout <<"3: DELETE CASSETTE" ;
gotoxy(10,18) ;
cout <<"Enter your choice:" ;
ch = getch() ;
textmode(C80) ;
clrscr() ;
CASSETTE cas ;
switch(ch)
{
case 27,'0' : break ;
case '1' :
cas.ADDITION();
break ;
case '2' :
cas.MODIFICATION() ;
break ;
case '3' :
cas.DELETION() ;
break ;
}
} while (ch != 27 && ch != '0') ;
}
//**********************************************************
// THIS FUNCTION CONTROL ALL THE FUNCTIONS IN THE EDIT MENU
// (MODIFICATION, DELETION).
//**********************************************************
void MENU :: EDIT_MENU(void)
{
char ch ;
LINES line ;
do
{
textmode(C40) ;
clrscr() ;
line.BOX(2,1,39,25,219) ;
line.BOX(6,5,35,21,218) ;
line.BOX(14,8,24,10,218) ;
gotoxy(15,9) ;
cout <<"EDIT MENU" ;
gotoxy(10,12) ;
cout <<"1:CASSETTE" ;
gotoxy(10,14) ;
cout <<"2: CUSTUMER" ;
gotoxy(10,18);
cout <<"Enter your choice:" ;
ch = getch() ;
textmode(C80) ;
clrscr() ;
;
switch(ch)
{
case 27,'0' : break ;
case '1' :
EDIT_MENU1();
break ;
case '2' :
EDIT_MENU2() ;
break ;
}
} while (ch != 27 && ch != '0') ;
}
//**********************************************************
// THIS FUNCTION CONTROL ALL THE FUNCTIONS RELATED TO
// DISPLAY (LIST, ETC.)
//**********************************************************
void MENU :: DISPLAY_MENU(void)
{
char ch ;
LINES line ;
do
{
textmode(C40) ;
clrscr() ;
line.BOX(2,1,39,25,219) ;
line.BOX(6,5,35,21,218) ;
line.BOX(14,8,25,10,218) ;
gotoxy(15,9) ;
cout <<"DISPLAY..." ;
gotoxy(10,12) ;
cout <<"1: LIST OF CASSETTE" ;
gotoxy(10,13) ;
cout <<"2: LIST OF CUSTOMER" ;
gotoxy(10,14) ;
cout <<"3: CASSETTE RECORD" ;
gotoxy(10,15) ;
cout <<"4: CUSTOMER RECORD" ;
gotoxy(10,16) ;
cout <<"0: EXIT" ;
gotoxy(10,18) ;
cout <<"Enter your choice:" ;
ch = getch() ;
textmode(C80) ;
clrscr() ;
CASSETTE cas ;
CUSTOMER cust ;
switch(ch)
{
case 27,'0' : break ;
case '1' :
cas.LIST() ;
break ;
case '2' :
cust.LIST() ;
break ;
case '3' :
cas.DISPLAY() ;
break ;
case '4' :
cust.DISPLAY() ;
break ;
}
} while (ch != 27 && ch != '0') ;
}
//**********************************************************
// THIS FUNCTION DRAWS THE HORRIZONTAL LINE
//**********************************************************
void LINES :: LINE_HOR(int column1, int column2, int row, char c)
{
for ( column1; column1<=column2; column1++ )
{
gotoxy(column1,row) ;
cout <<c ;
}
}
//**********************************************************
// THIS FUNCTION DRAWS THE VERTICAL LINE
//**********************************************************
void LINES :: LINE_VER(int row1, int row2, int column, char c)
{
for ( row1; row1<=row2; row1++ )
{
gotoxy(column,row1) ;
cout <<c ;
}
}
//**********************************************************
// THIS FUNCTION DRAWS THE BOX
//**********************************************************
void LINES :: BOX(int column1, int row1, int column2, int row2, char c)
{
char ch=218 ;
char c1, c2, c3, c4 ;
char l1=196, l2=179 ;
if (c == ch)
{
c1=218 ;
c2=191 ;
c3=192 ;
c4=217 ;
l1 = 196 ;
l2 = 179 ;
}
else
{
c1=c ;
c2=c ;
c3=c ;
c4=c ;
l1 = c ;
l2 = c ;
}
gotoxy(column1,row1) ;
cout <<c1 ;
gotoxy(column2,row1) ;
cout <<c2 ;
gotoxy(column1,row2) ;
cout <<c3 ;
gotoxy(column2,row2) ;
cout <<c4 ;
column1++ ;
column2-- ;
LINE_HOR(column1,column2,row1,l1) ;
LINE_HOR(column1,column2,row2,l1) ;
column1-- ;
column2++ ;
row1++ ;
row2-- ;
LINE_VER(row1,row2,column1,l2) ;
LINE_VER(row1,row2,column2,l2) ;
}
//**********************************************************
// THIS FUNCTION RETURNS THE LAST CASSETTE'S CODE
//**********************************************************
int CASSETTE :: LASTCODE(char filename[13])
{
fstream file ;
file.open(filename, ios::in) ;
file.seekg(0,ios::beg) ;
int count=0 ;
while (file.read((char *) this, sizeof(CASSETTE)))
count = code ;
file.close() ;
return count ;
}
//**********************************************************
// THIS FUNCTION RETURNS 0 IF THE GIVEN CODE NOT FOUND
//**********************************************************
int CASSETTE :: FOUND_CODE(char filename[13], int cascode)
{
fstream file ;
file.open(filename, ios::in) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *) this, sizeof(CASSETTE)))
{
if (code == cascode)
{
found = 1 ;
break ;
}
}
file.close() ;
return found ;
}
//**********************************************************
// THIS FUNCTION RETURNS RECORD NO. OF THE GIVEN CODE
//**********************************************************
int CASSETTE :: RECORDNO(char filename[13], int cascode)
{
fstream file ;
file.open(filename, ios::in) ;
file.seekg(0,ios::beg) ;
int recno=0 ;
while (file.read((char *) this, sizeof(CASSETTE)))
{
recno++ ;
if (code == cascode)
break ;
}
file.close() ;
return recno ;
}
//**********************************************************
// THIS FUNCTION RETURNS 1 IF CASSETTE IS ISSUDE FOR THE
// GIVEN CODE
//**********************************************************
int CASSETTE :: ISSUED(char filename[13], int cascode)
{
fstream file ;
file.open(filename, ios::in) ;
file.seekg(0,ios::beg) ;
int issued=0 ;
while (file.read((char *) this, sizeof(CASSETTE)))
{
if (code == cascode && status == 'N')
{
issued = 1 ;
break ;
}
}
file.close() ;
return issued ;
}
//**********************************************************
// THIS FUNCTION RETURNS NAME OF THE CASSETTE FOR THE GIVEN
// CODE
//**********************************************************
char *CASSETTE :: CASNAME(char filename[13], int cascode)
{
fstream file ;
file.open(filename, ios::in) ;
file.seekg(0,ios::beg) ;
char casname[36] ;
while (file.read((char *) this, sizeof(CASSETTE)))
{
if (code == cascode)
{
strcpy(casname,name) ;
break ;
}
}
file.close() ;
return casname ;
}
//**********************************************************
// THIS FUNCTION DISPLAYS THE LIST OF THE CASSETTES
//**********************************************************
void CASSETTE :: DISPLAY_LIST(char filename[13])
{
int row = 6 , found=0, flag=0 ;
char ch ;
gotoxy(31,2) ;
cout <<"LIST OF CASSETTES" ;
gotoxy(30,3) ;
cout <<"~~~~~~~~~~~~~~~~~~~" ;
gotoxy(3,4) ;
cout <<"CODE NAME STATUS" ;
gotoxy(1,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
fstream file ;
file.open(filename, ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(CASSETTE)))
{
flag = 0 ;
delay(20) ;
found = 1 ;
gotoxy(4,row) ;
cout <<code ;
gotoxy(10,row) ;
cout <<name ;
gotoxy(59,row) ;
cout <<status ;
if ( row == 23 )
{
flag = 1 ;
row = 6 ;
gotoxy(1,25) ;
cout <<"Press any key to continue or Press <ESC> to exit" ;
ch = getch() ;
if (ch == 27)
break ;
clrscr() ;
gotoxy(31,2) ;
cout <<"LIST OF CASSETTES" ;
gotoxy(30,3) ;
cout <<"~~~~~~~~~~~~~~~~~~~" ;
gotoxy(3,4) ;
cout <<"CODE NAME STATUS" ;
gotoxy(1,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
}
else
row++ ;
}
if (!found)
{
gotoxy(5,10) ;
cout <<"\7Records not found" ;
}
if (!flag)
{
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
}
file.close () ;
}
//**********************************************************
// THIS FUNCTION DISPLAYS THE LIST OF THE CASSETTES
//**********************************************************
void CASSETTE :: LIST(void)
{
MENU menu ;
char filename[13] ;
strcpy(filename,menu.CHOICE_MENU()) ;
if (!strcmpi(filename,"FAILED"))
return ;
DISPLAY_LIST(filename) ;
}
//**********************************************************
// THIS FUNCTION DISPLAYS THE RECORD OF CASSETTE FOR THE
// GIVEN CODE
//**********************************************************
void CASSETTE :: DISPLAY_RECORD(char filename[13], int cascode)
{
CUSTOMER cust ;
fstream file ;
file.open(filename, ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(CASSETTE)))
{
if (code == cascode)
{
gotoxy(5,4) ;
cout <<"Cassette Code # " <<code ;
gotoxy(5,6) ;
cout <<"Cassette Name : " <<name ;
gotoxy(5,7) ;
cout <<"Status : " <<status ;
if (status == 'N' && custcode != 0)
{
gotoxy(5,9) ;
cout <<"Cassette is issued by : " <<cust.CUSTNAME(custcode) ;
}
break ;
}
}
file.close() ;
}
//**********************************************************
// THIS FUNCTION GIVES CODE TO DISPLAYS THE RECORD OF
// CASSETTE
//**********************************************************
void CASSETTE :: DISPLAY(void)
{
MENU menu ;
char filename[13] ;
strcpy(filename,menu.CHOICE_MENU()) ;
if (!strcmpi(filename,"FAILED"))
return ;
char t1[10] ;
int t2, cascode ;
gotoxy(72,2) ;
cout <<"<0>=EXIT" ;
gotoxy(5,5) ;
cout <<"Enter code of the Cassette " ;
gets(t1) ;
t2 = atoi(t1) ;
cascode = t2 ;
if (cascode == 0)
return ;
clrscr() ;
if (!FOUND_CODE(filename,cascode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
LINES line ;
line.BOX(2,1,79,25,218) ;
DISPLAY_RECORD(filename,cascode) ;
gotoxy(5,24) ;
cout <<"Press any key to continue..." ;
getch() ;
}
//**********************************************************
// THIS FUNCTION UPDATE THE GIVEN DATA IN THE CASSETTE'S
// FILE
//**********************************************************
void CASSETTE :: UPDATE(char filename[13], int cascode, int ccode, char casstatus)
{
int recno ;
recno = RECORDNO(filename,cascode) ;
fstream file ;
file.open(filename, ios::out | ios::ate) ;
custcode = ccode ;
status = casstatus ;
int location ;
location = (recno-1) * sizeof(CASSETTE) ;
file.seekp(location) ;
file.write((char *) this, sizeof(CASSETTE)) ;
file.close() ;
}
//**********************************************************
// THIS FUNCTION DELETES THE RECORD OF THE GIVEN CODE.
//**********************************************************
void CASSETTE :: DELETE_RECORD(char filename[13], int cascode)
{
fstream file ;
file.open(filename, ios::in) ;
fstream temp ;
{temp.open("temp.dat", ios::out) ;
file.seekg(0,ios::beg) ;
while (!file.eof())
{
file.read((char *) this, sizeof(CASSETTE)) ;
if (file.eof())
break ;
if (code != cascode)
temp.write((char *) this, sizeof(CASSETTE)) ;
}
file.close() ;
temp.close() ;
file.open(filename, ios::out) ;
temp.open("temp.dat", ios::in) ;
temp.seekg(0,ios::beg) ;
while ( !temp.eof() )
{
temp.read((char *) this, sizeof(CASSETTE)) ;
if ( temp.eof() )
break ;
file.write((char *) this, sizeof(CASSETTE)) ;
}
file.close() ;
temp.close() ;}
}
//**********************************************************
// THIS FUNCTION ADD THE GIVEN DATA IN THE CASSETTE FILE
//**********************************************************
void CASSETTE :: ADD_RECORD(char filename[13], int cascode, char casname[36], char casstatus, int ccode)
{
fstream file ;
file.open(filename, ios::app) ;
code = cascode ;
strcpy(name,casname) ;
status = casstatus ;
custcode = ccode ;
file.write((char *) this, sizeof(CASSETTE)) ;
file.close() ;
}
//**********************************************************
// THIS FUNCTION GIVES DATA TO ADD RECORD IN CASSETTE FILE
//**********************************************************
void CASSETTE :: ADDITION(void)
{
MENU menu ;
char filename[13], casname[36], ch ;
int cascode, valid ;
do
{
strcpy(filename,menu.CHOICE_MENU()) ;
if (!strcmpi(filename,"FAILED"))
return ;
cascode = LASTCODE(filename) + 1 ;
LINES line ;
line.BOX(10,6,71,21,219) ;
line.LINE_HOR(11,70,10,196) ;
gotoxy(72,1) ;
cout <<"<0>=EXIT" ;
gotoxy(27,8) ;
cout <<"ADDITION OF NEW CASSETTES" ;
gotoxy(20,12) ;
cout <<"Code # " <<cascode ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER NAME OF THE CASSETTE" ;
gotoxy(20,14) ;
cout <<" " ;
gotoxy(20,14) ;
cout <<"Name : " ;
gets(casname) ;
if (casname[0] == '0')
return ;
if (strlen(casname) < 1 || strlen(casname) > 35)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7Enter Correctly (Range: 1..35)" ;
getch() ;
}
} while (!valid) ;
gotoxy(5,25) ; clreol() ;
do
{
gotoxy(20,17) ;
cout <<" " ;
gotoxy(20,17) ;
cout <<"Do you want to save (y/n) " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'Y')
{
char casstatus='A' ;
int ccode=0 ;
ADD_RECORD(filename,cascode,casname,casstatus,ccode) ;
cascode++ ;
}
do
{
gotoxy(20,19) ;
cout <<" " ;
gotoxy(20,19) ;
cout <<"Do you want to Add more (y/n) " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'N')
return ;
} while (ch == 'Y') ;
}
//**********************************************************
// THIS FUNCTION MODIFY THE CASSETTE RECORD
//**********************************************************
void CASSETTE :: MODIFICATION(void)
{
MENU menu ;
char t1[10], ch, filename[13] ;
int t2, cascode, valid ;
strcpy(filename,menu.CHOICE_MENU()) ;
if (!strcmpi(filename,"FAILED"))
return ;
do
{
valid = 1 ;
do
{
clrscr() ;
gotoxy(72,2) ;
cout <<"<0>=EXIT" ;
gotoxy(5,5) ;
cout <<"Enter code of the Cassette or <ENTER> for help " ;
gets(t1) ;
t2 = atoi(t1) ;
cascode = t2 ;
if (cascode == 0 && strlen(t1) != 0)
return ;
if (strlen(t1) == 0)
DISPLAY_LIST(filename) ;
} while (strlen(t1) == 0) ;
if (!FOUND_CODE(filename,cascode))
{
valid = 0 ;
gotoxy(5,20) ;
cout <<"\7Cassette code not found." ;
getch() ;
}
} while (!valid) ;
clrscr() ;
gotoxy(72,1) ;
cout <<"<0>=EXIT" ;
DISPLAY_RECORD(filename,cascode) ;
do
{
gotoxy(5,12) ; clreol() ;
cout <<"Modify Cassette Name (y/n) " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'N')
return ;
char casname[36] ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER NAME OF THE CASSETTE" ;
gotoxy(5,15) ; clreol() ;
cout <<"Name : " ;
gets(casname) ;
if (casname[0] == '0')
return ;
if (strlen(casname) < 1 || strlen(casname) > 35)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7Enter Correctly (Range: 1..35)" ;
getch() ;
}
} while (!valid) ;
gotoxy(5,25) ; clreol() ;
do
{
gotoxy(5,17) ; clreol() ;
cout <<"Do you want to save (y/n) " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'N')
return ;
int recno ;
recno = RECORDNO(filename,cascode) ;
fstream file ;
file.open(filename, ios::out | ios::ate) ;
strcpy(name,casname) ;
int location ;
location = (recno-1) * sizeof(CASSETTE) ;
file.seekp(location) ;
file.write((char *) this, sizeof(CASSETTE)) ;
file.close() ;
gotoxy(5,20) ;
cout <<"\7Record Modified" ;
gotoxy(5,25) ;
cout <<"Press any key to continue..." ;
getch() ;
}
//**********************************************************
// THIS FUNCTION GIVES CODE TO DELETE THE CASSETTE RECORD
//**********************************************************
void CASSETTE :: DELETION(void)
{
MENU menu ;
char t1[10], ch, filename[13] ;
int t2, cascode, valid ;
strcpy(filename,menu.CHOICE_MENU()) ;
if (!strcmpi(filename,"FAILED"))
return ;
do
{
valid = 1 ;
do
{
clrscr() ;
gotoxy(72,2) ;
cout <<"<0>=EXIT" ;
gotoxy(5,5) ;
cout <<"Enter code of the Cassette or <ENTER> for help " ;
gets(t1) ;
t2 = atoi(t1) ;
cascode = t2 ;
if (cascode == 0 && strlen(t1) != 0)
return ;
if (strlen(t1) == 0)
DISPLAY_LIST(filename) ;
} while (strlen(t1) == 0) ;
if (!FOUND_CODE(filename,cascode))
{
valid = 0 ;
gotoxy(5,20) ;
cout <<"\7Cassette code not found." ;
getch() ;
}
} while (!valid) ;
clrscr() ;
gotoxy(72,1) ;
cout <<"<0>=EXIT" ;
DISPLAY_RECORD(filename,cascode) ;
int nik;
nik=ISSUED(filename,cascode);
if(nik!=1)
{ do
{
gotoxy(5,12) ; clreol() ;
cout <<"Delete this Cassette Record (y/n) " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'N')
return ;
DELETE_RECORD(filename,cascode) ;
gotoxy(5,20) ;
cout <<"\7Record Deleted" ;
gotoxy(5,25) ;
cout <<"Press any key to continue..." ;
getch() ;}
else
{gotoxy(5,12);
cout<<"The Record Is Issued CONNOT Be Deleted"<<endl;
gotoxy(5,25) ;
cout <<"Press any key to continue..." ;
getch() ;}
}
//**********************************************************
// THIS FUNCTION RETURNS THE LAST CUSTOMER'S CODE
//**********************************************************
int CUSTOMER :: LASTCODE(void)
{
fstream file ;
file.open("CUSTOMER.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int count=0 ;
while (file.read((char *) this, sizeof(CUSTOMER)))
count = code ;
file.close() ;
return count ;
}
//**********************************************************
// THIS FUNCTION RETURNS 0 IF THE GIVEN CODE NOT FOUND
//**********************************************************
int CUSTOMER :: FOUND_CODE(int custcode)
{
fstream file ;
file.open("CUSTOMER.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *) this, sizeof(CUSTOMER)))
{
if (code == custcode)
{
found = 1 ;
break ;
}
}
file.close() ;
return found ;
}
//**********************************************************
// THIS FUNCTION RETURNS NAME OF THE CUSTOMER FOR THE GIVEN
// CODE
//**********************************************************
char *CUSTOMER :: CUSTNAME(int custcode)
{
fstream file ;
file.open("CUSTOMER.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
char custname[26] ;
while (file.read((char *) this, sizeof(CUSTOMER)))
{
if (code == custcode)
{
strcpy(custname,name) ;
break ;
}
}
file.close() ;
return custname ;
}
//**********************************************************
// THIS FUNCTION DISPLAYS THE LIST OF THE CUSTOMER
//**********************************************************
void CUSTOMER :: LIST(void)
{
int row = 6 , found=0, flag=0 ;
char ch ;
gotoxy(31,2) ;
cout <<"LIST OF CUSTOMERS" ;
gotoxy(30,3) ;
cout <<"~~~~~~~~~~~~~~~~~~~" ;
gotoxy(3,4) ;
cout <<"CODE NAME PHONE" ;
gotoxy(1,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
fstream file ;
file.open("CUSTOMER.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(CUSTOMER)))
{
flag = 0 ;
delay(20) ;
found = 1 ;
gotoxy(4,row) ;
cout <<code ;
gotoxy(10,row) ;
cout <<name ;
gotoxy(57,row) ;
cout <<phone ;
if ( row == 23 )
{
flag = 1 ;
row = 6 ;
gotoxy(1,25) ;
cout <<"Press any key to continue or Press <ESC> to exit" ;
ch = getch() ;
if (ch == 27)
break ;
clrscr() ;
gotoxy(31,2) ;
cout <<"LIST OF CUSTOMERS" ;
gotoxy(30,3) ;
cout <<"~~~~~~~~~~~~~~~~~~~" ;
gotoxy(3,4) ;
cout <<"CODE NAME PHONE" ;
gotoxy(1,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
}
else
row++ ;
}
if (!found)
{
gotoxy(5,10) ;
cout <<"\7Records not found" ;
}
if (!flag)
{
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
}
file.close () ;
}
//**********************************************************
// THIS FUNCTION DISPLAYS THE RECORD OF CUSTOMER FOR THE
// GIVEN CODE
//**********************************************************
void CUSTOMER :: DISPLAY_RECORD(int ccode)
{
CASSETTE cas ;
fstream file ;
file.open("CUSTOMER.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(CUSTOMER)))
{
if (code == ccode)
{
gotoxy(5,4) ;
cout <<"Customer Code # " <<code ;
gotoxy(5,6) ;
cout <<"Customer Name : " <<name ;
gotoxy(5,7) ;
cout <<"Customer Phone : " <<phone ;
gotoxy(5,9) ;
cout <<"Cassette Issued : " <<cas.CASNAME(fname,cassette) ;
gotoxy(5,10) ;
cout <<"Date of Return : " <<dd <<"/" <<mm <<"/" <<yy ;
break ;
}
}
file.close() ;
}
//**********************************************************
// THIS FUNCTION GIVES CODE TO DISPLAYS THE RECORD OF
// CUSTOMER
//**********************************************************
void CUSTOMER :: DISPLAY(void)
{
char t1[10] ;
int t2, custcode ;
gotoxy(72,2) ;
cout <<"<0>=EXIT" ;
gotoxy(5,5) ;
cout <<"Enter code of the Customer " ;
gets(t1) ;
t2 = atoi(t1) ;
custcode = t2 ;
if (custcode == 0)
return ;
clrscr() ;
if (!FOUND_CODE(custcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
LINES line ;
line.BOX(2,1,79,25,218) ;
DISPLAY_RECORD(custcode) ;
gotoxy(5,24) ;
cout <<"Press any key to continue..." ;
getch() ;
}
//**********************************************************
// THIS FUNCTION DELETES THE RECORD OF THE GIVEN CODE.
//**********************************************************
void CUSTOMER :: DELETE_RECORD(int ccode)
{
CASSETTE cas ;
fstream file ;
file.open("CUSTOMER.DAT", ios::in) ;
fstream temp ;
temp.open("temp.dat", ios::out) ;
file.seekg(0,ios::beg) ;
while ( !file.eof() )
{
file.read((char *) this, sizeof(CUSTOMER)) ;
if ( file.eof() )
break ;
if ( code != ccode )
temp.write((char *) this, sizeof(CUSTOMER)) ;
else
cas.UPDATE(fname,cassette,0,'A') ;
}
file.close() ;
temp.close() ;
file.open("CUSTOMER.DAT", ios::out) ;
temp.open("temp.dat", ios::in) ;
temp.seekg(0,ios::beg) ;
while ( !temp.eof() )
{
temp.read((char *) this, sizeof(CUSTOMER)) ;
if ( temp.eof() )
break ;
file.write((char *) this, sizeof(CUSTOMER)) ;
}
file.close() ;
temp.close() ;
}
//**********************************************************
// THIS FUNCTION ADDS THE GIVEN DATA IN THE CUSTOMER'S FILE
//**********************************************************
void CUSTOMER :: ADD_RECORD(int custcode, char custname[26], char custphone[10], char filename[13], int cascode, int d, int m, int y)
{
fstream file ;
file.open("CUSTOMER.DAT", ios::app) ;
code = custcode ;
strcpy(name,custname) ;
strcpy(phone,custphone) ;
strcpy(fname,filename) ;
cassette = cascode ;
dd = d ;
mm = m ;
yy = y ;
file.write((char *) this, sizeof(CUSTOMER)) ;
file.close() ;
}
//**********************************************************
// THIS FUNCTION CALCULATE AND RETURN FINE FOR THE GIVEN
// CUSTOMER CODE.
//**********************************************************
int CUSTOMER :: FINE(int ccode)
{
ISSUE_RETURN ir ;
int d1, m1, y1 ;
struct date d;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
fstream file ;
file.open("CUSTOMER.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int days, t_fine ;
while (file.read((char *) this, sizeof(CUSTOMER)))
{
if (code == ccode)
{
days = ir.DIFF(dd,mm,yy,d1,m1,y1) ;
t_fine = days * 20 ;
break ;
}
}
file.close() ;
return t_fine ;
}
//**********************************************************
// FUNCTION TO EXTEND GIVEN DATE BY 5 DAYS
//**********************************************************
void ISSUE_RETURN :: EXTEND_DATE(int d1, int m1, int y1, int days)
{
static int month[] = {31,29,31,30,31,30,31,31,30,31,30,31} ;
for (int i=1; i<=days; i++)
{
d1++ ;
if ((d1 > month[m1-1]) || (y1%4 != 0 && m1 == 2 && d1 > 28))
{
d1 = 1 ;
m1++ ;
}
if (m1 > 12)
{
m1 = 1 ;
y1++ ;
}
}
day = d1 ;
mon = m1 ;
year = y1 ;
}
//**********************************************************
// THIS FUNCTION RETURN THE DIFFERENCE BETWEEN TWO GIVEN
// DATES
//**********************************************************
int ISSUE_RETURN :: DIFF(int d1, int m1, int y1, int d2, int m2, int y2)
{
int days = 0 ;
if ((y2<y1) || (y2==y1 && m2<m1) || (y2==y1 && m2==m1 && d2<d1))
return days ;
static int month[] = {31,29,31,30,31,30,31,31,30,31,30,31} ;
while (d1 != d2 || m1 != m2 || y1 != y2)
{
days++ ;
d1++ ;
if ((d1 > month[m1-1]) || (y1%4 != 0 && m1 == 2 && d1 > 28))
{
d1 = 1 ;
m1++ ;
}
if (m1 > 12)
{
m1 = 1 ;
y1++ ;
}
}
return days ;
}
//**********************************************************
// THIS FUNCTION ISSUE CASSETTE TO THE CUSTOMER & GIVE DATA
// TO ADD RECORD IN CUSTOMER'S FILE
//**********************************************************
void ISSUE_RETURN :: ISSUE(void)
{
MENU menu ;
CUSTOMER cust ;
CASSETTE cas ;
char filename[13] ;
strcpy(filename,menu.CHOICE_MENU()) ;
if (!strcmpi(filename,"FAILED"))
return ;
char t1[10] ;
int t2, cascode, valid ;
do
{
valid = 1 ;
do
{
clrscr() ;
gotoxy(72,2) ;
cout <<"<0>=EXIT" ;
gotoxy(5,5) ;
cout <<"Enter code of the Cassette or <ENTER> for help " ;
gets(t1) ;
t2 = atoi(t1) ;
cascode = t2 ;
if (cascode == 0 && strlen(t1) != 0)
return ;
if (strlen(t1) == 0)
DISPLAY_LIST(filename) ;
} while (strlen(t1) == 0) ;
if (!CASSETTE::FOUND_CODE(filename,cascode))
{
valid = 0 ;
gotoxy(5,20) ;
cout <<"\7Cassette code not found. Kindly choose another." ;
getch() ;
}
if (valid && ISSUED(filename,cascode))
{
valid = 0 ;
gotoxy(5,20) ;
cout <<"\7Cassette already issued. Kindly choose another." ;
getch() ;
}
} while (!valid) ;
clrscr() ;
int ccode ;
ccode = CUSTOMER::LASTCODE() + 1 ;
char custname[26], custphone[10] ;
int d1, m1, y1 ;
struct date d;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
gotoxy(5,2) ;
cout <<"Date: " <<d1 <<"/" <<m1 <<"/" <<y1 ;
gotoxy(72,2) ;
cout <<"<0>=EXIT" ;
CASSETTE::DISPLAY_RECORD(filename,cascode) ;
gotoxy(5,10) ;
cout <<"Customer Code # " <<ccode ;
gotoxy(5,12) ;
cout <<"Name : " ;
gotoxy(5,13) ;
cout <<"Phone : " ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"Enter the name of the Customer" ;
gotoxy(14,12) ; clreol() ;
gets(custname) ;
strupr(custname) ;
if (custname[0] == '0')
return ;
if (strlen(custname) < 1 || strlen(custname) > 25)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7Enter correctly (Range: 1..25)" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"Enter Phone no. of the Customer" ;
gotoxy(14,13) ; clreol() ;
gets(custphone) ;
if (custphone[0] == '0')
return ;
if ((strlen(custphone) < 7 && strlen(custphone) > 0) || (strlen(custphone) > 11))
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7Enter correctly" ;
getch() ;
}
} while (!valid) ;
gotoxy(5,25) ; clreol() ;
UPDATE(filename,cascode,ccode,'N') ;
EXTEND_DATE(d1,m1,y1,5) ;
d1 = day ;
m1 = mon ;
y1 = year ;
CUSTOMER::ADD_RECORD(ccode,custname,custphone,filename,cascode,d1,m1,y1) ;
gotoxy(5,17) ;
cout <<"\7CASSETTE ISSUED" ;
gotoxy(5,19) ;
cout <<"Date of Return : " <<d1 <<"/" <<m1 <<"/" <<y1 ;
gotoxy(5,25) ;
cout <<"Press any key to continue..." ;
getch() ;
}
//**********************************************************
// THIS FUNCTION RETURN CASSETTE FROM THE CUSTOMER
//**********************************************************
void ISSUE_RETURN :: RETURN(void)
{
CUSTOMER cust ;
char t1[10], ch ;
int t2, ccode, valid ;
do
{
valid = 1 ;
do
{
clrscr() ;
gotoxy(72,2) ;
cout <<"<0>=EXIT" ;
gotoxy(5,5) ;
cout <<"Enter code of the Customer or <ENTER> for help " ;
gets(t1) ;
t2 = atoi(t1) ;
ccode = t2 ;
if (ccode == 0 && strlen(t1) != 0)
return ;
if (strlen(t1) == 0)
cust.LIST() ;
} while (strlen(t1) == 0) ;
if (!CUSTOMER::FOUND_CODE(ccode))
{
valid = 0 ;
gotoxy(5,20) ;
cout <<"\7Customer code not found." ;
getch() ;
}
} while (!valid) ;
clrscr() ;
CUSTOMER::DISPLAY_RECORD(ccode) ;
int d1, m1, y1 ;
struct date d;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
gotoxy(5,2) ;
cout <<"Date: " <<d1 <<"/" <<m1 <<"/" <<y1 ;
do
{
gotoxy(5,13) ; clreol() ;
cout <<"Return Cassette (y/n) " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'N')
return ;
int f=FINE(ccode) ;
if (f != 0)
{
gotoxy(5,16) ;
cout <<"You have to pay a fine of Rs." <<f ;
gotoxy(5,17) ;
cout <<"Please do not delay the Return of Cassette again" ;
}
CUSTOMER::DELETE_RECORD(ccode) ;
gotoxy(5,20) ;
cout <<"\7Cassette Returned" ;
gotoxy(5,25) ;
cout <<"Press any key to continue..." ;
getch() ;
}
//**********************************************************
// MAIN FUNCTION CALLING MAIN MENU
//**********************************************************
void main(void)
{
MENU menu;
menu.introduction();
menu.MAIN_MENU();
}
Web Search
Custom Search
Search Results
Thursday, June 19, 2008
Wednesday, June 18, 2008
!!!... Sales Management System ...!!!
This the Sales management Project made bt my friend niket anand http://www.orkut.co.in/Profile.aspx?uid=3779819302486299046. This when runned gives four options
1. List of Products which shows the products n price.
2. Edit Product file to edit the products n their prices.
3. Purchase Products by selecting fr the list.
4. Bill Report.
A very nicely made project.
//**********************************************************
// PROJECT SALES MANAGEMENT
//**********************************************************
//**********************************************************
// INCLUDED HEADER FILES
//**********************************************************
#include <iostream.h>
#include <fstream.h>
#include <process.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
//**********************************************************
// CLASS NAME : Menu
// DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS
//**********************************************************
class menu
{
public :
void main_menu(void) ;
private :
void edit_menu(void) ;
} ;
//**********************************************************
// CLASS NAME : Product
// DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS
// RELATED TO PRODUCT ITEMS
//**********************************************************
class product
{
public :
void add_item(void) ;
void delete_item(void) ;
void modify_item(void) ;
void list_of_item(void) ;
void purchase(void) ;
private :
int last_code(void) ;
void delete_record(int) ;
void modify_record(int) ;
void display_record(int) ;
int item_found(int) ;
int recordno(int) ;
void sort(void) ;
int itemcode ;
char itemname[30] ;
float itemcost, itemprice ;
} ;
//**********************************************************
// CLASS NAME : Account
// DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS
// RELATED TO MAKING BILL
//**********************************************************
class account
{
public :
void bill_list(void) ;
void prepare_bill(int) ;
int last_billno(void) ;
void add_bill(int, int t_itemcode, char *t_itemname, float t_qty,
float t_cost, float t_price) ;
private :
int code, billno, length ;
int dd, mm, yy ;
float cost, price, quantity ;
char name[30] ;
} ;
//**********************************************************
// THIS FUNCTION CREATE MAIN MENU AND CALLS OTHER FUNCTIONS
//**********************************************************
void menu :: main_menu(void)
{
clrscr() ;
char ch ;
while (1)
{
clrscr() ;
gotoxy(10,3) ;
cout
<<"*************************************************************" ;
gotoxy(10,23) ;
cout
<<"*************************************************************" ;
gotoxy(28,6) ;
cout <<"S A L E S M A N A G E M E N T" ;
gotoxy(28,7) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(30,9) ;
cout <<"1: PURCHASE PRODUCTS" ;
gotoxy(30,11) ;
cout <<"2: LIST OF PRODUCTS" ;
gotoxy(30,13) ;
cout <<"3: EDIT PRODUCTS FILE" ;
gotoxy(30,15) ;
cout <<"4: BILLS REPORT" ;
gotoxy(30,17) ;
cout <<"0: QUIT" ;
gotoxy(30,20) ;
cout <<"Enter Your Choice : " ;
ch = getche() ;
if (ch == '1')
{
product p ;
p.purchase() ;
}
else
if (ch == '2')
{
product p ;
p.list_of_item() ;
}
else
if (ch == '3')
edit_menu() ;
else
if (ch == '4')
{
account a ;
a.bill_list();
}
else
if (ch == '0')
break ;
}
}
//**********************************************************
// THIS FUNCTION CREATE EDIT MENU AND CALLS OTHER FUNCTIONS
//**********************************************************
void menu :: edit_menu(void)
{
char ch ;
while (1)
{
clrscr() ;
gotoxy(10,3) ;
cout
<<"*************************************************************" ;
gotoxy(10,23) ;
cout
<<"*************************************************************" ;
gotoxy(32,6) ;
cout <<"E D I T M E N U" ;
gotoxy(32,7) ;
cout <<"~~~~~~~~~~~~~~~~" ;
gotoxy(32,10) ;
cout <<"1: ADD PRODUCTS" ;
gotoxy(32,12) ;
cout <<"2: MODIFY PRODUCTS" ;
gotoxy(32,14) ;
cout <<"3: DELETE PRODUCTS" ;
gotoxy(32,16) ;
cout <<"0: EXIT" ;
gotoxy(32,19) ;
cout <<"Enter Choice : " ;
ch = getche() ;
if (ch == '1')
{
product p ;
p.add_item() ;
break ;
}
else
if (ch == '2')
{
product p ;
p.modify_item() ;
break ;
}
else
if (ch == '3')
{
product p ;
p.delete_item() ;
break ;
}
else
if (ch == '0')
break ;
}
}
//**********************************************************
// THIS FUNCTION RETURNS THE CODE OF THE LAST RECORD IN THE
// PRODUCT FILE (PRODUCT.DAT).
//**********************************************************
int product :: last_code(void)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int t=0 ;
while (file.read((char *) this, sizeof(product)))
t = itemcode ;
file.close() ;
return t ;
}
//**********************************************************
// THIS FUNCTION DISPLAY THE LIST OF THE ITEMS
//**********************************************************
void product :: list_of_item(void)
{
clrscr() ;
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0) ;
int row = 6 , found = 0 ;
gotoxy(30,2) ;
cout <<"LIST OF ITEMS" ;
gotoxy(3,4) ;
cout <<"ITEM CODE ITEM NAME ITEM COST ITEM PRICE" ;
gotoxy(2,5) ;
cout <<"***********************************************************" ;
while (file.read((char *) this, sizeof(product)))
{
delay(20) ;
found = 1 ;
gotoxy(5,row) ;
cout <<itemcode ;
gotoxy(14,row) ;
cout <<itemname ;
gotoxy(37,row) ;
cout <<itemcost ;
gotoxy(51,row) ;
cout <<itemprice ;
if ( row == 22 )
{
row = 5 ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
clrscr() ;
gotoxy(30,2) ;
cout <<"LIST OF ITEMS" ;
gotoxy(3,4) ;
cout <<"ITEM CODE ITEM NAME ITEM COST ITEM PRICE" ;
gotoxy(2,5) ;
cout <<"***********************************************************"
;
}
else
row++ ;
}
if ( !found )
{
gotoxy(5,10) ;
cout <<"\7Records not found" ;
}
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
file.close () ;
}
//***********************************************************
// THIS FUNCTION ADD RECORDS IN THE PRODUCT.DAT (PRODUCT.DAT)
//***********************************************************
void product :: add_item(void)
{
int tcode, valid ;
char ch, t_itemcost[10], t_itemprice[10] ;
tcode = last_code() ;
tcode++ ;
do
{
clrscr() ;
gotoxy(71,2) ;
cout <<"<0>=Exit" ;
gotoxy(27,3) ;
cout <<"ADDITION OF PRODUCTS" ;
gotoxy(26,4) ;
cout <<"********************" ;
gotoxy(5,6) ;
cout <<"Item Code : " <<tcode ;
gotoxy(5,8) ;
cout <<"Item Name : " ;
gotoxy(5,10) ;
cout <<"Item Cost : " ;
gotoxy(5,12) ;
cout <<"Item Price : " ;
do
{
valid = 1 ;
gotoxy(1,8) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM NAME TO ADD IN THE MENU" ;
gotoxy(5,8) ;
cout <<"Item Name : " ;
gets(itemname) ;
strupr(itemname) ;
if (itemname[0] == '0')
return ;
if ((strlen(itemname) < 1) || (strlen(itemname) > 20))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..20" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1 ;
gotoxy(1,10) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM COST TO ADD IN THE MENU" ;
gotoxy(5,10) ;
cout <<"Item Cost : " ;
gets(t_itemcost) ;
itemcost = atof(t_itemcost) ;
if (t_itemcost[0] == '0')
return ;
if (itemcost < 1 || itemcost > 800)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..800" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1 ;
gotoxy(1,12) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM PRICE TO ADD IN THE MENU" ;
gotoxy(5,12) ;
cout <<"Item Price : " ;
gets(t_itemprice) ;
itemprice = atof(t_itemprice) ;
if (t_itemprice[0] == '0')
return ;
if (itemprice < itemcost || itemprice > 1000)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = " <<itemcost <<"..1000" ;
getch() ;
}
} while (!valid) ;
do
{
gotoxy(1,15) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,15) ;
cout <<"Do you want to save this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'Y')
{
itemcode = tcode ;
fstream file ;
file.open("PRODUCT.DAT", ios::out | ios::app ) ;
file.write((char *) this, sizeof(product)) ;
file.close() ;
tcode++ ;
}
do
{
gotoxy(1,17) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,17) ;
cout <<"Do you want to add more records (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
} while (ch == 'Y') ;
}
//**********************************************************
// THIS FUNCTION DISPLAY THE RECORD OF THE GIVEN CODE FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: display_record(int tcode)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(product)))
{
if (itemcode == tcode)
{
gotoxy(5,3) ;
cout <<"Item Code : "<<itemcode ;
gotoxy(5,4) ;
cout <<"Item Name : "<<itemname ;
gotoxy(5,5) ;
cout <<"Item Cost : "<<itemcost ;
gotoxy(5,6) ;
cout <<"Item Price : "<<itemprice ;
break ;
}
}
file.close() ;
}
//**********************************************************
// THIS FUNCTION RETURN THE VALUE 1 IF THE RECORD IS FOUND
// FOR THE GIVEN CODE IN THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
int product :: item_found(int tcode)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *) this, sizeof(product)))
{
if (itemcode == tcode)
{
found++ ;
break ;
}
}
file.close() ;
return found ;
}
//**********************************************************
// THIS FUNCTION RETURN THE RECORD NO. OF THE GIVEN CODE IN
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
int product :: recordno(int tcode)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *) this, sizeof(product)))
{
found++ ;
if (itemcode == tcode)
break ;
}
file.close() ;
return found ;
}
//**********************************************************
// THIS FUNCTION DELETES THE RECORD FOR THE GIVEN CODE FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: delete_record(int tcode)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
fstream temp ;
temp.open("temp.dat", ios::out) ;
file.seekg(0,ios::beg) ;
while ( !file.eof() )
{
file.read((char *) this, sizeof(product)) ;
if ( file.eof() )
break ;
if ( itemcode != tcode )
temp.write((char *) this, sizeof(product)) ;
}
file.close() ;
temp.close() ;
file.open("PRODUCT.DAT", ios::out) ;
temp.open("temp.dat", ios::in) ;
temp.seekg(0,ios::beg) ;
while ( !temp.eof() )
{
temp.read((char *) this, sizeof(product)) ;
if ( temp.eof() )
break ;
file.write((char *) this, sizeof(product)) ;
}
file.close() ;
temp.close() ;
}
//**********************************************************
// THIS FUNCTION GIVES THE CODE NO. TO DELETE RECORD FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: delete_item(void)
{
clrscr() ;
char t_code[5], ch ;
int t, tcode ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Item Code of the item to be deleted : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (t_code[0] == '0')
return ;
if (tcode == 0)
{
list_of_item() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Item Code of the item to be deleted : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (tcode == 0)
return ;
}
clrscr() ;
if (!item_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
display_record(tcode) ;
do
{
gotoxy(1,8) ; clreol() ;
gotoxy(5,8) ;
cout <<"Do you want to delete this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
delete_record(tcode) ;
gotoxy(5,15) ;
cout <<"\7Record Deleted" ;
getch() ;
}
//**********************************************************
// THIS FUNCTION MODIFY THE RECORD FOR THE GIVEN CODE FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: modify_record(int tcode)
{
int recno ;
recno = recordno(tcode) ;
int valid, t_code ;
char ch, t_itemcost[10], t_itemprice[10], t_itemcode[5] ;
gotoxy(71,2) ;
cout <<"<0>=Exit" ;
gotoxy(5,12) ;
cout <<"Item Code : " ;
gotoxy(5,14) ;
cout <<"Item Name : " ;
gotoxy(5,16) ;
cout <<"Item Cost : " ;
gotoxy(5,18) ;
cout <<"Item Price : " ;
do
{
gotoxy(20,12) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,12) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM CODE TO ADD IN THE MENU" ;
gotoxy(5,12) ;
cout <<"Item Code : " ;
gets(t_itemcode) ;
t_code = atoi(t_itemcode) ;
if (t_code == 0)
return ;
if (item_found(t_code) && t_code != tcode)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 CODE ALREADY GIVEN" ;
getch() ;
}
}
do
{
gotoxy(20,14) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,14) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM NAME TO ADD IN THE MENU" ;
gotoxy(5,14) ;
cout <<"Item Name : " ;
gets(itemname) ;
strupr(itemname) ;
if (itemname[0] == '0')
return ;
if ((strlen(itemname) < 1) || (strlen(itemname) > 20))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..20" ;
getch() ;
}
}
do
{
gotoxy(20,16) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,16) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM COST TO ADD IN THE MENU" ;
gotoxy(5,16) ;
cout <<"Item Cost : " ;
gets(t_itemcost) ;
itemcost = atof(t_itemcost) ;
if (t_itemcost[0] == '0')
return ;
if (itemcost < 1 || itemcost > 800)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..800" ;
getch() ;
}
}
do
{
gotoxy(20,18) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,18) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM PRICE TO ADD IN THE MENU" ;
gotoxy(5,18) ;
cout <<"Item Price : " ;
gets(t_itemprice) ;
itemprice = atof(t_itemprice) ;
if (t_itemprice[0] == '0')
return ;
if (itemprice < itemcost || itemprice > 1000)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = " <<itemcost <<"..1000" ;
getch() ;
}
}
do
{
gotoxy(1,21) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,21) ;
cout <<"Do you want to save this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
itemcode = t_code ;
cout <<"\n" <<itemname ;
cout <<itemcost ;
cout <<itemprice ;
getch() ;
fstream file ;
file.open("PRODUCT.DAT", ios::out | ios::ate) ;
int location ;
location = (recno-1) * sizeof(product) ;
file.seekp(location) ;
file.write((char *) this, sizeof(product)) ;
file.close() ;
sort() ;
clrscr() ;
gotoxy(5,15) ;
cout <<"\7Record Modified" ;
getch() ;
}
//**********************************************************
// THIS FUNCTION GIVES THE CODE NO. TO MODIFY RECORD FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: modify_item(void)
{
clrscr() ;
char t_code[5], ch ;
int t, tcode ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Item Code of the item to be Modify : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (t_code[0] == '0')
return ;
if (tcode == 0)
{
list_of_item() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Item Code of the item to be modify : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (tcode == 0)
return ;
}
clrscr() ;
if (!item_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
display_record(tcode) ;
do
{
gotoxy(5,8) ;
cout <<"Do you want to Modify this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
modify_record(tcode) ;
}
//****************************************************************
// THIS FUNCTION SORT THE RECORD IN THE PRODUCT FILE (PRODUCT.DAT)
// ACCORDING TO THE CODE NOS.
//****************************************************************
void product :: sort(void)
{
int i=0,j ;
product arr[100] ;
product temp ;
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) &arr[i], sizeof(product)))
i++ ;
int size ;
size = i ;
file.close() ;
for (i=1; i<size; i++)
for (j=0; j<size-i; j++)
{
if (arr[j].itemcode > arr[j+1].itemcode)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
file.open("PRODUCT.DAT", ios::out) ;
for (i=0; i<size; i++)
file.write((char *) &arr[i], sizeof(product)) ;
file.close() ;
}
//**********************************************************
// THIS FUNCTION PURCHASES THE PRODUCT ITEM IN THE MENU
//**********************************************************
void product :: purchase(void)
{
clrscr() ;
account a ;
int t_billno, purchased=0 ;
t_billno = a.last_billno() ;
t_billno++ ;
char t_code[5], ch;
float t_quantity ;
int t, tcode, i=0, valid ;
float qty ;
int t_itemcode ;
float t_qty, t_cost, t_price ;
char t_itemname[30] ;
struct date d;
int d1, m1, y1 ;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
do
{
clrscr() ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Item Code of the item to be Purchase : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (t_code[0] == '0')
{
if (purchased)
a.prepare_bill(t_billno) ;
return ;
}
if (tcode == 0)
{
list_of_item() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Item Code of the item to be Purchase : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (tcode == 0)
{
if (purchased)
a.prepare_bill(t_billno) ;
return ;
}
}
clrscr() ;
if (!item_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Item Code not found" ;
getch() ;
if (purchased)
a.prepare_bill(t_billno) ;
return ;
}
gotoxy(60,2) ;
cout <<"Date:" <<d1 <<"/" <<m1 <<"/" <<y1 ;
display_record(tcode) ;
do
{
valid = 1 ;
gotoxy(1,8) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER QUANTITY TO BE PURCHASE IN Kg." ;
gotoxy(5,8) ;
cout <<"Quantity : " ;
cin>>t_quantity ;
qty=t_quantity ;
if (t_quantity == 0)
{
if (purchased)
a.prepare_bill(t_billno) ;
return ;
}
if (qty < 1 || qty > 800)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..800" ;
getch() ;
}
} while (!valid) ;
do
{
gotoxy(5,10) ; clreol() ;
gotoxy(5,10) ;
cout <<"Do you want to cancel this purchase (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
{
purchased = 1 ;
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(product)))
{
if (itemcode == tcode)
{
t_itemcode = itemcode ;
strcpy(t_itemname,itemname) ;
t_cost = itemcost ;
t_price = itemprice ;
t_qty = qty ;
a.add_bill(t_billno,t_itemcode,t_itemname,t_qty,t_cost,t_price) ;
i++ ;
break ;
}
}
file.close() ;
}
do
{
gotoxy(5,12) ; clreol() ;
gotoxy(5,12) ;
cout <<"Do you want to purchase more (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
} while (ch == 'Y') ;
a.prepare_bill(t_billno) ;
}
//**********************************************************
// THIS FUNCTION RETURNS THE BILL NO. OF THE LAST RECORD
// IN THE BILL FILE (BILL.DAT)
//**********************************************************
int account :: last_billno(void)
{
fstream file ;
file.open("BILL.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int t=0 ;
while (file.read((char *) this, sizeof(account)))
t = billno ;
file.close() ;
return t ;
}
//**********************************************************
// THIS FUNCTION ADDS THE RECORD IN THE BILL FILE (BILL.DAT)
//**********************************************************
void account :: add_bill(int t_billno, int t_itemcode, char
t_itemname[30], float t_qty, float t_cost, float t_price)
{
struct date d;
int d1, m1, y1 ;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
dd = d1 ;
mm = m1 ;
yy = y1 ;
code = t_itemcode ;
strcpy(name,t_itemname) ;
cost = t_cost ;
price = t_price ;
quantity = t_qty ;
billno = t_billno ;
fstream file ;
file.open("BILL.DAT", ios::out | ios:: app ) ;
file.write((char *) this, sizeof(account)) ;
file.close() ;
}
//**********************************************************
// THIS FUNCTION PREPARES AND DISPLAYS THE BILL FOR THE
// GIVEN BILL NO. ACCORDING TO PURCHASES MADE.
//**********************************************************
void account :: prepare_bill(int t_billno)
{
clrscr() ;
struct date d;
int d1, m1, y1 ;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
float total=0.0, total_bill=0.0 ;
gotoxy(33,3) ;
cout <<"CUSTOMER BILL" ;
gotoxy(55,5) ;
cout <<"Date:" <<d1 <<"/" <<m1 <<"/" <<y1 ;
gotoxy(8,7) ;
cout <<"ITEMS PURCHASED" ;
gotoxy(8,8) ;
cout <<"+++++++++++++++" ;
gotoxy(8,9) ;
cout <<"Item code Item name Cost Price Qty Total"
;
gotoxy(8,10) ;
cout <<"------------------------------------------------------------"
;
int row=11 ;
fstream file ;
file.open("BILL.DAT", ios::in) ;
file.seekg(0) ;
while (file.read((char *) this, sizeof(account)) !=0 )
{
if (billno == t_billno)
{
gotoxy(8,5) ;
cout <<"BILL NO. # " <<billno ;
gotoxy(8,6) ;
cout <<"===============" ;
gotoxy(10,row) ;
cout <<code ;
gotoxy(18,row) ;
cout <<name ;
gotoxy(39,row) ;
cout <<cost ;
gotoxy(47,row) ;
cout <<price ;
gotoxy(56,row) ;
cout <<quantity ;
total = quantity * price ;
gotoxy(63,row) ;
cout <<total ;
total_bill = total_bill + total ;
row++ ;
}
}
file.close() ;
gotoxy(39,row+1) ;
cout <<"TOTAL BILL: Rs." <<total_bill <<" /=" ;
getch() ;
}
//**********************************************************
// THIS FUNCTION DISPLAYS THE LIST OF THE BILLS
//**********************************************************
void account :: bill_list(void)
{
clrscr() ;
fstream file ;
file.open("BILL.DAT", ios::in) ;
file.seekg(0) ;
int row=5, found=0, pageno=1, prev_billno=0, flag=0 ;
float total=0.0, total_bill=0.0 ;
gotoxy(30,2) ;
cout <<"LIST OF BILLS" ;
gotoxy(3,4) ;
cout <<"Billno. Date Item Code Item name Cost Pri Qty Total" ;
gotoxy(3,5) ;
cout
<<"===========================================================================" ;
while (file.read((char *) this, sizeof(account)))
{
row++ ;
delay(20) ;
found = 1 ;
if (prev_billno != billno)
{
if (flag)
{
gotoxy(52,row) ;
cout <<"TOTAL BILL: Rs." <<total_bill <<"/=" ;
total_bill = 0.0 ;
row++ ;
}
gotoxy(4,row) ;
cout <<billno ;
}
flag = 1 ;
gotoxy(11,row) ;
cout <<dd <<"/" <<mm <<"/" <<yy ;
gotoxy(24,row) ;
cout <<code ;
gotoxy(32,row) ;
cout <<name ;
gotoxy(52,row) ;
cout <<cost ;
gotoxy(59,row) ;
cout <<price ;
gotoxy(67,row) ;
cout <<quantity ;
total = quantity * price ;
gotoxy(73,row) ;
cout <<total ;
total_bill = total_bill + total ;
if ( row >= 23 )
{
row = 5 ;
gotoxy(66,1) ;
cout <<"Page no. : " <<pageno ;
pageno++ ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
clrscr() ;
gotoxy(30,2) ;
cout <<"LIST OF BILLS" ;
gotoxy(3,4) ;
cout <<"Billno. Date Item Code Item name CostPrice Qty Total" ;
gotoxy(3,5) ;
cout
<<"===========================================================================" ;
}
prev_billno = billno ;
}
row++ ;
gotoxy(52,row) ;
cout <<"TOTAL BILL: Rs." <<total_bill <<"/=" ;
if ( !found )
{
gotoxy(5,10) ;
cout <<"\7Records not found" ;
}
gotoxy(66,1) ;
cout <<"Page no. : " <<pageno ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
file.close () ;
}
//**********************************************************
// THIS FUNCTION IS THE MAIN FUNCTION CALLING THE MAIN MENU
//**********************************************************
void main(void)
{
clrscr() ;
menu m ;
m.main_menu() ;
}
1. List of Products which shows the products n price.
2. Edit Product file to edit the products n their prices.
3. Purchase Products by selecting fr the list.
4. Bill Report.
A very nicely made project.
//**********************************************************
// PROJECT SALES MANAGEMENT
//**********************************************************
//**********************************************************
// INCLUDED HEADER FILES
//**********************************************************
#include <iostream.h>
#include <fstream.h>
#include <process.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
//**********************************************************
// CLASS NAME : Menu
// DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS
//**********************************************************
class menu
{
public :
void main_menu(void) ;
private :
void edit_menu(void) ;
} ;
//**********************************************************
// CLASS NAME : Product
// DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS
// RELATED TO PRODUCT ITEMS
//**********************************************************
class product
{
public :
void add_item(void) ;
void delete_item(void) ;
void modify_item(void) ;
void list_of_item(void) ;
void purchase(void) ;
private :
int last_code(void) ;
void delete_record(int) ;
void modify_record(int) ;
void display_record(int) ;
int item_found(int) ;
int recordno(int) ;
void sort(void) ;
int itemcode ;
char itemname[30] ;
float itemcost, itemprice ;
} ;
//**********************************************************
// CLASS NAME : Account
// DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS
// RELATED TO MAKING BILL
//**********************************************************
class account
{
public :
void bill_list(void) ;
void prepare_bill(int) ;
int last_billno(void) ;
void add_bill(int, int t_itemcode, char *t_itemname, float t_qty,
float t_cost, float t_price) ;
private :
int code, billno, length ;
int dd, mm, yy ;
float cost, price, quantity ;
char name[30] ;
} ;
//**********************************************************
// THIS FUNCTION CREATE MAIN MENU AND CALLS OTHER FUNCTIONS
//**********************************************************
void menu :: main_menu(void)
{
clrscr() ;
char ch ;
while (1)
{
clrscr() ;
gotoxy(10,3) ;
cout
<<"*************************************************************" ;
gotoxy(10,23) ;
cout
<<"*************************************************************" ;
gotoxy(28,6) ;
cout <<"S A L E S M A N A G E M E N T" ;
gotoxy(28,7) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(30,9) ;
cout <<"1: PURCHASE PRODUCTS" ;
gotoxy(30,11) ;
cout <<"2: LIST OF PRODUCTS" ;
gotoxy(30,13) ;
cout <<"3: EDIT PRODUCTS FILE" ;
gotoxy(30,15) ;
cout <<"4: BILLS REPORT" ;
gotoxy(30,17) ;
cout <<"0: QUIT" ;
gotoxy(30,20) ;
cout <<"Enter Your Choice : " ;
ch = getche() ;
if (ch == '1')
{
product p ;
p.purchase() ;
}
else
if (ch == '2')
{
product p ;
p.list_of_item() ;
}
else
if (ch == '3')
edit_menu() ;
else
if (ch == '4')
{
account a ;
a.bill_list();
}
else
if (ch == '0')
break ;
}
}
//**********************************************************
// THIS FUNCTION CREATE EDIT MENU AND CALLS OTHER FUNCTIONS
//**********************************************************
void menu :: edit_menu(void)
{
char ch ;
while (1)
{
clrscr() ;
gotoxy(10,3) ;
cout
<<"*************************************************************" ;
gotoxy(10,23) ;
cout
<<"*************************************************************" ;
gotoxy(32,6) ;
cout <<"E D I T M E N U" ;
gotoxy(32,7) ;
cout <<"~~~~~~~~~~~~~~~~" ;
gotoxy(32,10) ;
cout <<"1: ADD PRODUCTS" ;
gotoxy(32,12) ;
cout <<"2: MODIFY PRODUCTS" ;
gotoxy(32,14) ;
cout <<"3: DELETE PRODUCTS" ;
gotoxy(32,16) ;
cout <<"0: EXIT" ;
gotoxy(32,19) ;
cout <<"Enter Choice : " ;
ch = getche() ;
if (ch == '1')
{
product p ;
p.add_item() ;
break ;
}
else
if (ch == '2')
{
product p ;
p.modify_item() ;
break ;
}
else
if (ch == '3')
{
product p ;
p.delete_item() ;
break ;
}
else
if (ch == '0')
break ;
}
}
//**********************************************************
// THIS FUNCTION RETURNS THE CODE OF THE LAST RECORD IN THE
// PRODUCT FILE (PRODUCT.DAT).
//**********************************************************
int product :: last_code(void)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int t=0 ;
while (file.read((char *) this, sizeof(product)))
t = itemcode ;
file.close() ;
return t ;
}
//**********************************************************
// THIS FUNCTION DISPLAY THE LIST OF THE ITEMS
//**********************************************************
void product :: list_of_item(void)
{
clrscr() ;
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0) ;
int row = 6 , found = 0 ;
gotoxy(30,2) ;
cout <<"LIST OF ITEMS" ;
gotoxy(3,4) ;
cout <<"ITEM CODE ITEM NAME ITEM COST ITEM PRICE" ;
gotoxy(2,5) ;
cout <<"***********************************************************" ;
while (file.read((char *) this, sizeof(product)))
{
delay(20) ;
found = 1 ;
gotoxy(5,row) ;
cout <<itemcode ;
gotoxy(14,row) ;
cout <<itemname ;
gotoxy(37,row) ;
cout <<itemcost ;
gotoxy(51,row) ;
cout <<itemprice ;
if ( row == 22 )
{
row = 5 ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
clrscr() ;
gotoxy(30,2) ;
cout <<"LIST OF ITEMS" ;
gotoxy(3,4) ;
cout <<"ITEM CODE ITEM NAME ITEM COST ITEM PRICE" ;
gotoxy(2,5) ;
cout <<"***********************************************************"
;
}
else
row++ ;
}
if ( !found )
{
gotoxy(5,10) ;
cout <<"\7Records not found" ;
}
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
file.close () ;
}
//***********************************************************
// THIS FUNCTION ADD RECORDS IN THE PRODUCT.DAT (PRODUCT.DAT)
//***********************************************************
void product :: add_item(void)
{
int tcode, valid ;
char ch, t_itemcost[10], t_itemprice[10] ;
tcode = last_code() ;
tcode++ ;
do
{
clrscr() ;
gotoxy(71,2) ;
cout <<"<0>=Exit" ;
gotoxy(27,3) ;
cout <<"ADDITION OF PRODUCTS" ;
gotoxy(26,4) ;
cout <<"********************" ;
gotoxy(5,6) ;
cout <<"Item Code : " <<tcode ;
gotoxy(5,8) ;
cout <<"Item Name : " ;
gotoxy(5,10) ;
cout <<"Item Cost : " ;
gotoxy(5,12) ;
cout <<"Item Price : " ;
do
{
valid = 1 ;
gotoxy(1,8) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM NAME TO ADD IN THE MENU" ;
gotoxy(5,8) ;
cout <<"Item Name : " ;
gets(itemname) ;
strupr(itemname) ;
if (itemname[0] == '0')
return ;
if ((strlen(itemname) < 1) || (strlen(itemname) > 20))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..20" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1 ;
gotoxy(1,10) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM COST TO ADD IN THE MENU" ;
gotoxy(5,10) ;
cout <<"Item Cost : " ;
gets(t_itemcost) ;
itemcost = atof(t_itemcost) ;
if (t_itemcost[0] == '0')
return ;
if (itemcost < 1 || itemcost > 800)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..800" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1 ;
gotoxy(1,12) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM PRICE TO ADD IN THE MENU" ;
gotoxy(5,12) ;
cout <<"Item Price : " ;
gets(t_itemprice) ;
itemprice = atof(t_itemprice) ;
if (t_itemprice[0] == '0')
return ;
if (itemprice < itemcost || itemprice > 1000)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = " <<itemcost <<"..1000" ;
getch() ;
}
} while (!valid) ;
do
{
gotoxy(1,15) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,15) ;
cout <<"Do you want to save this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'Y')
{
itemcode = tcode ;
fstream file ;
file.open("PRODUCT.DAT", ios::out | ios::app ) ;
file.write((char *) this, sizeof(product)) ;
file.close() ;
tcode++ ;
}
do
{
gotoxy(1,17) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,17) ;
cout <<"Do you want to add more records (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
} while (ch == 'Y') ;
}
//**********************************************************
// THIS FUNCTION DISPLAY THE RECORD OF THE GIVEN CODE FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: display_record(int tcode)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(product)))
{
if (itemcode == tcode)
{
gotoxy(5,3) ;
cout <<"Item Code : "<<itemcode ;
gotoxy(5,4) ;
cout <<"Item Name : "<<itemname ;
gotoxy(5,5) ;
cout <<"Item Cost : "<<itemcost ;
gotoxy(5,6) ;
cout <<"Item Price : "<<itemprice ;
break ;
}
}
file.close() ;
}
//**********************************************************
// THIS FUNCTION RETURN THE VALUE 1 IF THE RECORD IS FOUND
// FOR THE GIVEN CODE IN THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
int product :: item_found(int tcode)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *) this, sizeof(product)))
{
if (itemcode == tcode)
{
found++ ;
break ;
}
}
file.close() ;
return found ;
}
//**********************************************************
// THIS FUNCTION RETURN THE RECORD NO. OF THE GIVEN CODE IN
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
int product :: recordno(int tcode)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *) this, sizeof(product)))
{
found++ ;
if (itemcode == tcode)
break ;
}
file.close() ;
return found ;
}
//**********************************************************
// THIS FUNCTION DELETES THE RECORD FOR THE GIVEN CODE FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: delete_record(int tcode)
{
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
fstream temp ;
temp.open("temp.dat", ios::out) ;
file.seekg(0,ios::beg) ;
while ( !file.eof() )
{
file.read((char *) this, sizeof(product)) ;
if ( file.eof() )
break ;
if ( itemcode != tcode )
temp.write((char *) this, sizeof(product)) ;
}
file.close() ;
temp.close() ;
file.open("PRODUCT.DAT", ios::out) ;
temp.open("temp.dat", ios::in) ;
temp.seekg(0,ios::beg) ;
while ( !temp.eof() )
{
temp.read((char *) this, sizeof(product)) ;
if ( temp.eof() )
break ;
file.write((char *) this, sizeof(product)) ;
}
file.close() ;
temp.close() ;
}
//**********************************************************
// THIS FUNCTION GIVES THE CODE NO. TO DELETE RECORD FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: delete_item(void)
{
clrscr() ;
char t_code[5], ch ;
int t, tcode ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Item Code of the item to be deleted : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (t_code[0] == '0')
return ;
if (tcode == 0)
{
list_of_item() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Item Code of the item to be deleted : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (tcode == 0)
return ;
}
clrscr() ;
if (!item_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
display_record(tcode) ;
do
{
gotoxy(1,8) ; clreol() ;
gotoxy(5,8) ;
cout <<"Do you want to delete this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
delete_record(tcode) ;
gotoxy(5,15) ;
cout <<"\7Record Deleted" ;
getch() ;
}
//**********************************************************
// THIS FUNCTION MODIFY THE RECORD FOR THE GIVEN CODE FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: modify_record(int tcode)
{
int recno ;
recno = recordno(tcode) ;
int valid, t_code ;
char ch, t_itemcost[10], t_itemprice[10], t_itemcode[5] ;
gotoxy(71,2) ;
cout <<"<0>=Exit" ;
gotoxy(5,12) ;
cout <<"Item Code : " ;
gotoxy(5,14) ;
cout <<"Item Name : " ;
gotoxy(5,16) ;
cout <<"Item Cost : " ;
gotoxy(5,18) ;
cout <<"Item Price : " ;
do
{
gotoxy(20,12) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,12) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM CODE TO ADD IN THE MENU" ;
gotoxy(5,12) ;
cout <<"Item Code : " ;
gets(t_itemcode) ;
t_code = atoi(t_itemcode) ;
if (t_code == 0)
return ;
if (item_found(t_code) && t_code != tcode)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 CODE ALREADY GIVEN" ;
getch() ;
}
}
do
{
gotoxy(20,14) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,14) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM NAME TO ADD IN THE MENU" ;
gotoxy(5,14) ;
cout <<"Item Name : " ;
gets(itemname) ;
strupr(itemname) ;
if (itemname[0] == '0')
return ;
if ((strlen(itemname) < 1) || (strlen(itemname) > 20))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..20" ;
getch() ;
}
}
do
{
gotoxy(20,16) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,16) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM COST TO ADD IN THE MENU" ;
gotoxy(5,16) ;
cout <<"Item Cost : " ;
gets(t_itemcost) ;
itemcost = atof(t_itemcost) ;
if (t_itemcost[0] == '0')
return ;
if (itemcost < 1 || itemcost > 800)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..800" ;
getch() ;
}
}
do
{
gotoxy(20,18) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,18) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER ITEM PRICE TO ADD IN THE MENU" ;
gotoxy(5,18) ;
cout <<"Item Price : " ;
gets(t_itemprice) ;
itemprice = atof(t_itemprice) ;
if (t_itemprice[0] == '0')
return ;
if (itemprice < itemcost || itemprice > 1000)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = " <<itemcost <<"..1000" ;
getch() ;
}
}
do
{
gotoxy(1,21) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,21) ;
cout <<"Do you want to save this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
itemcode = t_code ;
cout <<"\n" <<itemname ;
cout <<itemcost ;
cout <<itemprice ;
getch() ;
fstream file ;
file.open("PRODUCT.DAT", ios::out | ios::ate) ;
int location ;
location = (recno-1) * sizeof(product) ;
file.seekp(location) ;
file.write((char *) this, sizeof(product)) ;
file.close() ;
sort() ;
clrscr() ;
gotoxy(5,15) ;
cout <<"\7Record Modified" ;
getch() ;
}
//**********************************************************
// THIS FUNCTION GIVES THE CODE NO. TO MODIFY RECORD FROM
// THE PRODUCT FILE (PRODUCT.DAT)
//**********************************************************
void product :: modify_item(void)
{
clrscr() ;
char t_code[5], ch ;
int t, tcode ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Item Code of the item to be Modify : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (t_code[0] == '0')
return ;
if (tcode == 0)
{
list_of_item() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Item Code of the item to be modify : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (tcode == 0)
return ;
}
clrscr() ;
if (!item_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
display_record(tcode) ;
do
{
gotoxy(5,8) ;
cout <<"Do you want to Modify this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
modify_record(tcode) ;
}
//****************************************************************
// THIS FUNCTION SORT THE RECORD IN THE PRODUCT FILE (PRODUCT.DAT)
// ACCORDING TO THE CODE NOS.
//****************************************************************
void product :: sort(void)
{
int i=0,j ;
product arr[100] ;
product temp ;
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) &arr[i], sizeof(product)))
i++ ;
int size ;
size = i ;
file.close() ;
for (i=1; i<size; i++)
for (j=0; j<size-i; j++)
{
if (arr[j].itemcode > arr[j+1].itemcode)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
file.open("PRODUCT.DAT", ios::out) ;
for (i=0; i<size; i++)
file.write((char *) &arr[i], sizeof(product)) ;
file.close() ;
}
//**********************************************************
// THIS FUNCTION PURCHASES THE PRODUCT ITEM IN THE MENU
//**********************************************************
void product :: purchase(void)
{
clrscr() ;
account a ;
int t_billno, purchased=0 ;
t_billno = a.last_billno() ;
t_billno++ ;
char t_code[5], ch;
float t_quantity ;
int t, tcode, i=0, valid ;
float qty ;
int t_itemcode ;
float t_qty, t_cost, t_price ;
char t_itemname[30] ;
struct date d;
int d1, m1, y1 ;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
do
{
clrscr() ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Item Code of the item to be Purchase : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (t_code[0] == '0')
{
if (purchased)
a.prepare_bill(t_billno) ;
return ;
}
if (tcode == 0)
{
list_of_item() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press <ENTER> to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Item Code of the item to be Purchase : " ;
gets(t_code) ;
t = atoi(t_code) ;
tcode = t ;
if (tcode == 0)
{
if (purchased)
a.prepare_bill(t_billno) ;
return ;
}
}
clrscr() ;
if (!item_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Item Code not found" ;
getch() ;
if (purchased)
a.prepare_bill(t_billno) ;
return ;
}
gotoxy(60,2) ;
cout <<"Date:" <<d1 <<"/" <<m1 <<"/" <<y1 ;
display_record(tcode) ;
do
{
valid = 1 ;
gotoxy(1,8) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER QUANTITY TO BE PURCHASE IN Kg." ;
gotoxy(5,8) ;
cout <<"Quantity : " ;
cin>>t_quantity ;
qty=t_quantity ;
if (t_quantity == 0)
{
if (purchased)
a.prepare_bill(t_billno) ;
return ;
}
if (qty < 1 || qty > 800)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..800" ;
getch() ;
}
} while (!valid) ;
do
{
gotoxy(5,10) ; clreol() ;
gotoxy(5,10) ;
cout <<"Do you want to cancel this purchase (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
{
purchased = 1 ;
fstream file ;
file.open("PRODUCT.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(product)))
{
if (itemcode == tcode)
{
t_itemcode = itemcode ;
strcpy(t_itemname,itemname) ;
t_cost = itemcost ;
t_price = itemprice ;
t_qty = qty ;
a.add_bill(t_billno,t_itemcode,t_itemname,t_qty,t_cost,t_price) ;
i++ ;
break ;
}
}
file.close() ;
}
do
{
gotoxy(5,12) ; clreol() ;
gotoxy(5,12) ;
cout <<"Do you want to purchase more (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
} while (ch == 'Y') ;
a.prepare_bill(t_billno) ;
}
//**********************************************************
// THIS FUNCTION RETURNS THE BILL NO. OF THE LAST RECORD
// IN THE BILL FILE (BILL.DAT)
//**********************************************************
int account :: last_billno(void)
{
fstream file ;
file.open("BILL.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
int t=0 ;
while (file.read((char *) this, sizeof(account)))
t = billno ;
file.close() ;
return t ;
}
//**********************************************************
// THIS FUNCTION ADDS THE RECORD IN THE BILL FILE (BILL.DAT)
//**********************************************************
void account :: add_bill(int t_billno, int t_itemcode, char
t_itemname[30], float t_qty, float t_cost, float t_price)
{
struct date d;
int d1, m1, y1 ;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
dd = d1 ;
mm = m1 ;
yy = y1 ;
code = t_itemcode ;
strcpy(name,t_itemname) ;
cost = t_cost ;
price = t_price ;
quantity = t_qty ;
billno = t_billno ;
fstream file ;
file.open("BILL.DAT", ios::out | ios:: app ) ;
file.write((char *) this, sizeof(account)) ;
file.close() ;
}
//**********************************************************
// THIS FUNCTION PREPARES AND DISPLAYS THE BILL FOR THE
// GIVEN BILL NO. ACCORDING TO PURCHASES MADE.
//**********************************************************
void account :: prepare_bill(int t_billno)
{
clrscr() ;
struct date d;
int d1, m1, y1 ;
getdate(&d);
d1 = d.da_day ;
m1 = d.da_mon ;
y1 = d.da_year ;
float total=0.0, total_bill=0.0 ;
gotoxy(33,3) ;
cout <<"CUSTOMER BILL" ;
gotoxy(55,5) ;
cout <<"Date:" <<d1 <<"/" <<m1 <<"/" <<y1 ;
gotoxy(8,7) ;
cout <<"ITEMS PURCHASED" ;
gotoxy(8,8) ;
cout <<"+++++++++++++++" ;
gotoxy(8,9) ;
cout <<"Item code Item name Cost Price Qty Total"
;
gotoxy(8,10) ;
cout <<"------------------------------------------------------------"
;
int row=11 ;
fstream file ;
file.open("BILL.DAT", ios::in) ;
file.seekg(0) ;
while (file.read((char *) this, sizeof(account)) !=0 )
{
if (billno == t_billno)
{
gotoxy(8,5) ;
cout <<"BILL NO. # " <<billno ;
gotoxy(8,6) ;
cout <<"===============" ;
gotoxy(10,row) ;
cout <<code ;
gotoxy(18,row) ;
cout <<name ;
gotoxy(39,row) ;
cout <<cost ;
gotoxy(47,row) ;
cout <<price ;
gotoxy(56,row) ;
cout <<quantity ;
total = quantity * price ;
gotoxy(63,row) ;
cout <<total ;
total_bill = total_bill + total ;
row++ ;
}
}
file.close() ;
gotoxy(39,row+1) ;
cout <<"TOTAL BILL: Rs." <<total_bill <<" /=" ;
getch() ;
}
//**********************************************************
// THIS FUNCTION DISPLAYS THE LIST OF THE BILLS
//**********************************************************
void account :: bill_list(void)
{
clrscr() ;
fstream file ;
file.open("BILL.DAT", ios::in) ;
file.seekg(0) ;
int row=5, found=0, pageno=1, prev_billno=0, flag=0 ;
float total=0.0, total_bill=0.0 ;
gotoxy(30,2) ;
cout <<"LIST OF BILLS" ;
gotoxy(3,4) ;
cout <<"Billno. Date Item Code Item name Cost Pri Qty Total" ;
gotoxy(3,5) ;
cout
<<"===========================================================================" ;
while (file.read((char *) this, sizeof(account)))
{
row++ ;
delay(20) ;
found = 1 ;
if (prev_billno != billno)
{
if (flag)
{
gotoxy(52,row) ;
cout <<"TOTAL BILL: Rs." <<total_bill <<"/=" ;
total_bill = 0.0 ;
row++ ;
}
gotoxy(4,row) ;
cout <<billno ;
}
flag = 1 ;
gotoxy(11,row) ;
cout <<dd <<"/" <<mm <<"/" <<yy ;
gotoxy(24,row) ;
cout <<code ;
gotoxy(32,row) ;
cout <<name ;
gotoxy(52,row) ;
cout <<cost ;
gotoxy(59,row) ;
cout <<price ;
gotoxy(67,row) ;
cout <<quantity ;
total = quantity * price ;
gotoxy(73,row) ;
cout <<total ;
total_bill = total_bill + total ;
if ( row >= 23 )
{
row = 5 ;
gotoxy(66,1) ;
cout <<"Page no. : " <<pageno ;
pageno++ ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
clrscr() ;
gotoxy(30,2) ;
cout <<"LIST OF BILLS" ;
gotoxy(3,4) ;
cout <<"Billno. Date Item Code Item name CostPrice Qty Total" ;
gotoxy(3,5) ;
cout
<<"===========================================================================" ;
}
prev_billno = billno ;
}
row++ ;
gotoxy(52,row) ;
cout <<"TOTAL BILL: Rs." <<total_bill <<"/=" ;
if ( !found )
{
gotoxy(5,10) ;
cout <<"\7Records not found" ;
}
gotoxy(66,1) ;
cout <<"Page no. : " <<pageno ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
file.close () ;
}
//**********************************************************
// THIS FUNCTION IS THE MAIN FUNCTION CALLING THE MAIN MENU
//**********************************************************
void main(void)
{
clrscr() ;
menu m ;
m.main_menu() ;
}
Subscribe to:
Posts (Atom)

