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
|
/*
Program: Project 2
This program is to change one set of records from one format to another.
*/
#include <iostream>
#include <string>
#include <fstream>
//#include "convert.hpp"
#include "hydra.hpp"
#include "krebstar.hpp"
using namespace std;
KrebStarRecord convertHydraToKrebStar(HydraRecord hClient, KrebStarRecord kClient);
int main()
{
// Declare Variables
HydraRecord hClient[3];
KrebStarRecord kClient[3];
ifstream inFile; // Reads in the 'index.txt' file
ifstream savedInfo1; // Reads in information from the clients
ifstream savedInfo2;
ifstream savedInfo3;
ofstream outFile; // Saves the information to the KrebStar format
int numRecords = 0;
string fileNames[10];
// Welcome the user
cout << "Welcome to the record transfer system." << endl;
cout << "======================================="<<endl;
// Open the input file.
inFile.open("index.txt"); // 'index.txt' contains a list of filenames for the Hydra records
if(inFile.is_open() == false)
{
cerr << "ERROR: Cannot open index file. Exiting." << endl; // If the file isn't opened, produce the error and kill the program.
return 1;
}
else
{
cout << "The index file has been opened." << endl;
}
// Read in the file number of files from the index file.
inFile >> numRecords;
inFile.ignore(256, '\n');
cout << "There are " << numRecords << " records in this file." << endl;
// Read in the names of the files and display them to the screen
for(int i = 0; i < numRecords; i++)
{
getline(inFile, fileNames[i]);
cout << "file " << i + 1 << ": " << fileNames[i] << endl;
}
// End of index file work. Now to read information from the files.
savedInfo1.open(fileNames[0].c_str()); // Only opens 1 file at a time...
// Check to make sure the files open correctly
if(savedInfo1.is_open() == false)
{
cerr << "ERROR: Cannot open file" << 1 << ". Exiting." << endl; // If the file isn't opened, produce the error and kill the program.
return 1;
}
else
{
cout << "File " << 1 << " has been opened." << endl;
}
cout << "This is the filename that is opened: " << fileNames[0] << "." << endl; // Debug
getline(savedInfo1, hClient[0].customerID);
getline(savedInfo1, hClient[0].customerName);
getline(savedInfo1, hClient[0].customerStreetAddress);
getline(savedInfo1, hClient[0].customerPhoneNumber);
getline(savedInfo1, hClient[0].dateCreated[0]);
getline(savedInfo1, hClient[0].checkingBalance);
getline(savedInfo1, hClient[0].savingBalance);
// Force it to work for Debugging
// kClient[0].customerName = " <name>" + hClient[0].customerName + "</name>";
convertHydraToKrebStar(hClient[0], kClient[0]);
// More Debug...
cout << "This is the Hydra format name for customer 1: " << hClient[0].customerName << endl;
cout << "This is the KrebStar format name for customer 1: " << kClient[0].customerName << endl;
// Open the output file and write the information to it.
outFile.open("records.ksrf");
outFile << "<?xml version=""1.0""?>"<<endl;
outFile << "<ksrf>"<<endl;
outFile << " <customer>"<< endl;
outFile << kClient[0].customerID << endl;
outFile << kClient[0].customerName << endl;
outFile << " <address>"<<endl;
outFile << kClient[0].customerStreetAddress << endl;
outFile << kClient[0].customerCity << endl;
outFile << kClient[0].customerState << endl;
outFile << kClient[0].customerZip << endl;
outFile << " </address>"<<endl;
outFile << kClient[0].customerPhoneNumber << endl;
outFile << " <date>"<<endl;
outFile << kClient[0].yearCreated << endl;
outFile << kClient[0].monthCreated << endl;
outFile << kClient[0].dayCreated << endl;
outFile << " </date>" << endl;
outFile << " <accounts>"<< endl;
outFile << kClient[0].checkingBalance << endl;
outFile << kClient[0].savingBalance << endl;
outFile << " </accounts>"<< endl;
outFile << " </customer>" << endl;
outFile << endl;
outFile << "</ksrf>";
inFile.close();
outFile.close();
}
// conversion function
KrebStarRecord convertHydraToKrebStar(HydraRecord hClient, KrebStarRecord kClient)
{
kClient.customerID = " <id>" + hClient.customerID + "</id>";
kClient.customerName = " <name>" + hClient.customerName + "</name>";
kClient.customerStreetAddress = " <street>" + hClient.customerStreetAddress + "</street>";
kClient.customerState = " <state>" + hClient.Address[0] + "</state>";
kClient.customerCity = " <city>" + hClient.Address[1] + "</city>";
kClient.customerZip = " <zip>" + hClient.Address[2] + "</zip>";
kClient.customerPhoneNumber = " <phone>" + hClient.customerPhoneNumber + "</phone>";
kClient.dayCreated = " <day>" + hClient.dateCreated[0] + "</day>";
kClient.monthCreated = " <month>" + hClient.dateCreated[1] + "</month>";
kClient.yearCreated = " <year>" + hClient.dateCreated[2] + "</year>";
kClient.checkingBalance = " <checking>" + hClient.checkingBalance + "</checking>";
kClient.savingBalance = " <savings>" + hClient.savingBalance + "</savings>";
return kClient;
}
|