Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MovieType.cpp
- #include<iostream> // library
- #include"movieType.h" // including movietype.h
- #include<fstream>// library for read the file
- #include<string>
- using namespace std; // library
- movieType::movieType () {} // constructor the movietype
- bool movieType::readMovieInfo(ifstream& inFile) // function to read in the file
- {
- //Get rank
- inFile>>rank;
- if(rank>=1) //Checks to see if rank is valid
- {
- inFile>>weight;//Reads and Stores weight
- inFile>>year;//Reads and Stores year
- inFile>>votes;//Reads and Stores votes
- inFile>>genre;//Reads and Stores genre
- inFile>>length;//Reads and Stores length
- getline (inFile, name);
- return true; //Returns Success
- }
- else //Terminates if less than 1.
- return false;
- }
- void movieType::printMovieInfo(ofstream& outFile) // function to print in the file
- {
- outFile<<rank<<" "<<year<<" "<<genre<<" "<<length<<" "<<" "<<weight<<" "<<votes<<" "<<name<<endl;//prints the info to the file.
- }
- char movieType::getGener() // function to get the genre and put it in order
- {
- return genre;
- }
- int movieType::getRank() // function to get the rank and categorize the info
- {
- return rank;
- }
- bool movieType::operator>(movieType check2) const // bool function for the rank
- {
- if (rank > check2.rank) // checks if rank is < other rank
- return true;
- else
- return false;
- }
- bool movieType::operator>=(movieType check) const // bool function for the rank
- {
- if(rank >= check.rank)//checks if rank is <= the other rank
- return true;
- else
- return false;
- }
- movieType::~movieType () {}; //distructor
- main.cpp
- #include<iostream>
- #include<string>
- #include<fstream>
- //#include "QueueType.h" //includ the stack .h file for the stack
- #include"QueueType.h"
- #include"movieType.h"
- typedef movieType ItemType;
- #include "PQType.h"
- using namespace std;
- int main()
- {
- PQType<movieType> MType = PQType<movieType>(50);
- movieType movie;
- bool flag = true;
- ifstream inFile;
- inFile.open("movie1.txt");
- while(flag&&inFile.is_open())
- {
- flag=movie.readMovieInfo (inFile);
- if (flag)
- MType.Enqueue(movie);
- }
- inFile.close();
- QueType<movieType> GType;
- QueType<movieType> Genre [8];
- int i;
- for(i=0; i<8; i++)
- {
- Genre[i]=GType;
- }
- while(!MType.IsEmpty())
- {
- MType.Dequeue(movie);
- switch (movie.getGener () )
- {
- case 'A':
- Genre[0].Enqueue(movie);
- break;
- case 'C':
- Genre[1].Enqueue(movie);
- break;
- case 'D':
- Genre[2].Enqueue(movie);
- break;
- case 'H':
- Genre[3].Enqueue(movie);
- break;
- case 'M':
- Genre[4].Enqueue(movie);
- break;
- case 'R':
- Genre[5].Enqueue(movie);
- break;
- case 'V':
- Genre[6].Enqueue(movie);
- break;
- case 'W':
- Genre[7].Enqueue(movie);
- break;
- }
- }
- ofstream outFile;
- outFile.open("results.txt");
- string Movies[8]={"Action", "Comedy", "Drama", "Horro", "Mystery", "Romance", "Adventure", "Western"};
- for(i=0; i<8; i++)
- {
- outFile<<Movies[i]<<" Movies "<<endl;
- if (Genre[i].isEmpty())
- outFile<< "No Movies" <<endl;
- while(!Genre[i].isEmpty())
- {
- Genre[i].Dequeue(movie);
- movie.printMovieInfo(outFile);
- }
- }
- outFile.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment