I have an assignment that requires me to do this:
Create an abstract data type that represents a DVD in this store. Consider all the data and operations that may be necessary for the DVD type to work well within a rental management system. Include a print() member function that displays all the information about the DVD. Test your data type by creating an array of ten DVD instances and filling them using information read from a test input file that you create. Display the DVD information.
I have been trying to get this to work here, but maybe I just am not quite understanding how to use what I am trying to use properly. Or at all.
My code is posted below. The information in the text file is 10 lines that are like:
Movie1;R;Horror
Movie2;G;Comedy
etc..
Any help is appreciated. If you think I am approaching my assignment in the wrong way, let me know.
You should probably be creating a DVDInfo class (containing data and member functions), rather a C-style struct. Also, you probably want a string for each type of DVD information. For example:
1 2 3 4 5 6 7 8 9 10
class DVDInfo
{
public:
DVDInfo(const string &_title, const string &_rating, const string &_genre);
print();
private:
string title; // e.g. Movie1, Movie2
string rating; // e.g. R, G
string genre; // e.g. Horror, Comedy
};
Then in your main function create a std::vector or std::list of DVDInfo objects & and as you read in each line of the file, create a new DVDInfo object & append it to your vector or list. Finally, iterate through the vector or list, calling each DVDInfo objects' print() function.
Unfortunately your file-reading code will have to get quite a bit more complicated for this to work...
Thanks for your reply.
I wasn't quite sure how to implement this, and I can't quite get this to work... maybe I am doing it wrong still, could you be so kind as to take a look at let me know?
I actually spent some time since my last post just trying to figure out what was wrong.
I got it -sort- of working, but let me show you, and explain my new problem:
This now compiles. But it only outputs the first last line of the text file. What have I done wrong?
Edit: I have realized that I don't have an array for storing all of the dvd instances... but I am not quite sure how to implement one. I have tried a few things to no avail, and hundreds of lines of error spam when trying to compile with everything I tried to do.