Guest User

Untitled

a guest
Jul 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. const string StopName = "***";
  7.  
  8. class MovieType
  9. {
  10. //friend ostream& operator<<(const MovieType& p);
  11.  
  12. private:
  13. string m_title; //THIS IS THE "key"
  14. string m_studio;
  15. string m_stars;
  16. string m_receipts;
  17. int m_year;
  18.  
  19. public:
  20. MovieType(string title = "", string studio = "", string stars = "", int year = 1990, string receipts = "");
  21. bool CompareKeys(const MovieType& p2) const;
  22. void Initialize(string title = "", string studio = "", string stars = "", int year = 1990, string receipts = "");
  23. bool ReadOneMovieFromFile(ifstream& fin);
  24. void Display(ostream& os = cout) const;
  25. };
  26.  
  27. MovieType::MovieType(string title, string studio, string stars, int year, string receipts)
  28. {
  29. m_title = title;
  30. m_studio = studio;
  31. m_stars = stars;
  32. m_year = year;
  33. m_receipts = receipts;
  34. }
  35.  
  36. bool MovieType::CompareKeys(const MovieType& p2) const
  37. {
  38. return true;
  39. }
  40.  
  41. void MovieType::Initialize(string title, string studio, string stars, int year, string receipts)
  42. {
  43. m_title = title;
  44. m_studio = studio;
  45. m_stars = stars;
  46. m_year = year;
  47. m_receipts = receipts;
  48. }
  49.  
  50. bool MovieType::ReadOneMovieFromFile(ifstream& fin)
  51. {
  52. getline(fin,m_title);
  53. if( m_title == StopName )
  54. return false;
  55. fin >> m_year;
  56. fin >> m_receipts;
  57. fin >> m_studio;
  58. fin.ignore(50,',');
  59. getline(fin,m_stars);
  60. return true;
  61. }
  62.  
  63. void MovieType::Display(ostream& os) const
  64. {
  65. os << "TITLE:" << m_title << endl;
  66. os << "STUDIO:" << m_studio << endl;
  67. os << "STARS:" << m_stars << endl;
  68. os << "YEAR:" << m_year << endl;
  69. os << "RECEIPTS:" << m_receipts << endl;
  70. }
  71.  
  72. int main()
  73. {
  74. MovieType one;
  75. ifstream f;
  76. f.open("Movies1.txt");
  77. one.ReadOneMovieFromFile(f);
  78. one.Display();
  79. cin.get();
  80. return 0;
  81. }
Add Comment
Please, Sign In to add comment