Guest User

lala

a guest
Apr 14th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <math.h>
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. using namespace std;
  7. ///////////////////////////////////////////////////////
  8. class student
  9. {
  10. public:
  11. string fio;
  12. int id;
  13. string group;
  14.  
  15. void getData()
  16. {
  17. cout << "Enter fio: "; cin >> fio;
  18. cout << "Enter id: "; cin >> id;
  19. cout << "Enter group: "; cin >> group;
  20. }
  21.  
  22. void showData()
  23. {
  24. cout << "Fio: " << fio;
  25. cout << "Id: " << id;
  26. cout << "Group: " << group;
  27. }
  28. };
  29.  
  30. int main()
  31. {
  32. student person;
  33. fstream file;
  34. int operation;
  35. do
  36. {
  37. cout << "Select one of the following operation:\n";
  38. cout << "1 = Add student\n";
  39. cout << "2 = Change student\n";
  40. cout << "3 = Delete student\n";
  41. cout << "4 = Search student\n";
  42. cout << "0 = Exit\n";
  43. cin >> operation;
  44.  
  45. if (operation == 1)
  46. {
  47. file.open("lab_1.txt", ios_base::out | ios_base::app | ios_base::binary);
  48. cout << "Enter data:\n";
  49. person.getData();
  50. file.write(reinterpret_cast<char*>(&person), sizeof(person));
  51. file << "\r\n";
  52. file.close();
  53. }
  54.  
  55. else if (operation == 2)
  56. {
  57. int search;
  58. cout << "Enter id of the student for search and change: "; cin >> search;
  59. file.open("lab_1.txt", ios_base::out | ios_base::in | ios_base::binary);
  60. file.seekg(0);
  61. while (!file.eof())
  62. {
  63. file.read(reinterpret_cast(&person), sizeof(person));
  64. cout « "FOUND" « person.id;
  65. /* file.read(reinterpret_cast<char*>(&person), sizeof(person));
  66. if (search == person.id)
  67. {
  68. cout << "Enter new data:\n";
  69. person.getData();
  70. file.write(reinterpret_cast<char*>(&person), sizeof(person));
  71. }
  72. */
  73. }
  74. file.close();
  75. }
  76. /*
  77. else if (operation == 3)
  78. {
  79. int search;
  80. cout << "Enter id of the student for search and delete: "; cin >> search;
  81. file.open("lab_1.txt", ios_base::in | ios_base::binary);
  82. file.seekg(0);
  83. while (!file.eof())
  84. {
  85. cout << file.tellg() << " | ";
  86. file.read(reinterpret_cast<char*>(&person), sizeof(person));
  87. if (search == person.id)
  88. {
  89. }
  90. cout << file.tellg() << " | ";
  91. file.close();
  92. }
  93. }
  94. else if (operation == 4)
  95. {
  96. int id_student;
  97. cout << "Введите номер зачетки студента, по которому будет осуществляться поиск и вывод информации: "; cin >> id_student;
  98. file.open("1.txt", ios_base::out | ios_base::binary);
  99. file.seekg(0);
  100. file.read(reinterpret_cast<char*>(&pers), sizeof(pers));
  101. while (!file.eof())
  102. {
  103. if (id_student == pers.id_zachet)
  104. {
  105. }
  106. file.read(reinterpret_cast<char*>(&pers), sizeof(pers));
  107. }
  108. file.close();
  109. }
  110. */
  111. } while (operation != 0);
  112. system("pause");
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment