Ok, I'm not really filled in on the XOR encryption yet, I'll come to that.
This is the program, with filly implemented search & DB_Mem.txt.
@Xhi This also gets around the prob of Id's 1,2,3 and then 12, since it just reads whatever is inside the text file
Code:
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <clrscr.h> // Yesyes, a custom header thingy, but no credit 2 me, it's taken from the faq.
using namespace std;
/*
30-12-05 20:38
Thanks people of the cboard forum!!!
Special thanks:
xhi
xhi
xhi
xhi
*Repeat 200000 times*
Me
*/
/*
Ideas to implement:
DB.txt file, which includes:
Errors
Member names + id's ( So the search routine can be skipped altogether. )
*/
struct dbase_read {
int id_no;
string name;
int age;
};
int main() {
int x = 0;
dbase_read employee; // This program creates a text file for each new entry,
// in a subfolder called database.
// hey, maybe I'll add a mobile phone/ house phone number function!!! :D
while ( x != 1 ) { /*See the explanation ( At the bottom )*/
cout<< "Do you want to:\n\n1. Create a new employee\n2. Read the Database\n\n:";
int choice;
cin>> choice;
string txt = ".txt";
string name = "database/Member";
string iid;
switch ( choice ) {
case 1: {
clrscr();
cout<< "Id Number?\n:"; // Seems pretty self-explanatory to me.
cin>> employee.id_no;
stringstream s;
s << employee.id_no;
s >> iid;
clrscr();
cin.ignore();
cout<< "Full Name?\n:";
getline(cin, employee.name, '\n');
clrscr();
cout<< "Age?\n:";
cin>> employee.age;
clrscr();
string full_filename = name + iid + txt;
ofstream write_file ( full_filename.c_str() ); // Below, all of the input is printed into a text file.
write_file<< "Name:\n"<< employee.name << "\n\n" << "Age:\n" << employee.age<< "\n\n" << "Id Number:\n" << employee.id_no << "\n\n¼";
write_file.close();
ofstream write_db_file ( "database/DB_Mem.txt", ios::app ); // <-- I didn't make this up.. You know who did ;)
write_db_file<< employee.name << " Id: " << employee.id_no << "\n"; // Makes a DB_Mem.txt file in the database subdir.
clrscr(); // Will Make the search func MUCH easier to write :)
break; // Thumbs up for me not being off track ;)
}
case 2: {
int know_id;
cout<< "Do you know the persons Id?\n:";
cin.ignore();
cin>> know_id;
cin.ignore();
clrscr();
if ( know_id == 1 ) {
cout<< "What is the Id Number of the person you want the details of?\n\nEnter Id:";
int id=0;
cin>> id;
stringstream sstr;
sstr << id;
string read;
string filename = name + sstr.str() + txt;
ifstream read_file ( filename.c_str() );
getline(read_file, read, '¼');
clrscr();
cout<< read;
cin.ignore();
cin.get();
clrscr();
}
else {
ifstream db_mem ( "database/DB_Mem.txt" );
string db_read;
getline(db_mem, db_read, '\0');
cout<< "These are the members:\n" << db_read;
cin.get();
}
break;
}
default: {
cout<< "Wtf?"; // Best I could think of ;)
break;
}
}
clrscr();
cout<< "Quit?\n:"; // So you don't have to restart the program when you want to do something again.
cin>> x; // See the while loop, if x does not equal 1, then it continues.
clrscr();
}
clrscr();
cin.get();
}