Guest User

Untitled

a guest
Dec 12th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7. /*
  8. This is just a function implementation of a
  9. section of project.
  10. need to read a file ( attached ) , update
  11. the amount of the specified client given the client id in the file. Then write back to the file */
  12.  
  13. class editor {
  14. private:
  15. fstream fs;
  16. ofstream ofs_1;
  17. public:
  18. editor()
  19. {
  20. fs.open("users.txt", ios::ios_base::in || ios::ios_base::out);
  21. ofs_1.open("users1.txt", ios::ios_base::app);
  22. unsigned int stat_cap, id, acc_no;
  23. string fname, lname;
  24. if (ofs_1.is_open())
  25. {
  26. if (fs.is_open())
  27. {
  28. while (fs >> id >> fname >> lname >> acc_no >> stat_cap)
  29. {
  30. if (id == get_id())
  31. {
  32. std::cout << id << " " << fname + " " + lname << " " << acc_no << " " << stat_cap << std::endl;
  33. std::cout << "editing ..." << std::endl;
  34. edit(std::ref(stat_cap));
  35. ofs_1 << id << fname + " " + lname << " " << acc_no << " " << stat_cap << std::endl;
  36. }
  37. ofs_1 << id << fname + " " + lname << " " << acc_no << " " << stat_cap << std::endl;
  38. }
  39. }
  40. else
  41. {
  42. perror("Read file could not open");
  43. }
  44. }
  45. else
  46. {
  47. perror("Write file could not open");
  48. }
  49. }
  50. unsigned int get_id()
  51. {
  52. unsigned int passed_id;
  53. std::cout << " Enter your id : ";
  54. cin >> passed_id;
  55.  
  56. return passed_id;
  57. }
  58. unsigned int edit(unsigned int &stat_cap)
  59. {
  60. unsigned int *ptr = NULL;
  61. ptr = &stat_cap;
  62. stat_cap = *ptr + 10000;
  63. return stat_cap;
  64. }
  65. };
  66.  
  67.  
  68. int main()
  69. {
  70. int status;
  71. editor edit_it;
  72. status = remove("users.txt");
  73. if (status == 0)
  74. {
  75. std::cout << " Original file deleted successfully" << std::endl;
  76. }
  77. else
  78. {
  79. std::cout << " Error ! original file could not be deleted " << std::endl;
  80. }
  81. return 0;
  82. }
Add Comment
Please, Sign In to add comment