Music Store [ C++ Program ]
MUSIC STORE
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#include<dos.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
#include<math.h>
// CLASS 'db' DEFINITION
class db - { int sno; char
title[40]; int no_copy; charrate[5]; float price; public:
void putdata(); void
replace();
void
increase();
void addrec(); - void rcorder(); void
Viewlib(); void getdataQ; void input(void); void sales(); void bill(); void
lesscopyQ;
// DEFAULT CONSTRUCTOR
db()
{ price=67.78; no_copy=10;
}
// END OF CLASS db
11 INITIALISING GLOBAL
VARIABLES
int no=0; float totcost=0; int netcost=0; db
dummy [50]; db billdat[20];
char cfct-270; db *mu;
// FUNCTION TO SHOW DATA FROM OBJECT
void db::putdata() {
clrscr();
cout«"\n\n
SERIAL NO: " «sno
«"\n\n TITLE :
puts(title); cout«"\n\n RATING : ";
puts(rate);
cout«"\n\n COPIES : "«no^copy; cout«"\n\n PRICE :
"«int(price)«".99"«"$";
j
void db::getdata()
// TO INPUT DATA { cout«"\n sno"; cin»sno; cout«"\n title";
gets(title); fflush(stdin); cout«"\n no: copy"; cin»no_copy;
cout«"\n price"; cin» price; cout«"\n rating"; gets(rate);
fflush(stdin);:
11 LOADING -EFECTS
void Ioad() { clrscr();
for(int j=3 ;j>0;j-) { for(int
i=44;i<59;i++) { _setcursortype(_NOCURSOR); gotoxy(34,24); textcolor(RED);
cprintf("LOADING '*); gotoxy(i,24); textcolor(GREEN);
cprintf("»»"); del ay (90);
clrscr();
}
}"
}
// TO LOAD DATA FROM FILE TO GLOBAL mu
void readfile() { ifstream
ifile("music.dat",ios::binary|ios::beg); mu=new (db[90]);/* dynamic
memory allocation for storing files in active memory */
' db *ptr=mu; if
(mu)
{ while(!ifile.eof())
{ ifile.read((char *)
mu,sizeof(db)); mu++;
i
i
}
else
{cout«"
\n\n\n\n\t\t\t SYSTEM OUT OF MEMORY"- delay(200); exit(0);} ifile.close();
mu=ptr;
// PASSWORD
int pass() { clrscrQ;
intp=1234,c,llag=0;
cout«"
\n\n\n\t\tENTER YOUR 4-DIGIT PASSWORD";
cin»c;
if(c==p)
{
cout«"\n\n\t\t\tACCESS GRANTED"; getch(); flag=l;
}
else
{
cout«"\n\n\t\tACCESS DENIED"; getch();
}
clrscr(); return(flag);
}
// TO WRITE DATA FROM GLOBAL mu TO FILE
void writefile()
{
ofstream
ofile; a
db *ptr=mu;
ofile.open("music.dat",
ios::trunc|ios::binary|ios::beg); for(int i-0;i<50;i++,ptr++)
ofile.write((char*) ptr,sizeof(db)); ofile.close();
}
// FUNCTION TO REDUCE COPIES
void db::iesscopy() {
no__copy-; ofstream ofile;
ofile.open("music.dat",
ios::trunc|ios::binary|ios::beg); for(int i=0;i<50;i++)
ofile.
wrile((char*)&dummy[i],sizeof(db));
ofile.close();
// FUNCTION TO ENTER DATA TO FILE DIRECTLY
void db::input() {
ofstream
ofile("music.dat",ios::app|ios::binary);
db dummy;
dummy.getdata();
ofIle.write((char *)
&dummy, sizeof(dummy)); ofile.close();
}
// TO DISPLAY ERROR
void callerrorO
{
gotoxy(30,24); textcolor(
GREEN);
cout«"\n SORRY SUCH A
CHOICE DOESNOT EXIST"; gotoxy(30,28);
cout«"\n TYPE CHOICE 1 TO 5";
}
// TO ACCESS ADMINISTATOR
A
void administratorQ
{ begin:textcolor(RED); clrscr(); int flag=pass(); if(flag) {intx; db dummy;
textcolor(RED); gotoxy(7,5);
cout«" ANY
CHANGES MADE HEREWITH ALTERS THE FILE PERMANENTLY"
«"\n\n\t PROCEED WITH EXTREME CAUTION"
«"\n\n ADMINISTRATOR
MENU"
«"\n\n 1. REPLACE
FILE"
«"\n\n 2. INCREASE
COPIES"
«"\n\n 3. REORDER FILES"
«"\n\n 4. EXIT"
«"\n\n\n\n\n ENTER YOUR CHOICE";
cin»x; switch (x)
{ case 1: dummy.replace();
break;
case 2: dummy. increase();
break;
case 3: dummy.reorder();
break; case 4: goto
end; default: { clrscr();
cout«"\n\n\n\n\n\n\n INVALID ENTRY";
getch();
goto begin; }
} goto begin;
end:clrscr();
}
// TO REPLACE FILE RECORD
void db "replace () {
clrscr(); int x;
db *ptr01; readiile();
cout«"\n\n\n\n\n\n\n\t
ENTER SERIAL NUMBER OF ALBUM TO REPLACE"; cin»x;
ptrO 1 =(mu+(x-1));
ptrO 1 ->putdata();
ptr01->getdata();
writefile();
readfile();
ptrO l=(mu+(x-1));
ptr01->putdata();
cout«"\n\n\n\n\t\t
FILE OVER WRITE SUCCESS"
}
// TO INCREASE COPIES IN RECORD
void db::increase() {
clrscr(); int x,copy; db*ptr01; readfile();
cout«"\n\n\n\n\n\n\n\t
ENTER SERIAL NUMBER OF ALBUM TO ADD COPIES"; cin»x;
cout«"\n\n\n\n\t
ENTER NUMBER OF COPIES TO ADD";
cin»copy;
ptr01=(mu+(x-l));
ptr01->putdata();
(ptrO 1
->no_copy)+=copy;
writefile();
readfile();
ptr01->putdata();
cout«"\n\n\n\n\t FILE
UPGRADE SUCCESS";
delay (200); }
// TO RENUMBER FILE SERIAL NUMBER -i
void db::reorder() { readfile();
db *ptr02;
for(int i=0;i<60;i++) {
ptr02=(mu+i);
(ptr02->sno)=(i+l);
}
writefile();
cout«"\n\n\n\n\t -
FILE ORDERING SUCCESSFUL"; delay(200);
\ )
II TO RUN ACTIVE MAIN MENU
int mainstrip()
{ char strip[]={ "POWER OF MUSIC BROUGHT
TO YOU BY - MusiC DreamZ"}; char ch; clrscr();
{
for(int i=0;i<80;i++) { gotoxy(0,5); cout«"\n\n\n\n\n\t MU6 STORE"
«"\n\n\t
«"\n\n\n\n\t
|
BBBBBBBBBBBBBBB 1.
SALES"
|
«"\n\n\n\t 2.
VIEW LIBRARY'
3. ADMINISTRATOR"
4.
HELP"
5.
CREDITS"
6.
EXIT"
«"\n\n\n\t «"\n\n\n\t «"\n\n\n\t
<<"\n\n\n\t «"\n\n\n\t
|
ENTER YOUR
CHOICE(l-6)\t";
for( int j=0 ;j <4 7 ;j
++) { gotoxy(80-i+j,45); cout«strip[j]; if(kbhit())
goto end; }
delay(lOO);
clrscr(); }
}
end:ch=getch();
if(ch=-1') { return(l);} else if(ch='2') { return(2);} else if(ch='3') {
return(3);} else if(ch=—4') { return(4);} else if(ch=='5') { retum(5);} else
if(ch=-6') { return(6);}
else
{ return(9);}
// TO RUN ACTIVE HELP MENU
int helpstrip()
{ char strip[]={
"MusiC DreamZ -MUSIC FOR YOUR HEAD... "}; char ch; clrscrQ;
{ for(int i=0;i<80;i++)
{ gotoxy(0,5);
cout«"\n\n\n\n «"\n «"\n\n\n
«"\n\n\n «"\n\n\n «"\n\n\n
for(int j=0;j<47;j++) {
gotoxy(80-i+j,45); cout«strip[j]; if(kbhit())
goto end; }
delay(lOO);
clrscr(); }
}
end:ch=getch();
if(ch—' 1') { return(l);} else if(ch—='2') { return(2);} else if(ch=-3') {
return(3);} else if(ch='4') { return(4);} else
THE MU6 HELP "
BBBBBBBBBBBBBBBBBBB" J) 1. BUYING CD " J) 2. SAVING MONEY "
3. ABOUT MU6 STORE"
J) 4. EXIT HELP ";
{ return (9);}
// TO MANAGE SALES
void db::sales() {
char ch; int x; do
{ BEGIN:clrscr();
textcolor(GREEN); gotoxy(5,28);
cout«"ENTER THE ALBUM
TO BE SELECTED :";
cin»x;
x--;
cout«"\n\n\n\n\t\tTHE
ALBUM YOU SELECTED IS:"; clrscr();
db *ptrf=mu+x;
ptrf->putdata(); if((ptrf->no_copy)==0) {clrscr();
cout«"\n\n\n\n\n\t
SORRY WE ARE OUT OF STOCK PLEASE «"\n\n\t CONTACT US IN ONE WEEK'S
TIME" «"\n\n\n\n\n\n\n\t PRESS ANY KEY TO RETURN TO MENU getch();
goto BEGIN; } '
cout«"\n\n\tARE YOU
SURE?(Y/N)";
cin»ch;
int cost;
if(ch==Y'||ch=y) {
cost=((mu+x)->price)+l; ((mu+x)->price)=cost; ((mu+x)->no_copy)~;
billdat[no]=*(mu+x); totcost+=(mu+x)->price; no++;
}
writefileQ;
}white(ch=,Y,||ch==,y»);
(mu+x)->bill();
// GRAPHICS-EFFECTS
void graphics() { clrscrQ;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"d:\\turboc3\\"); int
x,y,u; y=480;
for (int i=100;i<540;i++)
{ clrscr(); textcolor(BLACK); setcolor(4); outtextxy(i,y/2,"<");
outtextxy(620-i,y/2,">");delay(3);
}
for (u=86;u<540;u++) { putpixel(u,y/2+3,2);
delay(5);
double Y1,Y2,Y;
for(double
ph=3.14/2;u>0;ph=ph+( 15 *(3.14/180))) { for(double ang=0;ang<(3.14);ang=ang+(5*(3.14/180)))
{ for(int x=86;x<541 ;x++) { Yl=60*sin(ang); Y2=60*sin(ang+ph);
Y-y/2+3+(Yl+Y2); putpixel(x,Y,2); ang=ang+(5 * (3.14/180)); if(lcbhit()) {
delay(2);
goto end; }
}
}delay(.01); clrser();
end:
char *mu6[8]={"M","U","6","$","T","0","R","E"};
for(i=0;i<8;i++) . { ior(intj=0;j<5;j~~) { settextsty 1 e(7,0,j+3);
setcolor(l 1); int yl=getmaxyO; int xl=getmaxx(); outtextxy((xl/2),(y 1
/2),mu6[i]); delay(80); clrscr();
}
for(j=5;j>0;j—) {
settextstyle(7,0,j+3); setcolor(,12); int yl=getmaxy(); int xl=getmaxx();
outtextxy((x 1 /2),(y 1 /2),mu6 [i]); delay(80);
clrscr();
}
}
closegraph();
\ i
II TO MANAGE BILL
|
void db::bill() {
clrscr(); readfile();
if(no>0) {
cout« "\n\n\n\t\t MU6
STORE:INVOICE"; cout«"\n\n\n\t\t\t\tYOU SELECTED"«endl; for(int
i=0;i<no;i++)
{
gotoxy(5,10+(i*3));cout«"TITLE:"«billdat[i].title; gotoxy(60,10+(i*3));cout«billdat[i].price«".99";
if(no>=6)
netcost=totcost* 0.75;
else if(no>=4)
netcost=totcost*.85; else
if(no>=2) netcost=totcost*.95; else netcost=totcost; gotoxy(320,200);
cout«"\n\n\n\n YOUR NET AMOUNT IS':
"«totcost«" $";
cout«"\n\n\n\n
YOUR DISCOUNTED PRICE IS :"«netcost«" $"; getch(); I
}
else
{ clrscr();
cout«"\n\n\n\n\n\n\n\t\t
MUSIC IS THE SPICE OF LIFE. SO DO VISIT US AGAIN"
«"\n\n\n\t\t AND TAKE
HOME SOME MUSIC AND NEVER FORGET" «"\n\n\n\t\t LIFE IS SHORT.HEAR
MORE " «"\n\n\n\t\t -POWER OF MUSIC BROUGHT TO YOU BY"
«"\n\n\n\t\t\t MusiC DreamZ.INC"; delay(500);
" I }
1 textcol or(GREEN);
|
// TO MANAGE HELP FILE
void help()
int choice; char ch;
cout«"\n\n\n\n THE MU6 HELP "
«"\n BBBBBBBBBBBBBBBBBBB "
;
cout«"\n\n\n 1. BUYING CD "
«"\n\n\n f 2. SAVING MONEY "
«"\n\n\n f3.ABOUTMU6 STORE"
«"\n\n\n . 4. EXIT HELP ";
gotoxy(40,80);
cout«"\n\n\n \t
Please enter your choice : ";
choice=helpstrip();
clrscr();
switch (choice)
{ case 1 :textcolor(GREEN);
cout«"\n\n BUYING
CD"; cout«"\n\n\n\n\n\n\n"
«" MU6 store has been designed to satisfy
your musical needs. \n
onscreen
|
«" By choosing the option of buying you
will be taken to our " «"\n\n title database,from which you can
select the titles you like,
«"\n\n that is,the
famous english albums and songs.Follow the
«"\n\n instructions while browsing the
database."; cout«"\n\n\n\n\n\n\t\t
X->return to help. ";
ch= getch();
if(ch—X'||ch—x') { clrscr();
help(); } else
break; break;
case 2:
cout«"\n\n SAVING YOUR MONEY !!!"; cout«"\n\n\n\n\n\n\n"
«" MU6 store provides you an opportunity
to save your money.
«"\n\n All you have
to do is buy more copies of your favourite
«"\n\n artists and we
give you a proportional discount on your
«"\n\n bill!This is a
wonderful feature provided by your favourite
\n"
|
«"\n\n music
store.Given below is our discount policy: " «"\n\n\n\n\t NO.of copies
\t Discount" «" \n\n\t >>==6 \t 25% " «" \n\n\t Jd >=4 Yt 15%
" «" \n\n\t
p>=2 \t 5% "; cout«"\n\n\n\n\n\n\t\t X->return to
help. ";
ch=getch();
if(ch==’X’||ch==’x’)
{ clrscr();
help();
else
break;
break;
case 3:
cout<<”\n\n******ABOUT MU6
STORE******”;
cout<<”\n\n\n\n\n”
<<”MU6 version 1.0”
<<”\n\n Evaluation released on date-month-year by”
<<”\n\n Music
DreamZ Inc.”
<<”\n\n Copyright
Held By :”
<<”\n\n ___________________”
<<”\n\n INDIA.”;delay(2000);
cout <<”\n\n\n\t Sincere
gratitude to……..”
<<”\n\n\n\t ________________________________”
<<”\n\n\t ________________________________”
<<”\n\n\t *ALL
the crew of
Music DreamZ Inc.”
<<”\n\n\t\t—MUSIC FOR
YOUR HEAD……….”;
cout<<chr<<”
“<<chr<<” “<<chr<<” “;
cout<<”\n\n\n\t\t X->return
to help.”:
ch=getch():
if(ch==’X’||ch==’x’)
{ clrscr();
help(); }
else
break;
break;
case 4:
cout«"\n\n\n\n\n \t Do you really want to exit(Y/N) : "; char cho;
cin»cho;
if(cho='Y,||cho=-y')
{goto end;}
else
if(cho=-N'||cho--n') { clrscr(); help();} else
{ cout«"\n\t\t WRONG ENTRY!!!!!!!! ";
clrscr(); help();}
break;
default:
cout«"\n\n\n\n\n\n\n !!!!!! wrong entry, returning to help
cout«"\n\n\n \t X->return to help "; ch-getch(); clrscr(); help();
}
end :clrscr();
// TO MANAGE VIEW OF LIBRARY RECORDS
void
db::viewlib()
{
db *ptr03=mu;
clrscr(); int
cost,cur=0; textcolor(GREEN); db *ptr2=ptr03; home:
clrscrQ;
gotoxy(2,2);
cout«"SNO";
gotoxy(6,2);
cout«"TITLE";
gotoxy(47,2);
cout«"RATING";
gotoxy(58,2);
cout«"PRICE"; gotoxy(68,2); cout«"COPIES"; for(int i=cur
j=0;i<cur+l 0;i++,ptr2=ptr03+i,j+=3) { textcolor(GREEN); gotoxy(2,j+4);
cout«(ptr2->sno); gotoxy(6,j+4); cout«(ptr2->title); gotoxy(47,j+4);
cout«(ptr2->rate); cost=(ptr2->price); gotoxy(58,j+4);
cout«cost«".99"; gotoxy(68,j+4); cout«(ptr2->no_copy);
delay(lOO);
}
gotoxy(5,47);cout«"
PAGE UP->8 \t PAGE DOWN->2 \t EXIT->X char a=getch(); if
((a='2')&&(cur<40)) { cur+=10; goto home;} else if(
(a=-8')&&(cur>=10)) { cur-=10; goto home;} else if((a=-x')lj(a~'X'))
{ goto end;} else
{clrscrQ;
cout«"\n\n\n\n\n\n\n\n\n\n\t\t\t
UNIDENTIFYABLE ENTRY"- delay(5Q0);
goto home; }
end : clrscr();
}
// CREDITS
void endprog() {
gotoxy(30,2);
cprintf(“\n ***MU6 STORE***”);
cout<<”\n\n\n\n\n\n\n”
<<”MU6 version 1.0”
<<”\n\n By \n\n Music DreamZ – Music 4 Your
Head…”<<chr<<” “<<chr<<” “<<chr
<<”\n\n\n\t The Crew :”
<<”\n\n\t Name 1”
<<”\n\n\t Name 2 ”
<<”\n\n\t Name 3”<<”\n\n\t Name 4”;
cout<<”\n\n\n\n\n\t\t
THANK YOU. GOOD BYE VISIT US AGAIN SOON…..”;
getch();
}// end of fn.endprog
void credits()
{ int
gdrive=DETECT,gmode,I,*ptr;
initgraph(&gdrive,&gmode,”d:\\turboc3\\”);
int x=getmaxx();
int y=getmaxy();
char*name[2]={“Name 1”,”Name 2”,”Name 3”,”Name 4”};
clrscr();
textcolour(BLACK);
for(i=0;i<2;i++,ptr++)
{ for(int j=0;j<x/2;j++)
{ clrscr();
setcolour(GREEN);
outtextxy(j,y/2,name[i]);
delay(.001);
}
for(int
k=((x/2)-40);k<((x/2)+l 52);k++) { for(int t=0;t<y;t++); setcolor(YELLOW);
line(k,280,k,210); setcolor(GREEN); ou1textxy(x/2,y/2,name[i]); delay(4);
clrscr();
}
for(j =x/2 ;j
<=x;j ++) { clrscr();
setcolor(GREEN
);
outtextxy(j,y/2,name[i]);
delay(.OOl);
}
}
}
void main()
{
loadO;
db dupe;
top:
readfile(); //READING
FILE TO-ACTIVE MEMORY
clrscr();
textcolor(GREEN); _setcursortype(_NOCURSOR);
// dupe.viewlib();
cout«"\n\n\n\n\n\t MU6 STORE"
<<"\n\n\t BBBBBBBBBBBBI3I3B";
cout«"\n\n\n\n\t 1SALES"
«"\n\n\n\t 2. VIEW
LIBRARY"
«"\n\n\n\t 3.
ADMINISTRATOR"
«"\n\n\n\t 4.
PIELP"
«"\n\n\n\t 5.
CREDITS"
<<"\n\n\n\t 6.
EXIT"
«"\n\n\n\t ENTER YOUR CHOICE(l
-6)\t";
int a;
a=mainstrip(); switch(a)
{ case 1: { clrscr();
load(); dupe.sales();
break; }
case 2: { clrscr();
load();
dupe.viewlibQ;
break; }
case 3:{ clrscrQ;
load();
administrator();
break;}
case 4: { clrscr();
help();
break;}
case 5:{ clrscr();
cirscr();
credits(); goto end;
}
case 6:{clrscr();
goto end; }
default:
{
gotoxy(35,24);
clrscr();
callerror();
}
goto top;
end : endprog();
char ch=270; for(int d-0;d<9000;d++)
{cout<<ch<<”
“;
sound(d);
delay(1);}
nosound();
graphics(); delete mu;
}
No comments