1 //File: cla15.cpp 2 //Programmer: 3 //Class: CSCI 2170 4 // 5 //This program reads and prints information related to videos 6 //owned by Movie Rent Video Store. 7 // 8 //The program reads data from the data files, cla15.dat and 9 //cla15b.dat. The data in cla15.dat contains information about 10 //videos including the name of a video, the number of copies of a 11 //particular video, and the video type. You will add code to this 12 //program to read information about the video store's customers 13 //from cla15.dat. 14 // 15 //The user is allowed to select from a menu of options that includes: 16 // 1) Print a list of all videos owned by the Movie Rent Video Store 17 // 2) Print a list of all customers 18 // 3) Print out a list of rental information by video titles 19 // 0) Exit this program 20 21 #include 22 #include 23 #include 24 #include 25 using namespace std; 26 27 //maximum number of videos owned by the store 28 const unsigned int MAX_VIDEOS = 100; 29 30 //maximum number of customers 31 const unsigned int MAX_CUSTOMERS = 20; 32 33 //Definition of a Video structure 34 struct Video 35 { 36 string movieTitle; //name of movie 37 unsigned int numberCopies; //number of copies 38 string videoType; //type of video 39 }; 40 41 //Definition of a customerType structure 42 struct customerType 43 { 44
//Exercise 3 goes here 45 }; 46 47 //function prototypes 48 int menuSelection(); 49 void getVideo (Video&, ifstream&); 50 void printVideo (Video); 51 void getCustomer(customerType&, ifstream&); 52 void printCustomer(customerType); 53 void printRentalInfo(customerType[], string , int); 54 bool numberInSet(int x); 55 56 int main () 57 { 58 //variables 59 Video videoInfo; //used to read in video information 60 Video allVideos[MAX_VIDEOS]; //an array of videos owned by the store 61
//Exercise 3 goes here //one customer's check out information 62 //Exercise 5 goes here //array of customer check out info 63 64 ifstream videoIn; //input stream for video information 65 ifstream customerIn; //input stream for customer info 66 int numVideos=0; //how many videos? 67 int numCustomers=0; //how many customers? 68 int choice; //user's menu choice 69 70 //open the files and check for file failure 71 videoIn.open ("cla15.dat"); 72 if (!videoIn) 73 { 74 cerr << "cla15.dat could not be opened!"; 75 exit (0); 76 } 77 customerIn.open("cla15b.dat"); 78 if (!customerIn) 79 { 80 cerr << "cla15b.dat could not be opened!"; 81 exit (0); 82 } 83 84 //input all videos owned by the video store 85 getVideo(allVideos[numVideos], videoIn); 86 while (videoIn) 87 { 88 numVideos++; 89 getVideo(allVideos[numVideos], videoIn); 90 } 91 92 //getCustomer(allCustomers[numCustomers], customerIn); 93 //while (customerIn) 94 { 95 //printCustomer(allCustomers[numCustomers]); 96 numCustomers++; 97 //getCustomer(allCustomers[numCustomers], customerIn); 98 } 99 100 101 //get the user's choice from the menu 102 choice = menuSelection(); 103 104 //loop until the user decides to quit 105 while (choice != 0) 106 { 107 switch (choice) 108 { 109 //print all videos owned by the store 110 case 1: 111 for (int i=0; i< numVideos; i++) 112 printVideo(allVideos[i]); 113 break; 114 /* === 115 //print all store customers 116 case 2: 117 for (int j=0; j< numCustomers; j++) 118 printCustomer(allCustomers[j]); 119 break; 120 //print out a list of rental information by video titles 121 case 3: 122 for (int k=0; k< numVideos; k++) 123 { 124 printVideo(allVideos[k]); 125 printRentalInfo(allCustomers, 126 allVideos[k].movieTitle,numCustomers); 127 } 128 break; 129 === */ 130 }; 131 choice = menuSelection(); 132 } 133 return 0; 134 } 135 136 //This method prints a menu, gets the user's selection and returns it. 137 int menuSelection() 138 { 139 int choice; //the user's menu selection 140 141 //print the menu and make the user enter a valid menu selection 142 do 143 { 144 cout <<" Welcome to Movie Rent Video Store Information"; 145 cout <<" 1----Print out list of all owned videos"; 146 cout <<" 2----Print out list of all customers"; 147 cout <<" 3----Print out list of rental information by video titles"; 148 cout <<" 0----Exit this program"; 149 cout <<" Please enter choice and hit :"; 150 cin >> choice; 151 } 152 while (!numberInSet(choice)); 153 return choice; 154 } 155 156 //This function determines whether the argument x is in 157 //a valid range. If it is, true is returned; otherwise 158 //return false. 159 bool numberInSet(int x) 160 { 161 if ( x>3 || x< 0) 162 return false; 163 else 164 return true; 165 } 166 167 //This function reads information about a video from the file 168 //myIn. 169 void getVideo (Video& oneVideo, ifstream& myIn) 170 { 171 char endOfLine; //used to remove the end of line character 172 173 //get the video information 174 getline(myIn, oneVideo.movieTitle); 175 myIn >> oneVideo.numberCopies; 176 myIn.get(endOfLine); 177 getline (myIn, oneVideo.videoType); 178 } 179 180 //Print out the information about a video. 181 void printVideo (Video oneVideo) 182 { 183 cout
//Exercise 4 goes here 193 } 194 195 //This function receives an array of check out information for 196 //all customers, the title of a movie that has been checked out, 197 //and the number of customers. The function prints a list of all 198 //the names of customers who have rented the video indicated in 199 //the movie title. 200 void printRentalInfo (customerType people[], string title, int numCustomers) 201 { 202
//Exercise 7 goes here 203 } 204 205 //This function prints one person's check out information. 206 void printCustomer(customerType person) 207 { 208
//Exercise 8 goes here 209 } =====================================================================
1 James W. Wilson 2 1113 3 A Bridge Too Far 4 11/19/95 5 Wanda T. Bear 6 1114 7 A Bridge Too Far 8 11/19/95 9 Linda W. Smith 10 1115 11 The Man in White 12 11/20/95 13 Carol M. Brown 14 1117 15 All the Robots 16 11/20/95 17 Franklin D. Russell 18 1118 19 The Man in White 20 11/21/95
=====================================================================
1 A Bridge Too Far 2 10 3 mystery 4 The Cat and Mouse 5 5 6 comedy 7 Today is Night 8 20 9 adventure 10 The Movie Factor 11 19 12 musical 13 All the Robots 14 20 15 horror 16 The Sand 17 5 18 adventure 19 My Name is Sue 20 14 21 comedy 22 Why Me? 23 2 24 mystery 25 The Man in White 26 17 27 musical
===================================================
name of customer (string)
id number of customer (integer)
name of video rented by the customer (a string)
return date of the video ( a string)
Exercise 3: Using the above struct declaration as a guide, show code to set up a struct called customerType that will have fields for a customer's name, the customer's id number (integer), the title of the movie/video rented, and when the video is to be returned. Also declare a variable customer of the type customerType. Insert this code into the two positions indicated by comments in the cla15.cpp program.
====================================================
Exercise 4: Add code to read values for the variable customer described in exercise 3. This is accomplished by a call to the function getCustomer(). Complete the function getCustomer() so that it will read values for one customer from the indicated input file stream. Include this code in the indicated position of the cla15.cpp program.
==============================================
Exercise 5 Add code to the cla15.cpp program to define a variable called allCustomers that will store information contained in the cla15b.dat file for as many as 20 customers as described in Exercise 4.
==============================================================
Exercise 6: Write code to print out the id number of the second customer included in the allCustomers array as described in exercise 5. Place your answer on the answer sheet.
==============================================
Exercise 7: Add code to the stub function called printRentalInfo (at the indicated position inside cla15.cpp) so that it will receive the allCustomers array defined in Exercise 5, a movie title, and the number of customers, and will print out a list of all the names of customers who have rented the video indicated in the movie title sent to the function.
====================================================
Exercise 8: Now complete the Movie Rent Video Store program. Add code to the stub function called printCustomer (at the indicated position inside cla15.cpp) that will receive one struct of type customerType and will print out all information related to this customer (name, id, name of video rented, and return date of video).