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
|
/** @file main.cpp */
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "ListP.h"
using namespace std;
void displayList( const List& a )
{
ListItemType content;
for ( int i = 1; i <= a.getLength(); ++i )
{
a.retrieve( i, content );
cout << content << "-->";
}
cout << "NULL" << endl;
}
void makeUnique( List& a )
{
// TODO: Begin question 3
ListItemType content;
for (int i = 1; i<=a.getLength(); ++i)
{
a.retrieve(i, content);
cout << content;
}
}
void Inquire(string titlename, List& a)
{
for (int i = 1; i <= a.getLength(); ++i)
{
ListItemType content;
a.retrieve(i, content);
if (titlename == content)
{
cout << "The searched movie title : " <<endl;
cout << "(DVD ID, Title, Year, Have, Wanted)" << endl;
cout << content;
}
//cout<< titlename;
}
}
void UserModify(string titlename, string newTitleName, List& a) //replace titlename with newTitleName
{
for (int i = 1; i <= a.getLength(); ++i)
{
a.retrieve(i, titlename);
// a.insert(i,newTitleName);
}
// for(int i = 1; i<=a.getLength(); ++i)
// {a.insert(i,newTitleName);}
for ( int i = 1; i <= a.getLength(); ++i )
{
ListItemType content;
a.retrieve( i, content );
cout << content << endl;
}
}
int main()
{
char choice;
bool done = false;
List alist;
do
{
cout << endl << endl << endl;
cout << " =======================================" <<endl;
cout << " - _ - _ - _ - _ - _ - _ - _ - _- _ - _ "<< endl;
cout << " --------------------------------------- " << endl;
cout << " 1. Add a record " << endl;
cout << " 2. Displays ALL records" << endl;
cout << " 3. Delete a record" << endl;
cout << " 4. Save records" << endl;
cout << " 7. display 1 record "<< endl;
cout << " R. Read inventory from file" << endl;
cout << " W. Read wait list file" << endl;
cout << " H. Help" << endl;
cout << " I. Inquire a titlename" << endl;
cout << " Q. Quit" << endl;
cout << " --------------------------------------- " << endl;
cout << " - _ - _ - _ - _ - _ - _ - _ - _- _ - _ "<< endl;
cout << " =======================================" <<endl;
cout << endl;
cout << " ==> ";
cin >> choice;
cin.ignore();
choice = toupper(choice);
ListItemType ch, content, maxContent;
string filename;
int recno = 1;
switch ( choice )
{
case '1' :
{
string dvdid, dvdtitle,dvdyear,dvdhave,dvdwanted,input;
int i = 1;
cout << "(insert ID, Title, Year, Have, Wanted)" <<endl;
cout << "DVD ID to add " <<endl;
getline(cin, dvdid);
cout << "DVD title to add " <<endl;
getline(cin, dvdtitle);
cout << "DVD year to add " <<endl;
getline(cin, dvdyear);
cout << "DVD have to add " <<endl;
getline(cin, dvdhave);
cout << "DVD wanted to add " <<endl;
getline(cin, dvdwanted);
input = dvdid + " " + dvdtitle + " " + dvdyear + " " + dvdhave + " " + dvdwanted;
cout << input;
alist.insert(i, input);
break;
}
case '3' :
cout << "Record number to erase => ";
cin >> recno;
alist.remove( recno );
break;
case '2' :
{
cout << "Data for ALL Records" << endl;
cout << "----------------------------" << endl;
for ( int i = 1; i <= alist.getLength(); ++i )
{
alist.retrieve( i, content );
cout << content <<endl;
}
cout << endl;
cout << "----------------------------" << endl;
ifstream file1; //Open DVD Inventory From file.
file1.open("dvdlist.txt");
string line;
cout << "[ List of the entire DVD Inventory ]";
while (!file1.eof())
{
getline(file1, line );
cout << line << endl;
}
ifstream file2; //Open DVD Inventory From file.
file2.open("waitlist.txt");
string line2;
cout << "[ List of the entire Wait List ]" << endl;
while (!file2.eof())
{
getline(file2, line2 );
cout << line2 << endl;
}
}
break;
case '4' :
{
ifstream file1;
cout << "Save records to? File name = ";
cin >> filename;
alist.save( filename );
break;
}
case '5' :
{
makeUnique(alist);
break;
}
case '6' :
{
string titlename, newTitleName;
cout << "The title that you want to modify: ";
getline(cin, titlename);
cout << "New Name For the Title: ";
getline(cin, newTitleName);
UserModify(titlename, newTitleName, alist);
break;
}
case '7' :
{
for ( int i = 1; i <= alist.getLength(); ++i )
{
cout << "Displaying " << i << " record" << endl ;
alist.retrieve( i, content );
cout << content << endl;
}
cout << endl;
break;
}
case 'H' : //help
cout << " 1. Add a record" << endl;
cout << " [Adding a new record]" << endl;
cout << endl;
cout << " 3. Remove a record from a position " << endl;
cout << " [Deletes a record from a position]" <<endl;
cout << endl;
cout << " 7. Display ALL records " << endl;
cout << " [Displays all records of waitlist,inventory list]" <<endl;
cout << endl;
cout << " 8. Save records to file " << endl;
cout << " [Save record to a file of your choice]" <<endl;
cout << endl;
cout << " H. Help" << endl;
cout << " [User Manual] " <<endl;
cout << endl;
cout << " R. Read inventory from file " << endl;
cout << " [Reads inventory a file of your choice] " <<endl;
cout << endl;
cout << " W. Read wait list file " << endl;
cout << " [Reads wait list file]" <<endl;
cout << endl;
cout << " Q. Quit" << endl;
cout << " [Quits the Program] " <<endl;
cout << endl;
break;
case 'R' : //Read dvd list from file
{
string NameOfTheFile;
ifstream file1;
cin >> NameOfTheFile;
file1.open(NameOfTheFile.c_str());
string line;
while (!file1.eof())
{
getline(file1, line );
cout << line << endl;
}
break;
}
case 'W': //waitlist
{
string NameOfTheFile;
ifstream file1;
cin >> NameOfTheFile;
file1.open(NameOfTheFile.c_str());
string line;
while (!file1.eof())
{
getline(file1, line );
cout << line << endl;
}
break;
}
case 'Q' : //Quit
done = true;
break;
case 'I' :
{
string titlename;
cout << "Enter movie title : ";
getline(cin, titlename);
Inquire(titlename, alist);
break;
}
default :
cout << "Invalid choice" << endl;
}
}
while ( !done );
cout << "Good Bye ! Thank you for using the program." << endl;
return 0;
}
| |