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
|
#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 modify(domList list[], string dName, string IpNum);
void Delete(domList list[], string dName);
int main (){
char command;
domList list[NULL];
int listLength = 0;
string ipNum, DomName;
int counter = 0;
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 >> DomName >> ipNum;
switch(command){
case 'A':
insertOne(list, dataFile, listLength);
listLength++;
break;
case 'M':
modify(list, DomName, ipNum);
break;
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)
{
for(int i = 0; i < list.length(); i++)
{
if(list[i].domName == dName)
{
list[i].ipAddress = IpNum;
list[i].counter += 1;
}
}
}
void Delete(domList list[], string dName)
{
for(int i = 0; i < list.length(); i++)
{
if(list[i].domName == dName)
{
for(int l = i; l < list.length(); l++)
{
list[l] = list[l+1];
}
}
}
}
|