sir,please correct the errors in this program and also write the algorithm in this program and give me an introduction to this program.Pls send the error free program,algorithm & introduction before 03/09/2004.thank you
#include<iostream>
#include<iomanip>
#include<stdio>
#include<cstdlib>
#include<cctype>
#include<fstream>
using namespace std;
const int maxchrs=50;
const int items=3;
const short year=0;
const short length=1;
const short shelf=2;
class movies
{
short data[items];
string title ;
bool readmovie(fstream &video)
{
char str[maxchrs];
video.read(str,maxchrs);
title=str;
video.read((char*)data,sizeof(data));
if(!video.eof())
return true;
else
returnfalse;
}
void writemovie(fstream &video)
{
video.write(&title[0],maxchrs);
video.write((char*)data,sizeof(data));
}
public;
void printfile(void)
void add(void)
void del(void)
void change(int index)
void newfile(void)
};
void newfile(void)
{
fstream video;
video.open("VIDEOS.DAT",ios::out|ios::binary);
title="Nammal";
data[year]=2002;data[lenth]=95;data[shelf]=265;
write movie(video);
title="four the people";
data[year]=2003;data[lenth]=88;data[shelf]=300;
write movie(video);
title="runway";
data[year]=2004;data[lenth]=75;data[shelf]=550;
write movie(video);
video.close()
}
int main(void)
{
movies movie;
char choice;
movie.newfile();
fstream video;
video.open("video file missing"<<endl;
exit(EXIT_FAILURE);
}
video.close();
do
{
cout<<"Do you want to: change:\n";
cout<<"[A]dd a video? A[T]itle?\n";
cout<<"[D]elete a video? A[Y]ear?\n";
cout<<"[p]rint the list? A[L]ength? \n";
cout<<"[Q]uit ? A[S]helf position?\n";
cout<<"Take your choice:";
cin>>choice;
cin.ignore(500,'\n');
switch(toupper(choice))
{
case 'A':
movie.add();
break;
case'D':
movie.del();
break;
case'T':
movie.change(-1);
break;
case'y':
movie.change(year);
break;
case'L':
movie.change(length);
break;
case's':
movie.change(shelf);
break;
case'p':
movie.printfile();
}
}
while(toupper(choice)!='Q');
return 0;
}
void printfile(void)
{
fstream video;
short index;
video.open("VIDEOS.DAT",ios::in|ios::binary);
cout<<"\n YEAR LEN SHELF TITLE \n";
while(readmovie(video))
{
for(index=0;index<items;++index)
cout<<setw(6)<<data[index];
cout<<" "<<title<<endl;
}
cout<<endl;
video.close();
}
void add(void)
{
fstream video;
movies newmovie;
int recLen=maxchrs+sizeof(data);
long pos;
video.open("VIDEOS.DAT",ios::in|ios::binary);
cout<<"new title:";
getline(cin,new movie.title,'\n');
cout<<"year,length,shelfposition:";
cin>>newmovie.data[year]>>newmovie.data[length]
>>newmovie.data[shelf];
cin.ignore(500,'\n');
video.seekg(-recLen,ios::end);
readmovie(video);
while(newmovie.title < title && pos > 0)
{
writemovie(video);
pos=recLen;
if(pos>0)
{
video.seekg(pos-recLen,ios::beg);
readmovie(video);
}
}
video.seekg(pos,ios::beg);
newmovie.writemovie(video);
video.close();
}
void del(void)
{
fstream video;
fstream temp;
string deltitle;
char answer;
video.open("VIDEOS.DAT",ios::in|ios::binary);
temp.open("TEMP.$TM",ios::out|ios::binary);
cout<<"Deletetitle:";
getline(cin,deltitle,'\n');
while(readmovie(video))
{
answer='N';
if
(deltitle==title.substr(0,deltitle.size()))
{
cout<<"Delete"<<title<<"?";
cin>>answer;
cin.ignore(500,'\n');
}
if(toupper(answer)!='y')
writemovie(temp);
else
deltitle='~";
}
void change(int index)
{
fstream video;
string chtitle;
char answer;
video.open("VIDEOS.DAT",ios::in|ios::out|ios::binary);
cout<<"change title:";
getline(cin,chtitle,'\n');
while(readmovie(video))
{
if
(chtitle==title.substr(0,chtitle.size()))
{
cout<<"change"<<title<<"?";
cin>>answer;
cin.ignore(500,'\n');
if(toupper(answer)=='y')
{
if (index==-1)
{
cout<<"To:";
getline(cin,title,'\n');
}
else
{
cout<<"change"<<data[index]<<"to:";
cin>>data[index];
cin.ignore(500,'\n');
}
video.seekg(-maxchrs+sizeof(data)),ios::cur);
writemovie(video);
video.seekg(0,ios::end);
}
}
}
video.close();
}