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 <string>
#include <iomanip>
#include <cmath>
using namespace std;
struct domList
{
string domName;
string ipAddress;
int counter;
};
void insertOne(domList list[], ifstream& inFile, int len);
void change(domList list[], string dName, string IpNum, int len);
void Delete(domList list[], string dName, int& lengthList);
void Find(domList list[], string dName, int len);
void Print (domList list[], int len);
void Quit (domList list[], int len);
void topDom(domList list[], int len);
int main (){
char command;
domList list[100];
int listLength = 0;
string ipNum, DomName;
int counter = 0;
bool x;
ifstream dataFile;
//stores the name of the dataFile
string dataFile1;
cout << "Please enter the data file you wish to use: ";
cin >> dataFile1;
dataFile.open (dataFile1.c_str());
if (!dataFile)
{
cout << "bummer file\n\n";
system ("pause");
return 1;
}
while(!dataFile.eof()){
dataFile >> command;
if(command == 'A')
{
insertOne(list, dataFile, listLength);
listLength++;
}
else if(command == 'M')
{
change(list, DomName, ipNum, listLength);
}
else if(command == 'D')
{
Delete(list, DomName, listLength);
listLength--;
}
else if(command == 'F')
{
Find(list, DomName, listLength);
}
else if(command == 'P')
{
Print(list, listLength);
}
else if(command == 'Q')
{
Quit(list, listLength);
Print(list, listLength);
}
}
dataFile.close();
cout << endl << endl << endl;
topDom(list, listLength);
int high = list[0].counter;
for (int i = 1; i < listLength; i++)
{
if(list[i].counter > high)
{
high = list[i].counter;
}
}
cout << "The domain with the highest counter is: "
<< high << endl;
ofstream out;
out.open("info.txt");
for (int i = 0; i < listLength; i++)
{
out << setw(23) << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
out << "Programmed By: Jack Davis" << endl;
out << "Date: 11/11/2011" << endl;
out << "Lab CRN: 10942" << endl;
out.close();
system("pause");
return 0;
}
void insertOne(domList list[], ifstream& inFile, int len)
{
domList one;
inFile >> one.domName >> one.ipAddress;
one.counter = 0;
list[len] = one;
}
void change(domList list[], string dName, string IpNum, int len)
{
for(int i = 0; i < len; i++)
{
if(list[i].domName == dName)
{
list[i].ipAddress = IpNum;
list[i].counter += 1;
}
}
}
void Delete(domList list[], string dName, int& lengthList)
{
for(int i = 0; i < lengthList; i++)
{
if(list[i].domName == dName)
{
for(int l = i; l < lengthList; l++)
{
list[l] = list[l+1];
lengthList--;
}
}
}
}
void Find(domList list[], string dName, int len)
{
for (int i = 0; i < len; i++)
{
if (list[i].domName == dName)
{
cout << "The ip Address for " << list[i].domName
<< " is " << list[i].ipAddress << endl;
list[i].counter += 1;
}
}
}
void Print (domList list[], int len)
{
cout << "\n\n\nPrinting" << endl;
for (int i = 0; i < len; i++)
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
void Quit (domList list[], int len)
{
domList one, two;
int min, temp;
for(int i = 0; i < len; i++)
{
min = i;
for(int l = 1; l < len; l++)
{
if(list[l].domName.substr(5,5) < list[i].domName.substr(5,5))
min = l;
}
one = list[i];
list[i] = list[min];
list[min] = one;
}
}
void topDom(domList list[], int len)
{
int edu, com, org, net, largest;
string highest;
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "edu")
edu++;
else if(list[i].domName.substr(len-3, len) == "com")
com++;
else if(list[i].domName.substr(len-3, len) == "org")
org++;
else if(list[i].domName.substr(len-3, len) == "net")
net++;
}
if(edu > com && edu > org && edu > net)
{
cout << ".edu is the most popular domain with " << edu << endl;
cout << "List of .edu domains";
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "edu")
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
}
else if(com > edu && com > org && com > net)
{
cout << ".com is the most popular domain with " << edu << endl;
cout << "List of .com domains";
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "com")
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
}
else if(org > edu && org > com && org > net)
{
cout << ".org is the most popular domain with " << edu << endl;
cout << "List of .org domains";
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "org")
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
}
else if(net > edu && net > com && net > org)
{
cout << ".net is the most popular domain with " << edu << endl;
cout << "List of .net domains";
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "net")
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
}
}
|