Film eklemenizi,update etmenizi,filmleri siralamanizi,eklediginiz actor ve actrislerin hangi filmlerde oynadigi ve bilgisayarda yerini dogru olarak kaydettiginiz filmi calistirmaniza yarayacak bir program. cmpe.boun projesi
#include<iostream>
#include<fstream>
#include <process.h>
#include<string>
using namespace std;
using std::ofstream;
using std::ifstream;
using std::fstream;
struct info{
char title[30];
char actor[30];
char actress[30];
int year;
char path[128];
};
struct index{
char act[30];
int ind[10];
};
void menu();
void insert(index,int,int);
void update();
void list();
int film_no();
void show(index,int);
void play();
void menu(){
cout<<"Welcome to the PMDB system"<<endl
<<"Please enter your choice:"<<endl
<<" a. Insert Film"<<endl
<<" b. Update Film"<<endl
<<" c. Show Films by Actor/Actress"<<endl
<<" d. List All Films"<<endl
<<" e. Play Movie"<<endl
<<" f. Exit"<<endl;
}
void insert(index idx[],int &counter,int &indexno){ //counter is the number of film in movie.db file
//indexno is the number in the current movie.idx file
info mov;
fstream file("C:\\********s and Settings\\thehero\\Desktop\\movie.db",ios::out | ios::binary | ios::app | ios::in);
fstream file2("C:\\********s and Settings\\thehero\\Desktop\\movie.idx",ios::binary | ios::in | ios::app | ios::out);
if(!file){
cerr<<"file cannot be opened"<<endl;
exit(1);
}
if(!file2){
cerr<<"file cannot be opened"<<endl;
exit(1);
}
cout<<"Please enter information of the movie: "<<endl;
cout<<"Title: ";
cin.ignore(); //to get the title,otherwise "\n" becomes title
cin.getline(mov.title,30);
cout<<"Actor: ";
cin.getline(mov.actor,30);
cout<<"Actress: ";
cin.getline(mov.actress,30);
cout<<"Year: ";
cin>>mov.year;
cin.ignore();
cout<<"Path: ";
cin.getline(mov.path,128);
cout<<"\n"<<"Movie is added to PMDB...."<<endl<<endl;
file.write(reinterpret_cast<const char *>(&mov),sizeof(mov));
int flag1=0,flag2=0,g=0,z,x,q=0; //flag1 is to understand whether actor is present before,flag2 is for actress
for(z=0;z<indexno;z++){ //z and x are used only in 'for'
if(!strcmp(mov.actor,idx[z].act)){
flag1=1;
break;
}
}
for(x=0;x<indexno;x++){
if(!strcmp(mov.actress,idx[x].act)){
flag2=1;
break;
}
}
if(!flag1){
strcpy(idx[indexno].act,mov.actor);
idx[indexno].ind[0]=counter+1;
indexno++;
}
cout<<indexno<<counter<<idx[indexno].ind[0]<<endl;
if(!flag2){
strcpy(idx[indexno].act,mov.actress);
idx[indexno].ind[0]=counter+1;
indexno++;
}
cout<<indexno<<counter<<idx[indexno].ind[0]<<endl;
if(flag1){
while(idx[z].ind[g]!=-1){
g++;
}
idx[z].ind[g]=counter+1;
}
if(flag2){
while(idx[x].ind[q]!=-1){//the same thing for inserting two times a new actress
q++;
}
idx[x].ind[q]=counter+1;
}
counter++; //a new film is being inserted so the counter(no of films) should increase as 1
file.close();
file2.close();
}
void update(){
fstream file("C:\\********s and Settings\\thehero\\Desktop\\movie.db",ios::binary | ios::in | ios::out);
if(!file){
cerr<<"file cannot be opened"<<endl;
exit(1);
}
info oldmov;
int newyear;
char searchtitle[30],newpath[128];
cout<<"Please enter the title you want to update: ";
cin.ignore();
cin.getline(searchtitle,30);
while(!file.eof()){
file.read(reinterpret_cast<char *>(&oldmov),sizeof(info));
if(!strcmp(searchtitle,oldmov.title)){
file.seekg(-(sizeof(oldmov.path)+sizeof(oldmov.year)),ios::cur); //when reading the db file the curser is at the and of read piece
cout<<"Please enter the year you want to update: "; //so it should come back by path and year
cin>>newyear;
file.write(reinterpret_cast<const char *>(&newyear),sizeof(newyear));
cout<<"and the path,please: ";
cin.ignore();
cin.getline(newpath,128);
file.write(reinterpret_cast<const char *>(&newpath),sizeof(newpath));
cout<<endl<<"New year and path are being updated..."<<endl<<endl;
break;
}
}
if(file.eof())
cout<<"There is no such a title existing"<<endl;
file.close();
}
int film_no(){
info oldmov;
int i=0;
fstream file("C:\\********s and Settings\\thehero\\Desktop\\movie.db",ios::binary | ios::in | ios::out | ios::app);
if(!file){
cerr<<"file cannot be opened"<<endl;
exit(1);
}
while(!file.eof()){
file.read(reinterpret_cast<char *>(&oldmov),sizeof(info));
i++;
}
return i-1;
file.close();
}
int index_no(index idx[]){
int h=-1;
fstream file2("C:\\********s and Settings\\thehero\\Desktop\\movie.idx",ios::binary | ios::in | ios::out | ios::app);
if(!file2){
cerr<<"file cannot be opened"<<endl;
exit(1);
}
while(!file2.eof()){ //calculates the no of indexes saved in idx file
h++;
file2.read(reinterpret_cast<char *>(&idx[h]),sizeof(index));
}
file2.close();
return h;
}
void show(index idx[],int indexno){
fstream file("C:\\********s and Settings\\thehero\\Desktop\\movie.db",ios::binary | ios::in | ios::out);
char act[30];
int s=0,flag=0;
info oldmov;
cout<<"Which actor or actress are you looking for: ";
cin.ignore();
cin.getline(act,30);
for(int f=0;f<indexno;f++){
if(!strcmp(idx[f].act,act)){
while(idx[f].ind[s]!=-1){
if(s==10)
break;
file.seekg(sizeof(oldmov)*(idx[f].ind[s]-1),ios::beg);
file.read(reinterpret_cast<char *>(&oldmov),sizeof(info));
cout<<oldmov.title<<endl;
s++;
flag=1;
}
break;
}
}
if(!flag)
cout<<"There is no such an actor or actress existing,please try again"<<endl<<endl;
file.close();
}
void list(){
fstream file("C:\\********s and Settings\\thehero\\Desktop\\movie.db",ios::binary | ios::in);
info oldmov;
while(!file.eof()){
file.read(reinterpret_cast<char *>(&oldmov),sizeof(info));
if(!file.eof()){
cout<<oldmov.title<<endl
<<oldmov.actor<<endl
<<oldmov.actress<<endl
<<oldmov.year<<endl
<<oldmov.path<<endl
<<endl;
}
}
file.close();
}
void play(){
ifstream file("C:\\********s and Settings\\thehero\\Desktop\\movie.db",ios::binary | ios::in);
if(!file){
cerr<<"file cannot be opened"<<endl;
exit(1);
}
info oldmov;
char title[30],temp[130];
int i;
cout<<"Please enter the title which you want to play: ";
cin.ignore();
cin.getline(title,30);
while(!file.eof()){
file.read(reinterpret_cast<char *>(&oldmov),sizeof(info));
if(!strcmp(title,oldmov.title)){
file.seekg(-(sizeof(oldmov.path)),ios::cur);
file.read(reinterpret_cast<char *>(&oldmov.path),sizeof(oldmov.path));
while(oldmov.path[i-1]!='\0'){
temp[i]=oldmov.path[i-1];
i++;
}
temp[0]='"';
temp[i]='"';
_execl("C:\\Program Files\\Windows Media Player\\Wmplayer.exe","Wmplayer.exe",temp);
}
}
}
/* void play(){
ifstream file("C:\\********s and Settings\\thehero\\Desktop\\movie.db",ios::binary | ios::in);
if(!file){
cerr<<"file cannot be opened"<<endl;
exit(1);
}
info oldmov;
char title[30],temp[130];
int i=1,flag=0;
cout<<"Please enter the title which you want to play: ";
cin.ignore();
cin.getline(title,30);
while(!file.eof()){
file.read(reinterpret_cast<char *>(&oldmov),sizeof(info));
if(!strcmp(title,oldmov.title)){
flag=1;
break;
}
}
if(flag){
while(oldmov.path[i-1]!='\0'){
temp[i]=oldmov.path[i-1];
i++;
}
temp[0]='"';
temp[i]='"';
_execl("C:\\Program Files\\Windows Media Player\\Wmplayer.exe","Wmplayer.exe",temp,NULL);
}
if(!flag)
cout<<"There is no such a title existing"<<endl<<endl;
file.close();
}
file.close();
}
*/
int main(){
char ch;
int film_counter,y,index_counter;
index idx[1200];
for(int d=0;d<1200;d++) //makes all indexes -1 before sending to struct array memory
for(int b=0;b<10;b++)
idx[d].ind[b]=-1;
menu(); //displays the menu
film_counter=film_no(); //returns the no of films
index_counter=index_no(idx); //return the no of index
cout<<index_counter<<film_counter;
cin>>ch;
while(1){
switch(ch){
case 'a':
insert(idx,film_counter,index_counter);
break;
case 'b':
update();
break;
case 'c':
show(idx,index_counter);
break;
case 'd':
list();
break;
case 'e':
play();
break;
case 'f':
{
fstream file2("C:\\********s and Settings\\thehero\\Desktop\\movie.idx",ios::binary | ios::in | ios::out);
//cout<<index_counter;
for(y=0;y<index_counter;y++){
file2.write(reinterpret_cast<const char *>(&idx[index_counter]),sizeof(index));
}
exit(1);
break;
}
// default:
// cout<<"Wrong letter input,please enter again"<<endl;
// break;
}
menu();
cin>>ch;
}
return 0;
}
Movie Data Base
Movie Data Base
Konuyu Okuyanlar: 1 Ziyaretçi