You are on page 1of 17

#include<stdio.

h>
#include<string.h>
#include<iomanip.h>
//#include<windows.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<iostream.h>
#include<fstream.h>

void welcome();
void login();
void menu();
void addnewalbum();
void editalbum();
void viewalbum();
void deletealbum();
void searchalbum();
struct Album
{
char year[20];
char name[30];
char artist[30];
float price;
}s;
void main()
{
welcome();
login();
}

void welcome()
{
int i;

time_t t;
time(&t);

cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n
o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o ";
cout<<"\n * * ";
cout<<"\n * * ";
cout<<"\n * WELCOME TO * ";
cout<<"\n * * ";
cout<<"\n * | ALBUM MANAGEMENT SYSTEM| *
";
cout<<"\n * * ";
cout<<"\n * * ";
cout<<"\n * * ";
cout<<"\n * Press ENTER to continue. . * ";
cout<<"\n * * ";
cout<<"\n
o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o*o ";
cout<<"\n\n";

cout<<"\nCurrent date and time : %s",ctime(&t);

getchar();
system("cls");

void login()
{
system("cls");
char name[20];
char pass[20];
char Username[20]="admin";
char Password[20]="admin";
int i,j;

cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<" ALBUM MANAGEMENT SYSTEM ";
cout<<"\n ";
cout<<"\n LOGIN MENU ";
cout<<"\n ";
cout<<"\nUsername : ";
cin>> name ;
cout<<"\n ";
cout<<"\nPassword : ";
cin>>pass ;

if (strcmp(name,Username) == 0 && strcmp(pass,Password) == 0)

{
system("cls");
cout<<"\n";
for(i=0;i<160;i++)
cout<<"-";
cout<<"\n";
cout<<"\n";
cout<<" WELCOME USER ! ";
cout<<"\n ";
cout<<"\n You are Logged in.
";
cout<<"\n ";
cout<<"\n ";
cout<<"\n ";
cout<<"\n Press any key to Continue...
";
cout<<"\n\n";
for(i=0;i<160;i++)
cout<<"-";
getch();
system("cls");
}

else
{
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<" SORRY, ";
cout<<"\n The Username or the Password is Incorrect.
";
cout<<"\n ";
cout<<"\n Please Try Again ! ";
getch();
system("cls");
login();
}

void menu();
{
time_t t;
time(&t);
int Password;
char choice;
system("cls");
while(1)
{

system("cls");
cout<<"\n";
for(i=0;i<80;i++)
cout<<"-";
for(j=0;j<80;j++)
cout<<"-";
for(i=0;i<80;i++)
cout<<"-";
cout<<"\n";
cout<<"\n ALBUM MANAGEMENT SYSTEM
";
cout<<"\n";
cout<<"\n MENU ";
cout<<"\n\n Press 1 : >> ADD NEW ALBUM
";
cout<<"\n\n Press 2 : >> EDIT EXISTING ALBUM
";
cout<<"\n\n Press 3 : >> VIEW ALBUMS
";
cout<<"\n\n Press 4 : >> SEARCH ALBUMS
";
cout<<"\n\n Press 5 : >> DELETE ALBUM
";
cout<<"\n\n Press 6 : >> EXIT. ";
cout<<"\n\n";
for(i=0;i<80;i++)
cout<<"-";
cout<<"\nCurrent date and time : %s",ctime(&t);
for(i=0;i<80;i++)
cout<<"-";

choice=getch();
choice=toupper(choice);
switch(choice)

{
case '1':
addnewalbum();
break;
case '2':
editalbum();
break;
case '3':
viewalbum();
break;
case '4':
searchalbum();
break;
case '5':
deletealbum();
break;
case '6':
system("cls");
cout<<"\n\n :-) THANK YOU !!
";
// Sleep(2000);
exit(0);
break;
default:
system("cls");
cout<<"INVALID KEYWORD. PLEASE ENTER A VALID
KEYWORD TO CHOOSE. ";
cout<<"\nPRESs any key to continue..........";
getch();
}
}
}
}

void addnewalbum()
{
fstream Album;
char test;
Album.open("album22.txt",ios::in|ios::out|ios::ate);
if(Album==0)
{
Album.open("album22.txt",ios::in|ios::out|ios::ate);
system("cls");
getch();
}
while(1)
{
system("cls");
cout<<"\nEnter Album Name: ";
fflush(stdin);
cin>>s.name;
cout<<"\nEnter Album Year: ";
cin>>s.year;
cout<<"\nEnter Album Artist: ";
fflush(stdin);
cin>>s.artist;
cout<<"\nEnter Album Price: ";
cin>>s.price;
Album.write((char*)&s,sizeof(s)) ;
fflush(stdin);
system("cls");

cout<<"\n\n";
cout<<" * The Album is Successfully recorded. \n\n";
cout<<"\n * Press any Key to Continue ";
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n Press ESC
to return back to < MAIN MENU >";
test=getche();
if(test==27)
break;
}
Album.close();
}

void editalbum()
{
fstream Album;
char test;
char year[20];
long int size=sizeof(s);
Album.open("album22.txt",ios::in|ios::out);
int last=Album.tellg();
int n=last/sizeof(s);
int on;
cout<<"\n Enter The Row Number For Update";

cin>>on;
int l=(on-1)*sizeof(s);

if(Album.eof())
Album.clear();

Album.seekp(l);
cout<<"\n Enter the new Album Year:";
fflush(stdin);
cin>>s.year;
cout<<"\n Enter the new Album Name: ";
fflush(stdin);
cin>>s.name;
cout<<"\n Enter the new Album Artist: ";
fflush(stdin);
cin>>s.artist;
cout<<"\n Enter the new Album Price: ";
cin>>s.price;
Album.write((char *)&s,sizeof(s));
fflush(stdin);
system("cls");
//break;

cout<<"\n\n";
cout<<" * Album is Successfully edited. \n\n";
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Press ESC to return back to < MAIN MENU >";
test=getche();
if(test==27)

Album.close();
}

void viewalbum()
{
fstream Album;
int i,j;
Album.open("album22.txt",ios::in|ios::out);
if(!Album)
exit(0);
system("cls");
cout<<" Album Year \t Album Name \t Album Artist \t Album Price\
n";
for(i=0;i<160;i++)
cout<<"-";

while(Album.read((char*)&s,sizeof(s)))
{
cout<<s.year<<"\t\t "<<s.name<<"\t\t\t "<<s.artist<<"\t\t
"<<s.price<<"\n";
}
cout<<"\n";
for(i=0;i<160;i++)
cout<<"-";

Album.close();
getch();
}

void searchalbum()
{
fstream Album;
char year[20];
int flag=1;
Album.open("album22.txt",ios::in|ios::out);
Album.seekg(0);
if(Album==0)
exit(0);
fflush(stdin);
system("cls");
cout<<"SEARCH ";
cout<<"\nEnter Album Year :";
cin>> year;
while(Album.read((char * )&s,sizeof(s)))
{
if(strcmp(s.year,year)==0)
{ system("cls");
cout<<"SEARCH RESULTS ";
cout<<"\n-----------------------------------";
cout<<"\n\n\n"<<"Year="<<s.year<<"\n\
n"<<"Name="<<s.name <<"\n\n"<<"Artist:"<<s.artist<<"\n\
n"<<"Price:"<<s.price<<" \n-----------------------------------";
cout<<"\n\n\n\n\n\n\n\n\n\nPress any key to Return Back
to < MAIN MENU >";
flag=0;
break;
}
else if(flag==1)
{ system("cls");
cout<<"OOPS! No Results Found.";
cout<<"Please Try Again. ";
}
}
getch();
Album.close();
}

void deletealbum()
{
system("cls");
fstream Album,f1;
int i=1;
char year[20];
Album.open("album22.txt",ios::in|ios::out);
f1.open("f1.txt",ios::in|ios::out);
if(!Album)
exit(0);

if(!Album)
exit(0);
system("cls");

cout<<"Enter Album's Year to delete: ";


fflush(stdin);
cin>>year;
while(Album.read((char * )&s,sizeof(s)) )
{
if(strcmp(s.year,year)==0)
{ i=0;
continue;

}
else
{
f1.write((char *)&s,sizeof(s)) ;
}

}
if(i==1)
{ system("cls");
cout<<"Album "<<year<<" not AVAILABLE";
getch();

Album.close();
main();
}
Album.close();
f1.close();
remove("album22.txt");
rename("f1.txt","album22.txt");
system("cls");
cout<<"album22 :"<<year<<" was successfully deleted.";
Album.close();
f1.close();
getch();
}

You might also like