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
|
//part of the Database class
void save()
{
ofstream write("friends.dat", ios::out);
write<<count<<'\n';
saveNode(parent, write);
write.close();
}
void saveNode(Node *root, ofstream & write)
{
char pwd[11] = "CSC220LEON";
if (root != NULL)
{
string s = root->getLastName();
write << encrypt(s, pwd) << '\n';
s = root->getFirstName();
write << encrypt(s, pwd) << '\n';
s = root->getMonth();
write << encrypt(s, pwd) << '\n';
s = root->getDay();
write << encrypt(s, pwd) << '\n';
s = root->getYear();
write << encrypt(s, pwd) << '\n';
s = root->getTelephone();
write << encrypt(s, pwd) << '\n';
s = root->getStreet();
write << encrypt(s, pwd) << '\n';
s = root->getCity();
write << encrypt(s, pwd) << '\n';
s = root->getState();
write << encrypt(s, pwd) << '\n';
s = root->getZip();
write << encrypt(s, pwd) << '\n';
saveNode(root->getLeft(), write);
saveNode(root->getRight(), write);
}
}
string encrypt(string s, char key[11])
{
char *temp = toCharArray(s);
int len = s.size();
for (int i = 0, j = 0; i < len; i++)
{
temp[i] ^= key[j++];
if (key[j] == '\0')
{
j = 0;
}
}
return string(temp);
}
int main(int argc, char *argv[])
{
string one = "/?";
if (argc == 2 && argv[1] == one)
{
cout << "Usage: \ncontact project /? (Help)\ncontact project (Display birthdays)\ncontact project -m (Display menu)\n";
}
else
{
Database d;
d.load(); //loads the file on start
cout<<"\nHello!\nWelcome to your personal Contact book."<<endl;
d.loop(); //loops through the program in database;
d.save(); //leaves the file on exit (here is where I'm having the problem)
return 0;
}
}
| |