Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iostream>
  5.  
  6. #include "./netflix.h"
  7. #include "./movie.h"
  8.  
  9. /*
  10. using std::cout;
  11. using std::endl;
  12. using std::cin;
  13. using std::string;
  14. using std::fstream;
  15. using std::ofstream;
  16. using std::ifstream;*/
  17. using namespace std;
  18.  
  19. movie enter_movie(int);
  20. void find_movie();
  21.  
  22. int main(){
  23.  
  24.     //Find the number of lines in the thing
  25.     //(Check how many they want to add)
  26.     //Make the netflix object with the array
  27.  
  28.     char current_num[256];
  29.     for(int f=0;f<256;f++){
  30.         current_num[f]='\0';
  31.     }
  32.  
  33.     ofstream database;
  34.     //getline(myfile,bl,'|')
  35.     database.open("netflix.dat",fstream::app);//for writing
  36.     //database<<"\n";
  37.  
  38.     ifstream read_data;
  39.     read_data.open("netflix.dat",ifstream::in);
  40.  
  41.  
  42.     if(read_data.is_open()){
  43.         while(read_data.good()){
  44.             read_data.getline(current_num,100,'|');
  45.             for(int d=0;d<20;d++)
  46.                 cout<<current_num[d]<<endl;;
  47.         }
  48.         database.close();
  49.     }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.     //check_length();
  60.     int movies2add;
  61.     int enterorfind;
  62.     cout<<"Do you want to enter a movie to the database or find a movie to rent?";
  63.     cout<<" (1 - enter, 2 - find, or 0 - exit) ";
  64.     cin>>enterorfind;
  65.  
  66.     if(enterorfind==1){
  67.         cout<<endl<<"How many movies do you want to enter to the database? ";
  68.         cin>>movies2add;
  69.         //netflix net_data;
  70.         movie to_add = enter_movie(movies2add);
  71.     }
  72.  
  73.     if(enterorfind==2){
  74.         //Find movie
  75.         find_movie();
  76.     }
  77.  
  78.  
  79.     if(enterorfind==0){
  80.         //Quit
  81.         return 0;
  82.     }
  83. }
  84.  
  85. movie enter_movie(int i){
  86.     string movie_name, movie_rating, movie_castmem;
  87.     int movie_stars, movie_castnum, movie_copies, movies2add;
  88.     string *cast;   //This is a dynamic array of strings
  89.     movie temp_movie;
  90.  
  91.     for(int i=0;i<movies2add;i++){
  92.  
  93.         cout<<"Enter the name of your movie: ";
  94.         cin>>movie_name;
  95.         temp_movie.set_name(movie_name);
  96.  
  97.         cout<<"How many stars? ";
  98.         cin>>movie_stars;
  99.         temp_movie.set_stars(movie_stars);
  100.  
  101.         cout<<"How many cast members? ";
  102.         cin>>movie_castnum;
  103.         temp_movie.set_num_cast(movie_castnum);
  104.  
  105.         cast = new string[movie_castnum];
  106.  
  107.         for(int j=0;j<movie_castnum;j++){
  108.             cout<<"Enter cast member "<<j+1<<": ";
  109.             cin>>movie_castmem;
  110.             cast[j]=movie_castmem;
  111.         }
  112.         temp_movie.set_cast(cast);
  113.  
  114.         cout<<"Enter the movie rating: ";
  115.         cin>>movie_rating;
  116.         temp_movie.set_rating(movie_rating);
  117.  
  118.         cout<<"How many copies of this movie: ";
  119.         cin>>movie_copies;
  120.         temp_movie.set_copies(movie_copies);
  121.         cout<<endl;
  122.  
  123.         cout<<"Added to the database!"<<endl<<endl;
  124.         return temp_movie;
  125.     }
  126. }
  127.  
  128. void find_movie(){
  129.     string movie_name, movie_rating, movie_castmem;
  130.     int movie_stars, movie_castnum, search_type, movie_copies, movies2add;
  131.  
  132.     cout<<"Do you want to find movies based on: 1 - name, 2 - number of stars, 3 - specific cast member, or 4 - rating)? ";
  133.     cin>>search_type;
  134.  
  135.     switch(search_type){
  136.         case 1:
  137.             cout<<endl<<"What is the title? ";
  138.             cin>>movie_name;
  139.         case 2:
  140.             cout<<endl<<"How many stars? ";
  141.             cin>>movie_stars;
  142.         case 3:
  143.             cout<<endl<<"Who is the cast member? ";
  144.             cin>>movie_castmem;
  145.         case 4:
  146.             cout<<endl<<"What is the rating? ";
  147.             cin>>movie_rating;
  148.         default:
  149.             cout<<endl<<"That isn't an option..."<<endl;
  150.         }
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement