Guest User

Untitled

a guest
Apr 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. MovieType.cpp
  2.  
  3. #include<iostream> // library
  4. #include"movieType.h" // including movietype.h
  5. #include<fstream>// library for read the file
  6. #include<string>
  7. using namespace std; // library
  8. movieType::movieType () {} // constructor the movietype
  9.  
  10. bool movieType::readMovieInfo(ifstream& inFile) // function to read in the file
  11. {
  12.  
  13.  
  14. //Get rank
  15. inFile>>rank;
  16. if(rank>=1) //Checks to see if rank is valid
  17. {
  18. inFile>>weight;//Reads and Stores weight
  19. inFile>>year;//Reads and Stores year
  20. inFile>>votes;//Reads and Stores votes
  21. inFile>>genre;//Reads and Stores genre
  22. inFile>>length;//Reads and Stores length
  23. getline (inFile, name);
  24. return true; //Returns Success
  25. }
  26. else //Terminates if less than 1.
  27. return false;
  28.  
  29.  
  30.  
  31. }
  32.  
  33. void movieType::printMovieInfo(ofstream& outFile) // function to print in the file
  34. {
  35.  
  36.  
  37. outFile<<rank<<" "<<year<<" "<<genre<<" "<<length<<" "<<" "<<weight<<" "<<votes<<" "<<name<<endl;//prints the info to the file.
  38.  
  39.  
  40. }
  41.  
  42.  
  43. char movieType::getGener() // function to get the genre and put it in order
  44.  
  45. {
  46. return genre;
  47. }
  48.  
  49. int movieType::getRank() // function to get the rank and categorize the info
  50.  
  51. {
  52. return rank;
  53. }
  54.  
  55. bool movieType::operator>(movieType check2) const // bool function for the rank
  56. {
  57. if (rank > check2.rank) // checks if rank is < other rank
  58. return true;
  59. else
  60. return false;
  61. }
  62. bool movieType::operator>=(movieType check) const // bool function for the rank
  63. {
  64. if(rank >= check.rank)//checks if rank is <= the other rank
  65. return true;
  66. else
  67. return false;
  68.  
  69. }
  70.  
  71. movieType::~movieType () {}; //distructor
  72.  
  73.  
  74.  
  75.  
  76.  
  77. main.cpp
  78.  
  79.  
  80. #include<iostream>
  81. #include<string>
  82. #include<fstream>
  83. //#include "QueueType.h" //includ the stack .h file for the stack
  84. #include"QueueType.h"
  85. #include"movieType.h"
  86. typedef movieType ItemType;
  87. #include "PQType.h"
  88. using namespace std;
  89.  
  90. int main()
  91. {
  92. PQType<movieType> MType = PQType<movieType>(50);
  93. movieType movie;
  94.  
  95. bool flag = true;
  96. ifstream inFile;
  97. inFile.open("movie1.txt");
  98.  
  99.  
  100. while(flag&&inFile.is_open())
  101.  
  102. {
  103.  
  104. flag=movie.readMovieInfo (inFile);
  105. if (flag)
  106. MType.Enqueue(movie);
  107.  
  108. }
  109.  
  110. inFile.close();
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. QueType<movieType> GType;
  122. QueType<movieType> Genre [8];
  123. int i;
  124. for(i=0; i<8; i++)
  125. {
  126. Genre[i]=GType;
  127. }
  128.  
  129. while(!MType.IsEmpty())
  130. {
  131. MType.Dequeue(movie);
  132. switch (movie.getGener () )
  133. {
  134. case 'A':
  135.  
  136. Genre[0].Enqueue(movie);
  137.  
  138. break;
  139.  
  140. case 'C':
  141.  
  142. Genre[1].Enqueue(movie);
  143.  
  144. break;
  145.  
  146. case 'D':
  147.  
  148. Genre[2].Enqueue(movie);
  149.  
  150. break;
  151.  
  152. case 'H':
  153.  
  154. Genre[3].Enqueue(movie);
  155.  
  156. break;
  157.  
  158. case 'M':
  159.  
  160. Genre[4].Enqueue(movie);
  161.  
  162. break;
  163.  
  164. case 'R':
  165.  
  166. Genre[5].Enqueue(movie);
  167.  
  168. break;
  169.  
  170. case 'V':
  171.  
  172. Genre[6].Enqueue(movie);
  173.  
  174. break;
  175.  
  176. case 'W':
  177.  
  178. Genre[7].Enqueue(movie);
  179.  
  180. break;
  181.  
  182. }
  183.  
  184.  
  185. }
  186.  
  187.  
  188.  
  189.  
  190. ofstream outFile;
  191. outFile.open("results.txt");
  192.  
  193. string Movies[8]={"Action", "Comedy", "Drama", "Horro", "Mystery", "Romance", "Adventure", "Western"};
  194.  
  195.  
  196. for(i=0; i<8; i++)
  197. {
  198. outFile<<Movies[i]<<" Movies "<<endl;
  199. if (Genre[i].isEmpty())
  200. outFile<< "No Movies" <<endl;
  201. while(!Genre[i].isEmpty())
  202. {
  203. Genre[i].Dequeue(movie);
  204. movie.printMovieInfo(outFile);
  205. }
  206.  
  207.  
  208.  
  209. }
  210.  
  211.  
  212. outFile.close();
  213.  
  214.  
  215.  
  216.  
  217. return 0;
  218.  
  219. }
Add Comment
Please, Sign In to add comment