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
|
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
//function prototypes
string extractField(string &input);
string fixName(string &input);
string fixSSN(string &input);
string fixPhone(string &input);
string fixAddress(string &input);
string fixCity(string &input);
string fixState(string &input);
string getZip(string &input);
void buildLine(string name, string SSN, string phone, string addr, string city, string state, string zip, ofstream &fout);
int main()
{
string input, name, SSN, phone, addr, city, state, zip;
ifstream fin;
ofstream fout;
fin.open("badnames.txt");
if (fin.fail())
{
cout << "File open failed" << endl;
}
else
{
fout.open("output.txt");
if (fout.fail())
{
cout << "File open failed" << endl;
}
else
{
while (getline(fin,input))
{
name = fixName(input);
SSN = fixSSN(input);
phone = fixPhone(input);
addr = fixAddress(input);
city = fixCity(input);
state = fixState(input);
zip = getZip(input);
buildLine(name, SSN, phone, addr, city, state, zip, fout);
}
fout.close();
}
fin.close();
}
cout << "Complete" << endl;
return 0;
}
string extractField(string &input)
{
int num;
string s;
num = input.find('#', 0);
s = input.substr(0, num);
input.erase(0, num);
return s;
}
string fixName(string &input)
{
char temp;
int num;
string first, last, name;
name = extractField(input);
num = name.find(' ', 0);
first = name.substr(0, num);
name.erase(0, num);
last = name;
temp = first.front();
temp = toupper(temp);
first.erase(0, 1);
first.insert(0, 1, temp);
temp = last.front();
temp = toupper(temp);
first.erase(0, 1);
last.insert(0, 1, temp);
last.append(1, ',');
first.append(1, ',');
name = last + first;
return name;
}
string fixSSN(string &input)
{
string SSN;
SSN = extractField(input);
SSN.insert(4, 1, '-');
SSN.insert(7, 1, '-');
SSN.append(1, ',');
return SSN;
}
string fixPhone(string &input)
{
string phone;
phone = extractField(input);
phone.insert(4, 1, '-');
phone.insert(8, 1, '-');
phone.append(1, ',');
return phone;
}
string fixAddress(string &input)
{
string addr;
addr = extractField(input);
addr.append(1, ',');
return addr;
}
string fixCity(string &input)
{
string city;
int temp;
city = extractField(input);
temp = city.front();
temp = toupper(temp);
city.erase(0, 1);
city.insert(0, 1, temp);
city.append(1, ',');
return city;
}
string fixState(string &input)
{
string state;
int temp;
state = extractField(input);
temp = state.front();
temp = toupper(temp);
state.erase(0, 1);
state.insert(0, 1, temp);
temp = state.back();
temp = toupper(temp);
state.erase(1, 1);
state.insert(1, 1, temp);
return state;
}
string getZip(string &input)
{
string zip;
zip = input;
return zip;
}
void buildLine(string name, string SSN, string phone, string addr, string city, string state, string zip, ofstream &fout)
{
fout << name << SSN << phone << addr << city << state << zip << endl;
}
|