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
|
/*----------------------------------------------------------------------
- program2.cpp -
----------------------------------------------------------------------*/
#include <iostream>
#include <string>
#include <fstream>
#include "linkedlist.h"
#define ignore cin.ignore();
using namespace std;
typedef std::string KeyType;
void menu();
void loader();
int main(int argc, char *argv[])
{
char choice;
bool menuFlag;
//string key;
//string name;
//string title;
LinkedList l;
KeyType findKey;
KeyType addKey;
KeyType rmKey;
Articles s;
Articles temp;
cout << "Loading library please wait.";
fflush(stdout);
sleep(1);
cout << ".";
fflush(stdout);
sleep(1);
cout << ".";
sleep(1);
puts(".");
cout << endl;
fstream inFile(argv[1]);
if (inFile.is_open())
{
while (!inFile.eof())
{
getline (inFile,s.key);
getline (inFile,s.name);
getline (inFile,s.title);
if (s.key >= " ")
l.insert(s);
}
inFile.close();
}
else
{
cout << "Unable to open file";
}
loader();
cout << "Hello to the CACM Library!" << endl;
menu();
menuFlag = true;
while (menuFlag)
{
cout << "\nYour Choice:";
cin >> choice;
cout << endl;
if (choice == 'f' || choice == 'F')
{
cout << "You have chosen to search for an article" << endl; //-----!!Remove when complete!!-----//
cout << "\nPlease enter your search key: ";
getline(cin, findKey);
if (l.find(findKey,temp))
{
cout << endl; //no error.
menu();
}
else if (!l.find(findKey,temp)) //key not found
{
cout << "---------------------------------------------------------" << endl;
cout << "- Sorry, but there are no records matching your query. -" << endl;
cout << "---------------------------------------------------------" << endl << endl;
menu();
}
cout << "\n" << endl;
menu();
}
else if (choice == 'l' || choice == 'L')
{
l.display();
cout << endl;
menu();
cout << "\n" << endl;
menu();
}
else if (choice == 'a' || choice == 'A')
{
ignore;
cout << "Enter the key for your new article:";
getline(cin, addKey);
if (l.find(addKey,s))
{
cout << "Article key already exists! Choose another key." << endl;
menu();
}
else if (!l.find(addKey,s))
{
s.key = addKey;
cout << endl << "Enter the author's name:";
cin >> s.name;
cout << endl << "Enter the title of the article:";
cin >> s.title;
l.insert(s);
cout << endl;
cout << "------------------------------------------" << endl;
cout << "- The following record has been ADDED -" << endl;
cout << "- -" << endl;
cout << "- Key: " << s.key << " -" << endl;
cout << "- Title: " << s.title << " -" << endl;
cout << "- Author: " << s.name << " -" << endl;
cout << "-----------------------------------------*" << endl;
menu();
}
cout << endl;
cout << "\n" << endl;
menu();
}
else if (choice == 'r' || choice == 'R')
{
cout << "You have chosen to remove an article" << endl; //-----!!Remove when complete!!-----//
cout << "\nEnter the key for the article that you want to remove: ";
getline(cin, rmKey);
if (!l.erase(rmKey))
{
cout << "----------------------------------------------------------------------" << endl;
cout << "- Sorry, record not removed because it was not found in the database -" << endl;
cout << "----------------------------------------------------------------------" << endl;
menu();
}
else
{
l.erase(rmKey);
cout << "-----------------------------------------------------" << endl;
cout << "- The following record has been REMOVED -" << endl;
cout << "- -" << endl;
cout << "- Key: " << rmKey << " -" << endl;
cout << "-----------------------------------------------------" << endl;
menu();
}
cout << endl;
menu();
}
else if (choice == 'e' || choice == 'E')
{
cout << "Thank you for using the CACM Library!" << endl;
menuFlag=false;
}
else
{
cout << "Invalid Choice." << endl;
menu();
}
}
return 0;
}
void loader()
{
return;
}
void menu()
{
cout << "\nWhat would you like to do?" << endl;
cout << "\n(F)ind an article" << endl
<< "(L)ist all articles" << endl
<< "(A)dd a new article" << endl
<< "(R)emove an existing article" << endl
<< "(E)xit" << endl;
}
| |