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
|
#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);
int main (){
char command;
domList list[NULL];
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){
dataFile >> command >> DomName >> ipNum;
switch(command){
case 'A':
insertOne(list, dataFile, listLength);
listLength++;
break;
case 'M':
change(list, DomName, ipNum, listLength);
break;
case 'D':
Delete(list, DomName, listLength);
listLength--;
default:
cout << "Enter a valid command." << endl;
}
}
}
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 << list[i].ipAddress << endl;
}
}
}
|