Advertisement
Guest User

Untitled

a guest
May 24th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5. #include <cstring>
  6. #include "stdlib.h"
  7. using namespace std;
  8.  
  9. struct STUDENT
  10. {
  11. string FIO;
  12. int age;
  13. char gender;
  14. int kurs;
  15. double average;
  16. };
  17.  
  18. void create_file()
  19. {
  20. int numberofenter;
  21. ifstream fin("base.txt");
  22. ofstream fout("base.txt");
  23. string tmp;
  24. cout << "Введите число записей, которое вы хотите сделать: "; cin >> numberofenter;
  25. for (int i = 0; i < numberofenter; i++)
  26. {
  27. cout << "-------------------------------------------------------------------------------" << endl;
  28. cout << "Введите ФИО студента: ";
  29. getline(cin, tmp);
  30. fout << tmp << " ";
  31. cout << tmp << endl;
  32. cout << "Введите возраст студента: "; cin >> tmp; fout << tmp << " ";
  33. cout << "Введите пол (м / ж): "; cin >> tmp; fout << tmp << " ";
  34. cout << "Введите курс: "; cin >> tmp; fout << tmp << " ";
  35. cout << "Введите средний бал: "; cin >> tmp; fout << tmp << endl;
  36. getline(fin, tmp);
  37. cout << tmp << endl;
  38. }
  39. cout << "-------------------------------------------------------------------------------" << endl;
  40. }
  41.  
  42. void output_file()
  43. {
  44. string tmp;
  45. STUDENT student;
  46. ifstream fin("base.txt");
  47. int tmpnum = 0;
  48. while (fin.good())
  49. {
  50. getline(fin, tmp);
  51. int i = 0;
  52. while (tmp[i] < 48 && tmp[i] > 57)
  53. {
  54. student.FIO[i] = tmp[i];
  55. i++;
  56. }
  57. while (tmp[i] != ' ')
  58. {
  59. tmpnum = tmpnum * 10 + (tmp[i] - 48);
  60. i++;
  61. }
  62. student.age = tmpnum;
  63. tmpnum = 0;
  64. i++;
  65. student.gender = tmp[i];
  66. i++;
  67. student.kurs = tmp[i];
  68. while (i < tmp.length())
  69. {
  70. if (tmp[i] != '.')
  71. {
  72. tmpnum = tmpnum * 10 + (tmp[i] - 48);
  73. i++;
  74. }
  75. else
  76. {
  77. tmpnum = tmpnum + ((tmp[i] - 48)*0.1);
  78. i++;
  79. }
  80. }
  81. cout << "| " << setw(38) << left << student.FIO << "| " << setw(2) << left << student.age << " | " << setw(1) << left << student.age << "| " << setw(1) << left << student.kurs << " | " << setw(4) << left << student.average << " |" << endl;
  82. }
  83. }
  84.  
  85. void menu_output()
  86. {
  87. cout << "-------------------------------------------------------------------------------" << endl;
  88. cout << "Введите 1 для создания файла" << endl;
  89. cout << "Введите 2 для просмотра содержимого файла в виде таблицы" << endl;
  90. cout << "Введите 3 для добавления записи в файл" << endl;
  91. cout << "Введите 4 для удаления записи из файла" << endl;
  92. cout << "Введите 5 для изменения записи в файле" << endl;
  93. cout << "Введите 6 для определения студентов с фамилией на заданую букву" << endl;
  94. cout << "Введите 9 для вывода этого меню" << endl;
  95. cout << "Введите 0 для выхода из программы" << endl;
  96. cout << "-------------------------------------------------------------------------------" << endl;
  97. }
  98.  
  99. void main()
  100. {
  101. setlocale(LC_ALL, "Russian");
  102. int c;
  103. menu_output();
  104. do
  105. {
  106. cout << "Введите команду: "; cin >> c;
  107. cout << "-------------------------------------------------------------------------------" << endl;
  108. switch (c)
  109. {
  110. case 1:
  111. {
  112. create_file();
  113. } break;
  114. case 2:
  115. {
  116. cout << "-------------------------------------------------------------------------------" << endl;
  117. cout << "| ФИО | возраст | пол | курс | успеваемость |" << endl;
  118. output_file();
  119. cout << "-------------------------------------------------------------------------------" << endl;
  120. } break;
  121. case 9:
  122. {
  123. menu_output();
  124. } break;
  125. }
  126. } while (c != 0);
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement