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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
int main()
{
videoListType videoList;
CustomerListType customerList;
int choice;
char ch;
string title;
string cName;
// code that reads input - works fine
displayMenu();
cout << "Enter your choice: ";
cin >> choice; //get the request
cin.get(ch);
cout << endl;
//process the requests
while (choice != 9)
{
switch (choice)
{
case 1:
cout << "Enter the title: ";
getline(cin, title);
cout << endl;
if (videoList.videoSearch(title))
cout << "The store carries " << title
<< endl;
else
cout << "The store does not carry "
<< title << endl;
break;
case 2: // This is for renting videos
cout << "Enter the title: ";
getline(cin, title);
cout << endl;
enterCustomer(cName);
if (videoList.videoSearch(title))
{
if (videoList.isVideoAvailable(title))
{
if (customerList.isCustomer(cName))
{
videoList.videoCheckOut(title);
cout << "case 2 " << title << endl;
customerList.videoRental(cName, title);
cout << "Enjoy your movie: " << title << endl;
}
}
else
cout << "Currently " << title
<< " is out of stock." << endl;
}
else
cout << "The store does not carry "
<< title << endl;
break;
// code for other cases
}//end switch
}
#ifndef H_CUSTOMERTYPE
#define H_CUSTOMERTYPE
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class CustomerType
{
public:
CustomerType();
void setCustomerType(string, int);
void addVideo(string);
string getName();
int getNumRentals();
vector<string> getVideosRented();
void rentVideo(string);
void returnVideo(string);
void printCustomerInfo();
bool checkCustomer(string);
bool operator==(const CustomerType&) const;
bool operator!=(const CustomerType&) const;
private:
string name;
int numRentals;
vector<string>videosRented;
};
#endif
void CustomerType::rentVideo(string v)
{
numRentals++;
cout << "rentVideo numRentals " << v << " " << numRentals << endl;
videosRented.push_back(v);
if (numRentals > 0)
{
for (int i=0; i < numRentals; i++)
{
cout << "Video " << i+1 << " is " << videosRented[i] << endl;
}
}
}
#ifndef H_CUSTOMERLISTTYPE
#define H_CUSTOMERLISTTYPE
#include <string>
#include "unorderedLinkedList.h"
#include "customerType.h"
using namespace std;
class CustomerListType:public unorderedLinkedList<CustomerType>
{
public:
bool isCustomer(string) const;
void videoRental(string, string) const;
void videoReturn(string, string);
void printCustomer(string) const;
void printCustomerList();
private:
bool searchCustomerList(string n, bool& found,
nodeType<CustomerType>* ¤t) const;
};
#endif
bool CustomerListType::searchCustomerList(string n, bool& found,
nodeType<CustomerType>* ¤t) const
{
found = false; //set found to false
current = first; //set current to point to the first node
//in the list
while (current != NULL && !found) //search the list
if (current->info.checkCustomer(n))
found = true;
else
current = current->link; //advance current to
//the next node
return found;
}//end searchVideoList
bool CustomerListType::isCustomer(string n) const
{
bool found;
nodeType<CustomerType> *location;
searchCustomerList(n, found, location);
return found;
}
void CustomerListType::videoReturn(string n, string title)
{
bool found = false;
nodeType<CustomerType> *location;
searchCustomerList(n, found, location); //search the list
if (found)
location->info.returnVideo(title);
else
cout << "Customer is not in the club.\n";
}
Customer text file which reads correctly:
John Smith
1
Titanic
Meg Ryan
0
Jane Doe
2
Sister Act
Rain Man
List of titles from another file (also reads correctly):
Video Title: Rain Man
Video Title: Jerry MacGuire
Video Title: Sister Act
Video Title: One Fine Day
Video Title: Titanic
Output of code (I do an example of a customer with a rental and the one without):
Select one of the following:
1: To check whether the store carries a particular video.
2: To check out a video.
3: To check in a video.
4: To check whether a particular video is in stock.
5: To print only the titles of all the videos.
6: To print a list of all the videos.
7: To print customer info.
8: To print a list of all the customers.
9: To exit
Enter your choice: 8
Customer name: Jane Doe
Number of rentals: 2
Video 1 is Titanic
Video 2 is Sister Act
Customer name: Meg Ryan
Number of rentals: 0
Customer name: John Smith
Number of rentals: 1
Video 1 is Titanic
Select one of the following:
1: To check whether the store carries a particular video.
2: To check out a video.
9: To exit
Enter your choice: 2
Enter the title: Sister Act
Enter customer name: Meg Ryan
check customer name Jane Doe n Meg Ryan
check customer name Meg Ryan n Meg Ryan
case 2 Sister Act
check customer name Jane Doe n Meg Ryan
check customer name Meg Ryan n Meg Ryan
in videoRental Sister Act
rentVideo numRentals Sister Act 1 /*this is in the CustomerType::rentVideo(string v) - v is correct */
Video 1 is Titanic /* same function but videoRentals is showing wrong video */
Enjoy your movie: Sister Act // back at main
Select one of the following:
7: To print customer info.
8: To print a list of all the customers.
9: To exit
Enter your choice: 7
Enter customer name: Meg Ryan
check customer name Jane Doe n Meg Ryan
check customer name Meg Ryan n Meg Ryan
Customer name: Meg Ryan
Number of rentals: 1
Video 1 is Titanic
Select one of the following:
1: To check whether the store carries a particular video.
2: To check out a video.
9: To exit
Enter your choice: 2
Enter the title: Sister Act
Enter customer name: John Smith
check customer name Jane Doe n John Smith
check customer name Meg Ryan n John Smith
check customer name John Smith n John Smith
case 2 Sister Act
check customer name Jane Doe n John Smith
check customer name Meg Ryan n John Smith
check customer name John Smith n John Smith
in videoRental Sister Act
rentVideo numRentals Sister Act 2
Video 1 is Titanic
Video 2 is Sister Act // here the video is correct
Enjoy your movie: Sister Act
Select one of the following:
7: To print customer info.
8: To print a list of all the customers.
9: To exit
Enter your choice: 7
Enter customer name: John Smith
check customer name Jane Doe n John Smith
check customer name Meg Ryan n John Smith
check customer name John Smith n John Smith
Customer name: John Smith
Number of rentals: 2
Video 1 is Titanic
Video 2 is Sister Act
Select one of the following:
1: To check whether the store carries a particular video.
2: To check out a video.
3: To check in a video.
4: To check whether a particular video is in stock.
5: To print only the titles of all the videos.
6: To print a list of all the videos.
7: To print customer info.
8: To print a list of all the customers.
9: To exit
Enter your choice: 9
Press any key to continue . . .
|