correct errors in this program

Closed Thread

Join Date: Sep 2004
Posts: 1
Reputation: shabna is an unknown quantity at this point 
Solved Threads: 0
shabna shabna is offline Offline
Newbie Poster

correct errors in this program

 
0
  #1
Sep 1st, 2004
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

PROGRAM
#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();
}
Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: correct errors in this program

 
0
  #2
Sep 1st, 2004
Ha ha ha ha. Funny! Ok, I'll bite...

Introduction:
This program moves data from one portion of the computer's memory to another, activates some peripheral devices, and attempts to communicate with a human, albeit cryptically.

Algorithm:
For each instruction in the program, execute the instructions in order, except for branches, until the program is complete.

You made my day, thanks! That was fun!
Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: correct errors in this program

 
0
  #3
Sep 1st, 2004
Seriously. We don't do homework problems for you. If you have a question about the assignment, ask it, but don't ask us to fix the entire program for you.

Besides, giving someone a deadline on a free help forum is kind of rude, anyways...
Alex Cavnar, aka alc6379
Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: correct errors in this program

 
0
  #4
Sep 2nd, 2004
True alc6379, common shabna, we dont get paid for doing this, we are in this to help each other.Chainsaw is a jolly good guy, but if someone wants to take things up a bit, you will find yourself being kicked around.

Btw, check your other post, Stack Overflow has given some very good links which I recommend you read and remmember.
http://www.daniweb.com/techtalkforums/thread10188.html
See what you can, remember what you need

Fourzon | Earn via Coding
Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 129
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: correct errors in this program

 
0
  #5
Sep 2nd, 2004
I didn't realize this was a duplicate thread. Thread locked.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC