Advertisement
priscill4

help pls

Mar 9th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.73 KB | None | 0 0
  1. // MAIN CPP HAS THIS
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <vector>
  6. #include <cstdlib>
  7. #include <fstream>
  8. #include "Film.h"
  9.  
  10. using namespace std;
  11. int main(){
  12.     int id;
  13.     int start =0;
  14.     std::string name;
  15.     std::string description;
  16.     int runningTime;
  17.     std::string rating;
  18.     std::ifstream filmData;
  19.    
  20.     vector <Film> films;
  21.    
  22.     filmData.open("filmData.txt",std::ios::in);
  23.    
  24.     while(!filmData.eof()){
  25.        
  26.         filmData >> id;
  27.         filmData.ignore();
  28.         getline(filmData, name, ',');
  29.         getline(filmData, description, ',');
  30.         filmData >> runningTime;
  31.         filmData.ignore();
  32.         getline(filmData, rating, ',');
  33.         films.push_back(Film(id,name, description, runningTime, rating));
  34.         films[start].printData();
  35.         start++;
  36.     }
  37.    
  38.     filmData.close();
  39.     return 0;
  40.    
  41. }
  42.  
  43.  
  44. /// FILM HEADER HAS THIS
  45. #ifndef Film_H
  46. #define Film_H
  47. #include <iostream>
  48. #include <string>
  49.  
  50. using namespace std;
  51.  
  52.  
  53. enum FilmRating {G, PG, PG_13, NC_17, R, UNRATED};
  54.  
  55. class Film{
  56.  
  57. private:
  58.    
  59.     int id;
  60.     string name;
  61.     string description;
  62.     int runningTime;
  63.     string rating;
  64.     FilmRating movieRate;
  65.    
  66. public:
  67.    
  68.     Film(int id, string name, string description, int runningTime, string rating);
  69.    
  70.     Film (int id, string name, string description,int runningTime, FilmRating rating);
  71.    
  72.     int getId();
  73.    
  74.     string getName();
  75.    
  76.     void setName(string);
  77.    
  78.     string getDescription();
  79.    
  80.     void setDescription(string);
  81.  
  82.     int getRunningTime();
  83.    
  84.     void setRunningTime(int);
  85.    
  86.     string getRating();
  87.    
  88.     void setRating(FilmRating);
  89.    
  90.     void stringRatetoFilmRate(string);
  91.    
  92.     void printData();
  93.  
  94. };
  95.  
  96. #endif
  97.  
  98. // FILM.CPP HAS THIS
  99.  
  100.  
  101.  
  102. #include "Film.h"
  103.  
  104.  
  105. Film::Film(int anID, std::string aName, std:: string theDescription, int therunningTime, std::string aRating){
  106.     id = anID;
  107.     name =aName;
  108.     description = theDescription;
  109.     runningTime = therunningTime;
  110.     rating = aRating;
  111.     stringRatetoFilmRate(rating);
  112. }
  113.  
  114.  
  115. Film::Film(int id, std:: string name, std:: string description, int runningTime, FilmRating movieRate){
  116.    
  117.     setName(name);
  118.     setDescription(description);
  119.     setRunningTime(runningTime);
  120.     setRating(movieRate);
  121. }
  122.  
  123.  
  124.  
  125. int Film:: getId(){
  126.    
  127.     return id;
  128. }
  129.  
  130. string Film::getName(){
  131.    
  132.     return name;
  133. }
  134.  
  135. void Film::setName(string aName){
  136.    
  137.     name = aName;
  138. }
  139.  
  140.  
  141. string Film::getDescription(){
  142.    
  143.     return description;
  144. }
  145.  
  146.  
  147. void Film::setDescription(string theDescription){
  148.    
  149.     description = theDescription;
  150. }
  151.  
  152. int Film::getRunningTime(){
  153.    
  154.     return runningTime;
  155.    
  156. }
  157.  
  158. void Film::setRunningTime(int therunningTime){
  159.    
  160.     runningTime = therunningTime;
  161.    
  162. }
  163.  
  164.  
  165. std::string Film::getRating(){
  166.    
  167.     switch(movieRate){
  168.            
  169.         case 0:
  170.             return "G";
  171.             break;
  172.            
  173.         case 1:
  174.             return "PG";
  175.             break;
  176.            
  177.         case 2:
  178.             return "PG_13";
  179.             break;
  180.            
  181.         case 3:
  182.             return "R";
  183.             break;
  184.            
  185.         case 4:
  186.             return "NC-17";
  187.             break;
  188.            
  189.         case 5:
  190.             return "UNRATED";
  191.             break;
  192.     }
  193. }
  194.  
  195.  
  196.  
  197. void Film::setRating(FilmRating aRating){
  198.     movieRate = aRating;
  199. }
  200.  
  201.  
  202. void Film::stringRatetoFilmRate(std::string rating){
  203.    
  204.     if(rating == "G"){
  205.         movieRate = G;
  206.         }
  207.     else if(rating == "PG"){
  208.         movieRate = PG;
  209.         }
  210.     else if(rating == "PG-13"){
  211.         movieRate = PG_13;
  212.     }
  213.     else if(rating =="NC_17"){
  214.        
  215.         movieRate = NC_17;
  216.     }
  217.    
  218.     else if(rating == "R"){
  219.        
  220.         movieRate = R;
  221.     }
  222.     else if(rating == "UNRATED"){
  223.        
  224.         movieRate =UNRATED;
  225.     }
  226.  
  227. }
  228.  
  229.  
  230. void Film::printData(){
  231.        
  232.     cout << "ID: " << getId() << endl;
  233.         cout << "Name: " << getName() << endl;
  234.         cout << "Description: " << getDescription()  << endl;
  235.         cout << "Running Time: " << getRunningTime() << endl;
  236.         cout << "Rating: " << rating << endl;
  237.        
  238.        
  239.     };
  240.  
  241.  
  242. // FILM.TXT HAS THIS
  243.  
  244. 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,
  245. 1, 13 Going on 30,  Focuses on a teenage girl who travels to her future through a wish that comes true, 98, PG_13,
  246. 2, Deadpool, A fast-talking mercenary with a morbid sense of humor who ends up saving people, 108, R,
  247. 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