Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 3.05 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "UserRecordManagement.h"
  2.  
  3.  
  4. UserRecordManagement::UserRecordManagement()
  5. {
  6.    
  7. }
  8.  
  9. void UserRecordManagement::createNewRecord(){
  10.    
  11.    
  12.        
  13.     cout << "Please enter a new account ID:" << endl;
  14.     cin >> accID;
  15.     cout << "Please enter a name:" << endl;
  16.     cin >> name;
  17.     cout << "Please enter a department ID:" << endl;
  18.     cin >> departmentID;
  19.     cout << "Please enter a password:" << endl;
  20.     cin >> password;
  21.    
  22.     ofstream outfile;
  23.     outfile.open("Report.txt",ios::app);
  24.     outfile << accID <<":"<< name <<":"<< departmentID <<":"<< password <<endl;
  25.     outfile.close();
  26.     cout << "Registration completed."<< endl;
  27.    
  28.    
  29. }
  30.  
  31. void UserRecordManagement::editRecord(){
  32.     string item, line;
  33.     string item_array[10];
  34.     int x=0;
  35.     int y=0;
  36.     long pos;
  37.     ifstream infile("Report.txt");              //normal way
  38.     //infile.open("Report.txt", ios::app);      //alternate way, app= append, no change content..
  39.     cout<<"Enter ID to change the record" << endl;
  40.     cin >> accID;
  41.     cout << ""<<endl;
  42.    
  43.     while(!infile.eof())
  44.     {
  45.         string newname;
  46.         string newdepartmentID;
  47.         getline(infile,line);
  48.        
  49.         stringstream stream(line);
  50.         x=0;// y=0;
  51.        
  52.         while(getline(stream,item,':')){        //read field,delimiter=":", and fill array
  53.             item_array[x]=item;
  54.             x++;
  55.             //item_array[y]=item;
  56.             //y++;
  57.         }
  58.        
  59.         //if first field is same as input
  60.         if(item_array[0]==accID){
  61.             //display...copy from net
  62.             cout<<"\tAccount ID: "<<item_array[0]<<endl;
  63.             cout<<"\tName: "<<item_array[1]<<endl;
  64.             cout<<"\tDepartment ID: "<<item_array[2]<<endl;
  65.             cout<<"\tPassword: "<<item_array[3]<<endl;
  66.            
  67.             cout<<"Enter new Name:";
  68.             cin >>newname;
  69.             cout<<"Enter new Department ID:";
  70.             cin >>newdepartmentID;
  71.            
  72.             //this part....not sure if really got change content of the text file
  73.             item_array[1] = newname;
  74.             item_array[2] = newdepartmentID;
  75.            
  76.             //cout<<setfill('-')<<left<<setw(10)<<"\tNew Name is:"<<right<<" "<<item_array[1]<<endl;
  77.             //cout<<setfill('-')<<left<<setw(10)<<"\tNew Department ID is:"<<right<<" "<<item_array[2]<<endl;
  78.            
  79.            
  80.         }
  81.     }
  82.     infile.close();
  83.    
  84.    
  85.     ifstream read("Report.txt");
  86.            
  87.             while (!read.eof() && line!=accID){
  88.                 getline(read,line);
  89.                 y++;
  90.                
  91.             }
  92.             ofstream write;
  93.             write.open("Report.txt",ios::app);
  94.             pos=y;
  95.             write.seekp(pos);
  96.             write<<item_array[0]<<":"<<item_array[1]<<":"<<item_array[2]<<":"<<item_array[3];
  97.             write.close();
  98.     read.close();
  99.    
  100.    
  101.    
  102.    
  103.    
  104.    
  105.    
  106. }
  107.  
  108. void UserRecordManagement::deleteRecord(){
  109.        
  110. }
  111.  
  112. void UserRecordManagement::resetPassword(){
  113.    
  114. }