Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MAIN CPP HAS THIS
- #include <iostream>
- #include <string>
- #include <vector>
- #include <cstdlib>
- #include <fstream>
- #include "Film.h"
- using namespace std;
- int main(){
- int id;
- int start =0;
- std::string name;
- std::string description;
- int runningTime;
- std::string rating;
- std::ifstream filmData;
- vector <Film> films;
- filmData.open("filmData.txt",std::ios::in);
- while(!filmData.eof()){
- filmData >> id;
- filmData.ignore();
- getline(filmData, name, ',');
- getline(filmData, description, ',');
- filmData >> runningTime;
- filmData.ignore();
- getline(filmData, rating, ',');
- films.push_back(Film(id,name, description, runningTime, rating));
- films[start].printData();
- start++;
- }
- filmData.close();
- return 0;
- }
- /// FILM HEADER HAS THIS
- #ifndef Film_H
- #define Film_H
- #include <iostream>
- #include <string>
- using namespace std;
- enum FilmRating {G, PG, PG_13, NC_17, R, UNRATED};
- class Film{
- private:
- int id;
- string name;
- string description;
- int runningTime;
- string rating;
- FilmRating movieRate;
- public:
- Film(int id, string name, string description, int runningTime, string rating);
- Film (int id, string name, string description,int runningTime, FilmRating rating);
- int getId();
- string getName();
- void setName(string);
- string getDescription();
- void setDescription(string);
- int getRunningTime();
- void setRunningTime(int);
- string getRating();
- void setRating(FilmRating);
- void stringRatetoFilmRate(string);
- void printData();
- };
- #endif
- // FILM.CPP HAS THIS
- #include "Film.h"
- Film::Film(int anID, std::string aName, std:: string theDescription, int therunningTime, std::string aRating){
- id = anID;
- name =aName;
- description = theDescription;
- runningTime = therunningTime;
- rating = aRating;
- stringRatetoFilmRate(rating);
- }
- Film::Film(int id, std:: string name, std:: string description, int runningTime, FilmRating movieRate){
- setName(name);
- setDescription(description);
- setRunningTime(runningTime);
- setRating(movieRate);
- }
- int Film:: getId(){
- return id;
- }
- string Film::getName(){
- return name;
- }
- void Film::setName(string aName){
- name = aName;
- }
- string Film::getDescription(){
- return description;
- }
- void Film::setDescription(string theDescription){
- description = theDescription;
- }
- int Film::getRunningTime(){
- return runningTime;
- }
- void Film::setRunningTime(int therunningTime){
- runningTime = therunningTime;
- }
- std::string Film::getRating(){
- switch(movieRate){
- case 0:
- return "G";
- break;
- case 1:
- return "PG";
- break;
- case 2:
- return "PG_13";
- break;
- case 3:
- return "R";
- break;
- case 4:
- return "NC-17";
- break;
- case 5:
- return "UNRATED";
- break;
- }
- }
- void Film::setRating(FilmRating aRating){
- movieRate = aRating;
- }
- void Film::stringRatetoFilmRate(std::string rating){
- if(rating == "G"){
- movieRate = G;
- }
- else if(rating == "PG"){
- movieRate = PG;
- }
- else if(rating == "PG-13"){
- movieRate = PG_13;
- }
- else if(rating =="NC_17"){
- movieRate = NC_17;
- }
- else if(rating == "R"){
- movieRate = R;
- }
- else if(rating == "UNRATED"){
- movieRate =UNRATED;
- }
- }
- void Film::printData(){
- cout << "ID: " << getId() << endl;
- cout << "Name: " << getName() << endl;
- cout << "Description: " << getDescription() << endl;
- cout << "Running Time: " << getRunningTime() << endl;
- cout << "Rating: " << rating << endl;
- };
- // FILM.TXT HAS THIS
- 0, Star Wars: A New Hope, The Imperial Forces hold Princess Leia hostage in their effort to quell the rebellion against the Galactic Empire, 125, PG_13,
- 1, 13 Going on 30, Focuses on a teenage girl who travels to her future through a wish that comes true, 98, PG_13,
- 2, Deadpool, A fast-talking mercenary with a morbid sense of humor who ends up saving people, 108, R,
- 3, IT, A shape-shifting evil that emerges from the sewer to prey on the towns children, 148, R
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement