Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- const string StopName = "***";
- class MovieType
- {
- //friend ostream& operator<<(const MovieType& p);
- private:
- string m_title; //THIS IS THE "key"
- string m_studio;
- string m_stars;
- string m_receipts;
- int m_year;
- public:
- MovieType(string title = "", string studio = "", string stars = "", int year = 1990, string receipts = "");
- bool CompareKeys(const MovieType& p2) const;
- void Initialize(string title = "", string studio = "", string stars = "", int year = 1990, string receipts = "");
- bool ReadOneMovieFromFile(ifstream& fin);
- void Display(ostream& os = cout) const;
- };
- MovieType::MovieType(string title, string studio, string stars, int year, string receipts)
- {
- m_title = title;
- m_studio = studio;
- m_stars = stars;
- m_year = year;
- m_receipts = receipts;
- }
- bool MovieType::CompareKeys(const MovieType& p2) const
- {
- return true;
- }
- void MovieType::Initialize(string title, string studio, string stars, int year, string receipts)
- {
- m_title = title;
- m_studio = studio;
- m_stars = stars;
- m_year = year;
- m_receipts = receipts;
- }
- bool MovieType::ReadOneMovieFromFile(ifstream& fin)
- {
- getline(fin,m_title);
- if( m_title == StopName )
- return false;
- fin >> m_year;
- fin >> m_receipts;
- fin >> m_studio;
- fin.ignore(50,',');
- getline(fin,m_stars);
- return true;
- }
- void MovieType::Display(ostream& os) const
- {
- os << "TITLE:" << m_title << endl;
- os << "STUDIO:" << m_studio << endl;
- os << "STARS:" << m_stars << endl;
- os << "YEAR:" << m_year << endl;
- os << "RECEIPTS:" << m_receipts << endl;
- }
- int main()
- {
- MovieType one;
- ifstream f;
- f.open("Movies1.txt");
- one.ReadOneMovieFromFile(f);
- one.Display();
- cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment