LiBRiUMz
Do not give up so quick. First pick apart what the directions say.
"Create an abstract data type that represents a DVD in this store." |
That says to me start with;
Within the class you will need your private variables and public member functions. One member you can get from the instructions is a print function. Last the instructions tell you to create an array of 10 instances of the
DVD class, and then fill the array with information read in from a file that you create, once the file is read print it out.
Once you know what to work on it becomes easier to work on small pieces instead of the whole. Expanding on the genre and rating you could use an enumeration for these variable which would take up less space in a file. Later in the print function use a switch case to chance the numbers into something meaningful.
Here is an example of my interpretation of the directions. May not be the best way to code the program, but it is quick and dirty and food for thought.
The DVD.h file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#pragma once
class DVD
{
public:
// constructor and destructor defined outside of the class
DVD();
~DVD();
// Forward declarations defined outside of class in the main file
void GetInputFromFile(ifstream &IF);
void PrintRec();
private:
string m_tital;
string m_genra;
string m_rating;
int m_year;
string m_rentalDate;
string m_returnDate;
};
// constructor setting all the private varables to empty or 0
DVD::DVD() : m_tital{ "" }, m_genra{ "" }, m_rating{ "" }, m_year{ 0 }, m_rentalDate{ "" }, m_returnDate{ "" }
{
}
// destructor
DVD::~DVD()
{
}
|
The Main file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// DVD Rental.cpp : Defines the entry point for the console application.
// Written and compiled with Visual Studio 2015 with Windows 10 OS
//
#include "stdafx.h"
#include <stdhead.h> // my own file contains "iostream", "string", "cstring", "vector", "iomanip", "Windows.h" just saves me some typing
#include <fstream> // for file IO
#include <array> // for use of the array class
#include "proto.h" // A file for my own use
#include "DVD.h"
// Member fuctions of the DVD class
void DVD::GetInputFromFile(ifstream &IFILE)
{
IFILE >> m_genra >> m_rating >> m_year >> m_rentalDate >> m_returnDate >> m_tital;
}
void DVD::PrintRec()
{
cout << m_tital << endl << m_genra << endl << m_rating << endl << m_year << endl << m_rentalDate << endl << m_returnDate << endl;
}
int main()
{
system("color 17"); // This and line 29 not needed for the program my personal use
CLS;
ifstream IFILE; // define the input file type
IFILE.open("Rental Info.txt");
// Test for is open
if (IFILE.is_open())
{
cout << "File is open.\n" << endl;
}
else
{
CLS;
cout << "\n\nCan not open \"Rental Info.txt\"" << endl;
Sleep(5000);
exit(1);
}
array<DVD, 10> myarray; // Create an array of 10 DVDs
// Could be done as a DVD member function,but worked for a quick solution
for (int lp = 0; lp < myarray.size(); lp++)
{
myarray[lp].GetInputFromFile(IFILE);
}
for (int lp = 0; lp < myarray.size(); lp++)
{
myarray[lp].PrintRec();
cout << endl;
}
cout << "\n\n\n\nFin Press any key to continue -- > ";
_getch();
IFILE.close();
return 0;
}
|
And the test file I used to read in the information.
1 2 3 4 5 6 7 8 9 10 11
|
music NR 2004 11/12/2016 11/15/2016 Celtic_Woman_a_New_Journey
music NR 2006 12/20/2016 12/25/2016 Celtic_Woman_a_New_Beginning
music NR 2007 10/15/2016 10/20/2016 Chloe
SIFI PG 2000 08/02/2016 08/07/2016 Startrek_Voyager_Seson_3
SIFI PG 2000 08/09/2016 08/14/2016 Startrek_Voyager_Seson_4
SIFI PG 2000 08/09/2016 08/14/2016 Startrek_Voyager_Seson_5
SIFI PG 2000 08/09/2016 08/14/2016 Startrek_Voyager_Seson_6
Drama PG 1999 07/01/2016 07/08/2016 Criminal_Minds_Season_1
Drama PG 1999 07/01/2016 07/08/2016 Criminal_Minds_Season_2
Drama PG 1999 07/01/2016 07/08/2016 Criminal_Minds_Season_3
|
Notice the way I wrote the title or name of the dvd. I did this based on the way of reading input from the file. Input stops on a white space, so you can not have any white space in the title.
A DVD member function could be written to remove the underscore characters and replace them with spaces.
I hope this helps you understand this better.
Andy