1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
void readFromfile(string filename, string title_arr[], int year_arr[], int& numberOfmovies);
void printScreen(string title_arr[], int year_arr[], int numberOfmovies);
void writeToFile(string filename, string title_arr[], int year_arr[], int numberOfmovies);
void sortNameAscendingBubble (string title_arr[], int year_arr[],int& numberOfmovies );
int search(string title_arr[], string target, int& numberOfmovies);
int main (){
bool done=false;
int menu;
const int MAXSIZE = 20;
string title[MAXSIZE], target;
int size=0;
int year[MAXSIZE];
while(!done){
cout<<"Select one of the options below\n";
cout<<"1. Read in Movies\n";
cout<<"2. List Titles, years to a screen.\n";
cout<<"3. List Titles, years to a file\n";
cout<<"4. Search Movies by Title\n";
cout<<"5. Sort Movies by Title\n";
cout<<"4. Exit\n";
cin>>menu;
switch(menu){
case 1:
cout<<"Read from file\n";
readFromfile("films.txt", title, year, size);
break;
case 2:
cout<<"Print to the Screen\n";
printScreen(title, year, size);
break;
case 3:
cout<<"Write to a file\n";
writeToFile("out.txt",title, year, size);
break;
case 4:
cout<<"Search Movies by Title\n";
readFromfile("films.txt", title, year, size);
search(title, target, size);
break;
case 5:
cout<<"Sort Movies by Title\n";
sortNameAscendingBubble (title, year, size);
printScreen(title, year, size);
break;
case 6:
cout<<"You will now exit menu.\n";
done=true;
break;
default:
cout<<"Invalid option.\n";
}
}
return 0;
}
int search(string title_arr[], string target, int& numberOfmovies) {
char reply;
string ans;
reply = toupper(reply);
do {
cout << "Which movie are you looking for?\n";
cin.ignore();
getline(cin, target);
for(int i=0; i<numberOfmovies; i++){
if (target== title_arr[i]){
cout<<"Title exists in list and is located at index: "<<i;
}
else
cout<<-1; }
cout << "Would you like to search for another title?\n";
cin>>reply;
} while (reply != 'n');
}
|