- #include "UserRecordManagement.h"
- UserRecordManagement::UserRecordManagement()
- {
- }
- void UserRecordManagement::createNewRecord(){
- cout << "Please enter a new account ID:" << endl;
- cin >> accID;
- cout << "Please enter a name:" << endl;
- cin >> name;
- cout << "Please enter a department ID:" << endl;
- cin >> departmentID;
- cout << "Please enter a password:" << endl;
- cin >> password;
- ofstream outfile;
- outfile.open("Report.txt",ios::app);
- outfile << accID <<":"<< name <<":"<< departmentID <<":"<< password <<endl;
- outfile.close();
- cout << "Registration completed."<< endl;
- }
- void UserRecordManagement::editRecord(){
- string item, line;
- string item_array[10];
- int x=0;
- int y=0;
- long pos;
- ifstream infile("Report.txt"); //normal way
- //infile.open("Report.txt", ios::app); //alternate way, app= append, no change content..
- cout<<"Enter ID to change the record" << endl;
- cin >> accID;
- cout << ""<<endl;
- while(!infile.eof())
- {
- string newname;
- string newdepartmentID;
- getline(infile,line);
- stringstream stream(line);
- x=0;// y=0;
- while(getline(stream,item,':')){ //read field,delimiter=":", and fill array
- item_array[x]=item;
- x++;
- //item_array[y]=item;
- //y++;
- }
- //if first field is same as input
- if(item_array[0]==accID){
- //display...copy from net
- cout<<"\tAccount ID: "<<item_array[0]<<endl;
- cout<<"\tName: "<<item_array[1]<<endl;
- cout<<"\tDepartment ID: "<<item_array[2]<<endl;
- cout<<"\tPassword: "<<item_array[3]<<endl;
- cout<<"Enter new Name:";
- cin >>newname;
- cout<<"Enter new Department ID:";
- cin >>newdepartmentID;
- //this part....not sure if really got change content of the text file
- item_array[1] = newname;
- item_array[2] = newdepartmentID;
- //cout<<setfill('-')<<left<<setw(10)<<"\tNew Name is:"<<right<<" "<<item_array[1]<<endl;
- //cout<<setfill('-')<<left<<setw(10)<<"\tNew Department ID is:"<<right<<" "<<item_array[2]<<endl;
- }
- }
- infile.close();
- ifstream read("Report.txt");
- while (!read.eof() && line!=accID){
- getline(read,line);
- y++;
- }
- ofstream write;
- write.open("Report.txt",ios::app);
- pos=y;
- write.seekp(pos);
- write<<item_array[0]<<":"<<item_array[1]<<":"<<item_array[2]<<":"<<item_array[3];
- write.close();
- read.close();
- }
- void UserRecordManagement::deleteRecord(){
- }
- void UserRecordManagement::resetPassword(){
- }