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?