I am developing an application for a video store, can someone guide me on different fragments of it.I need some help here. Here is what i have come up so far:

#include <iostream.h>//
#include <string.h>
#include <fstream.h>//Library fro File I/O  


using std::string;



class Video
{
 private:
      //Data Members   
       string title;
       string barcode;
       string category;
       long runtime;
       short copies;  
 public: 
      //Member Functions   
      void setTitle(string t);
      string getTitle();
      
      void setBarcode(string b);  
      string getBarcode();
                     
      void setCategory(string c);
      string getCategory();
      
      void setRuntime(long r);
      long getRuntime();
      
      void setCopies(short c);
      short getCopies();
      
      void AddVideoRec(string t,string b,string cat,long r,short c);
      void DeleteVidoeRec();
      void ModifyVideoRec();
      void PrintVideoRec();
      void FindVideoRec();
      void IncVideoCount();
      void DecVideoCount();
      void RentVideo();
      void RetVideo();      
};




void Video::setTitle(string t)
{
     title = t;     
}

string Video::getTitle()
{
     return title;
}



void Video::setCategory(string c)
{
     category = c;     
} 

string Video::getCategory()
{
     return category;       
}



void Video::setBarcode(string b)
{
       barcode = b;       
}  

string Video::getBarcode()
{
     return barcode;     
}



void Video::setRuntime(long r)
{
     runtime = r;
}

long Video::getRuntime()
{
     return runtime;        
}



void Video::setCopies(short c)
{
     copies = c;     
}

short Video::getCopies()
{
      return copies;      
}


     
void Video::AddVideoRec(string t,string b, string cat,long r, short c)
{
     ofstream myFile;
     myFile.open("VideoDatabase.txt",ios::app);//Opening File in append mode
     myFile<<"\n\nVideo Category: "<<cat<<"\n"
     <<"Video Title: "<<t<<"\n"
     <<"Video Barcode: "<<b<<"\n"
     <<"Video Runtime: "<<r<<"\n"
     <<"Video Copies: "<<c;
}




main()
{
string videoTitle;
string videoCategory;
string videoBarcode;
long videoRuntime;
short videoCopies;
      
char userChoice;

do
{
   cout<<"\n\n\t\t\tWelcome to XYZ Video Store System\n";
   cout<<"\nVideo Store System Menu:\n\n";  
   
   /************PROGRAM MENU*********************/
   cout<<"A) Add a new video record\n";
   cout<<"B) Delete a video record\n";
   cout<<"C) Modify a video record\n"; 
   cout<<"D) Print out a videos record\n";
   cout<<"E) Print out all video records\n";
   cout<<"F) Find a video record\n";
   cout<<"G) Rent video\n";
   cout<<"H) Return video\n";
   cout<<"Q) Exit\n\n";
   
   cout<<"Please choose your menu:";
   cin>>userChoice;
   
   Video *myVideo = new Video;
  
   
   switch (userChoice)
   {          
   case 'A':
   //code for Adding Video Record     
   cout<<"\n\n******ADDING VIDEO RECORD******\n\n";
   cout<<"Enter Video Category: ";
   cin>>videoCategory;
   myVideo->setCategory(videoCategory);
   
   cout<<"Enter Video Title: ";
   cin>>videoTitle;
   myVideo->setTitle(videoTitle);
   
   cout<<"Enter Video Barcode: ";
   cin>>videoBarcode; 
   myVideo->setBarcode(videoBarcode);
   
   cout<<"Enter Video Runtime: ";
   cin>>videoRuntime;
   myVideo->setRuntime(videoRuntime);
   
   cout<<"Enter Number of Copies of the Video: ";
   cin>>videoCopies;
   myVideo->setCopies(videoCopies);
   
   myVideo->AddVideoRec( videoTitle, videoBarcode,videoCategory, videoRuntime,videoCopies);
   break;
   case 'a':
   //code for Adding Video Record
   cout<<"\n\n******ADDING VIDEO RECORD******\n\n";
   cout<<"Enter Video Category: ";
   cin>>videoCategory;
   myVideo->setCategory(videoCategory);
   
   cout<<"Enter Video Title: ";
   cin>>videoTitle;
   myVideo->setTitle(videoTitle);
   
   cout<<"Enter Video Barcode: ";
   cin>>videoBarcode;
   myVideo->setBarcode(videoBarcode);
   
   cout<<"Enter Video Runtime: ";
   cin>>videoRuntime;
   myVideo->setRuntime(videoRuntime);
   
   cout<<"Enter Number of Copies of the Video:";
   cin>>videoCopies;
   myVideo->setCopies(videoCopies);
   
   myVideo->AddVideoRec( videoTitle, videoBarcode,videoCategory, videoRuntime,videoCopies);
   break;
   case 'B':
        //Code for Deleting Video Record
   break;
   case 'b':
        //Code for Deleting Video Record
   break;
   case 'C':
        //Code for Modifying a Video Record
   break;
   case 'c':
        //Code for Modifying a Video Record
   break;
   case 'D':
        //Code for Printing out a Video Record
   break;
   case 'd':
        //Code for Printing out a Video Record
   break;
   case 'E':
        //Code for Printing out all Video Records
   break;
   case 'e':
        //Code for Printing out all Video Records
   break;
   case 'F':
        //Code for Finding a Video Record
   break;
   case 'f':
        //Code for Finding a Video Record
   break;
   case 'G':
        //Code for Renting a Video
   break;
   case 'g':
        //Code for Renting a Video
   break;
   case 'H':
        //Code for Returning a Video
   break;
   case 'h':
        //Code for Returning a Video
   break;
   case 'Q':
        //Code to end program
        system("pause");
   break;
   case 'q':
        //Code to end program
        system("pause");
   break;          
   default:
           system("cls");
           cout<<"\nINVALID ENTRY!";
   break;                    
   }
        
   
}while(userChoice!='A' && userChoice != 'a'&& userChoice!='a' && userChoice!='B' && userChoice!='b' && userChoice!='C' && userChoice!='c' && userChoice!='D' && userChoice!='d' && userChoice!='E' && userChoice!='e' && userChoice!='F' && userChoice!='f' && userChoice!='G' && userChoice!='g' && userChoice!='H' && userChoice!='h' && userChoice!='Q' && userChoice!='q');   
   
     
}

My first problem is that the program cannot accept spaces. I am trying cin.getline but it does not work, i don't know why?

Another problem is about how we can search a record in a text file?

I did the following amendments in the program as you pointed out:

#
cout<<"\n\n******ADDING VIDEO RECORD******\n\n";
#
cout<<"Enter Video Category: ";
#
getline(cin,videoCategory);
#
myVideo->setCategory(videoCategory);
#
 
#
cout<<"Enter Video Title: ";
#
getline(cin,videoTitle);
#
myVideo->setTitle(videoTitle);
#
 
#
cout<<"Enter Video Barcode: ";
#
getline(cin,videoBarcode);
#
myVideo->setBarcode(videoBarcode);

And i came up with this output when i enter a or A:
******ADDING VIDEO RECORD******

Enter Video Category: Enter Video Title:

I don't know why this is happening. Please look in to it and try it out yourself.

It's a bad habbit to mix "cin>>" and getline().
The thing is: when you call cin>>, he gets what you need (in this example, char), but leaves everything else (including newline '\n').
And then when getline is called, it just picks up '\n' and stops.
Before calling getline, add this:

cin.ignore(80, '\n');

I don't know how to search, delete and edit a record. Could you please help me on this

search: open the file for reading then read each record until you get to the one you want.

delete: you have to rewrite the entire file. Open the original file for reading, open another temp file for writing. Read a record, if not the record to be deleted write it back to temp file. Do that for all records. When done, close both files, delete the original, then rename temp to the name of the original.

edit: very similar to search. After locating the record allow the user to make changes. Then do something similar to delete described above except replace the original record with the new one.

This article has been dead for over six months. Start a new discussion instead.