944,149 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3909
  • C RSS
Sep 1st, 2004
0

correct errors in this program

Expand Post »
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();
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shabna is offline Offline
1 posts
since Sep 2004
Sep 1st, 2004
0

Re: correct errors in this program

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!
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Sep 1st, 2004
0

Re: correct errors in this program

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...
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003
Sep 2nd, 2004
0

Re: correct errors in this program

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
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Sep 2nd, 2004
0

Re: correct errors in this program

I didn't realize this was a duplicate thread. Thread locked.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 163
The Queen of DaniWeb
cscgal is offline Offline
13,646 posts
since Feb 2002

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C Forum Timeline: C programming question
Next Thread in C Forum Timeline: winding rule in graphics





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC