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
|
#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);
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;
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--;
break;
case 'F':
Find(list, DomName, listLength);
break;
case 'P':
Print(list, listLength);
break;
case 'Q':
system("pause");
return 0;
default:
cout << "Invalid Command." << endl;
}
}
}
void insertOne(domList list[], ifstream& inFile, int len)
{
domList one;
inFile >> one.domName >> one.ipAddress;
one.counter = 0;
list[len] = one;
}
//change Function
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;
}
}
}
//Delete Function
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];
}
}
}
}
//Find Function
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;
list[i].counter += 1;
}
}
}
//Print Function
void Print (domList list[], int len)
{
for (int i = 0; i < len; i++)
/{
cout << setw(20) << list[i].domName << setw(15)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
//Quit Function
void Quit (domList list[], int len)
{
for (int i = 0; i < len; i++)
{
for (int l = 0; l < len; l++)
{
if(list[i].domName[5] <= list[l].domName[5])
{
}
}
}
}
|