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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
struct webType
{
string ip;
string url;
string command;
int counter;
};
typedef webType infoType;
struct nodeType
{
infoType info;
nodeType* link;
};
void heading (ofstream&);
void print(nodeType*);
void printOne(webType one);
void display (nodeType *box);
void add (ifstream& add_to, nodeType *& list);
void change (ifstream& fin, nodeType *& list);
//void search (nodeType *box);
//Start of main
int main()
{
nodeType *list, *box, *first;
string filename, command;
ifstream inFile;
ofstream outFile; //declares the output file
heading (outFile);
cout << "\nEnter the name of the input file: ";
cin >> filename;
cout << "\n--------------------------------------------------------\n";
inFile.open(filename.c_str());
outFile.open("Bass.txt");
if (!inFile)
{
cout << "ERROR!!!! INPUT FILE NOT FOUND!!!!!!!\n\n";
system("PAUSE");
return 1;
}
print(first);
box=NULL;
inFile >>command;
while (inFile)
{
if(command == "Add")
{
cout<<"Adding to the list"<<endl;
add ( inFile, box);
}
else if(command == "Change")
{
cout<<"Changing the list"<<endl;
change (inFile, box);
}
else if(command == "Eliminate")
{
cout<<"Eliminating from list"<<endl;
}
else if(command == "Search")
{
cout<<"Searching the list"<<endl;
// search (box) ;
}
else if (command == "Display")
{
cout<<"Displaying the list"<<endl;
display (box);
system("PAUSE");
}
inFile>>command;
}
system("PAUSE");
return 0;
}
//========================================================================
//prints the heading
void heading (ofstream&outFile)
{
cout << "===================================================" << endl;
cout << "FLY-BY-NIGHT-ENGINEERING URL,IP,WEB INFO MANAGER" << endl;
cout << "===================================================" << endl << endl;
cout<<"Source file : Bass_b_Prj5.cpp"<<endl;
outFile<<"Source file : Bass_b_Prj5.cpp"<<endl;
cout<<"Programmed by: Brent Bass"<<endl;
outFile<<"Programmed by: Brent Bass"<<endl;
cout<<"Date: 4/17/2011"<<endl;
outFile<<"Date: 4/17/2011"<<endl;
cout<<"Lab CRN 26682"<<endl << endl;
outFile<<"Lab CRN 26682"<<endl << endl;
}
//========================================================================
/* print displays the members of each element of the
linked list of structures of type nodeType; the formal parameter
first points to the first node in the list.
*/
void print(nodeType *first)
{
nodeType *current;
current = first;
while (current != NULL)
{
printOne ( current->info);
cout << endl;
current = current->link;
}
cout << endl;
}
//==============================================================================
void printOne ( webType one)
{
cout << "URL: " << one.url << endl;
cout << "IP ADDRESS: " <<one.ip << endl;
if ( one.command == "search" || one.command == "change")
{
cout << "COUNTER = " << one.counter << endl;
}
}
//==============================================================================
void display (nodeType *box)
{
nodeType *current;
current = box;
while (current != NULL)
{
printOne ( current->info);
cout << endl;
current = current->link;
}
cout << endl;
}
//==============================================================================
void add (ifstream& add_to, nodeType *& list)
{
nodeType *current;
webType data;
current = new nodeType;
int counter = 0;
//webType temp
add_to>>data.url>>data.ip;
current->info = data;
current->link = list;
list = current;
}
//==============================================================================
void change(ifstream& fin, nodeType *& list)
{
nodeType *current;
webType data;
fin>>data.url>>data.ip;
current=list;
while (current != NULL)
{
if ( current->info.url == data.url )
{
current->info.ip = data.ip;
current->info.counter++;
}
current =current->link;
}
}
/*void search (nodeType *box)
// search function...
{
box->info.counter++;
cout << "Domain Name: " << box->info.url << endl
<< "IP Number: " << box->info.ip << endl
<< "Counter is now " << box->info.counter << "\t";
}
void eliminate(ifstream& fin, nodeType *& list)
{
nodeType *current;
webType data;
current=list
while (current != NULL)
{
current =current->link
}
void eliminate (nodeType *&HEAD, nodeType *targetNode)
// eliminate function...
{
nodeType *backNode;
if (targetNode == HEAD)
// if the target node is the first node in the sequence
// 1. instruct the head to point to the second node of the sequence
// 2. delete the target node
{
HEAD = targetNode->LINK; // number 1
delete targetNode; // number 2
}
else
{
backNode = HEAD;
while (backNode->LINK != targetNode)
backNode = backNode->LINK;
backNode->LINK = targetNode->LINK;
delete targetNode;
}
}
*/
|