lashrone1

6.1

Jun 2nd, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7. int N=0;
  8.  
  9. struct date{
  10. int day;
  11. int month;
  12. int year;
  13. };
  14.  
  15. struct Student{
  16. string Surname ;
  17. string Name;
  18. string Patr;
  19. date Birth;
  20. double Mark;
  21. };
  22. Student* List;
  23. Student* Temp;
  24.  
  25. void add_stud(){
  26. N++;
  27. if(N==1)
  28. List=new Student[N];
  29. else{
  30. Student* Temp=new Student[N];
  31. for(int i=0; i<N-1; i++)
  32. Temp[i]=List[i];
  33. delete[] List;
  34. List=Temp;
  35. }
  36. cout << "Введіть данні нового студента:\nПрізвище: ";
  37. cin >>List[N-1].Surname;
  38. cout << "Ім'я: ";
  39. cin >>List[N-1].Name;
  40. cout << "По-батькові: ";
  41. cin >>List[N-1].Patr;
  42. cout << "День народження: ";
  43. cin >> List[N-1].Birth.day;
  44. cout << "Місяць народження: ";
  45. cin >> List[N-1].Birth.month;
  46. cout << "Рік народження: ";
  47. cin >> List[N-1].Birth.year;
  48. cout << "Середній бал(от 0 до 100 балів): ";
  49. cin>>List[N-1].Mark;
  50.  
  51. }
  52.  
  53. void sorting(){
  54. Student Temp;
  55. for(int j=0; j<N; j++)
  56. for(int i=0; i<N-1; i++)
  57. if(List[i].Surname>List[i+1].Surname){
  58. Temp=List[i];
  59. List[i]=List[i+1];
  60. List[i+1]=Temp;
  61. }
  62. }
  63.  
  64. void print_group(){
  65. cout << "Номер\tПрізвище\tІм'я\t\tПо-батькові\tДата народження\tСередній бал\n";
  66. for(int i=0; i<N; i++){
  67. cout << i+1 << ".\t" << List[i].Surname;
  68. if(List[i].Surname.size()>=8)cout<<"\t"; //контроль табуляций
  69. else cout << "\t\t";
  70. cout << List[i].Name;
  71. if(List[i].Name.size()>=8)cout<<"\t";
  72. else cout << "\t\t";
  73. cout << List[i].Patr;
  74. if(List[i].Patr.size()>=8)cout<<"\t";
  75. else cout << "\t\t";
  76. if(List[i].Birth.day<10)cout <<"0"; //нули для даты
  77. cout << List[i].Birth.day <<".";
  78. if(List[i].Birth.month<10)cout <<"0";
  79. cout << List[i].Birth.month <<"."<< List[i].Birth.year <<"\t"<< List[i].Mark << endl;
  80. }
  81. }
  82.  
  83. void surn(){
  84. char surn[20];int check=0;
  85. cout<<"Введіть прізвище\n";
  86. cin>>surn;
  87. for(int i=0;i<N;i++){
  88. if(List[i].Surname==surn){
  89. cout<< List[i].Surname <<"\t"
  90. << List[i].Name <<"\t"
  91. << List[i].Patr <<"\t"
  92. << List[i].Birth.day <<"\t"
  93. << List[i].Birth.month <<"\t"
  94. << List[i].Birth.year <<"\t"
  95. << List[i].Mark<<endl;
  96. check++;
  97. }
  98. }
  99. if(check==0)
  100. cout<<"Студенти не знайдені\n";
  101. }
  102.  
  103. void mark(){
  104. int beg,fin;
  105. bool flag=false;
  106.  
  107. cout << "Введіть діапазон баллів успішності(В межах від 0 до 100 включно):\nЗ: ";
  108. cin>>beg;
  109. while((beg<0)||(beg>100)){
  110. cout << "Неправильна межа(0 до 100): ";
  111. cin>>beg;
  112. }
  113. cout << "По: ";
  114. cin>>fin;
  115. while((fin<0)||(fin>100)){
  116. cout << "Неправильна межа(0 до 100): ";
  117. cin>>fin;
  118. }
  119.  
  120. for(int i=0; i<N; i++)
  121. if((List[i].Mark>=beg)&&(List[i].Mark<=fin)){
  122. cout << "\nСтуденти :\nНомер\tПрізвище\tІм'я\t\tПо-батькові\n";
  123. flag=true;
  124. break;
  125. }
  126. if(flag==false){
  127. cout << "Студенти не знайдені" << endl;
  128. return;
  129. }
  130.  
  131. for(int i=0; i<N; i++)
  132. if((List[i].Mark>=beg)&&(List[i].Mark<=fin)){
  133. cout << i+1 << ".\t" << List[i].Surname;
  134. if(List[i].Surname.size()>=8)cout<<"\t";
  135. else cout << "\t\t";
  136. cout << List[i].Name;
  137. if(List[i].Name.size()>=8)cout<<"\t";
  138. else cout << "\t\t";
  139. cout << List[i].Patr;
  140. if(List[i].Patr.size()>=8)cout<<"\t";
  141. else cout << "\t\t";
  142. cout<<endl;
  143. }
  144. }
  145.  
  146. void bd(){
  147. bool flag=false;
  148. int day;
  149. int month;
  150. cout<<"Введіть дату нароження у форматі ДД.ММ: \n";
  151. cin>>day;
  152. cin>>month;
  153.  
  154. for(int i=0; i<N; i++){
  155. if((List[i].Birth.day==day)&&(List[i].Birth.month==month)){
  156. cout << "\nСтуденти знайдені:\nНомер\tПрізвище\tІм'я\t\tПо-батькові\tДата народження\tСередня успішність\n";
  157. flag=true;
  158. break;
  159. }
  160. if(flag==false){
  161. cout << "Студенти не знайдені" << endl;
  162. return;
  163. }
  164. }
  165. for(int i=0; i<N;i++){
  166. if((List[i].Birth.day==day)&&(List[i].Birth.month==month)){
  167. cout << i+1 << ".\t" << List[i].Surname;
  168. if(List[i].Surname.size()>=8)cout<<"\t";
  169. else cout << "\t\t";
  170. cout << List[i].Name;
  171. if(List[i].Name.size()>=8)cout<<"\t";
  172. else cout << "\t\t";
  173. cout << List[i].Patr;
  174. if(List[i].Patr.size()>=8)cout<<"\t";
  175. else cout << "\t\t";
  176. if(List[i].Birth.day<10)cout <<"0";
  177. cout << List[i].Birth.day <<".";
  178. if(List[i].Birth.month<10)cout <<"0";
  179. cout << List[i].Birth.month <<"."<< List[i].Birth.year <<"\t"<< List[i].Mark << endl;
  180. }
  181.  
  182. }
  183.  
  184. }
  185.  
  186. void search_student(){
  187. int var;
  188. cout<<"Оберіть тип сортування: \n1.За прізвищем\n2.За середнім балом\n3.За датою народження\n";
  189. cout<<endl;
  190. cin>>var;
  191. switch (var){
  192. case 1: {
  193. surn();
  194. break;
  195. }
  196. case 2: {
  197. mark();
  198. break;
  199. }
  200. case 3: {
  201. bd();
  202. break;
  203. }
  204. default: cout<<"Оберіть один з видів сортування!\n";
  205. return search_student();
  206. }
  207. }
  208.  
  209. void del(){
  210. int pos;
  211.  
  212. cout << "Вкажіть номер студента, якого бажаєте видалити: ";
  213. cin>>pos;
  214. pos--;
  215. N--;
  216. Student* Temp=new Student[N];
  217. for(int i=0; i<pos; i++)
  218. Temp[i]=List[i];
  219. for(int i=pos+1; i<N+1; i++)
  220. Temp[i-1]=List[i];
  221. delete[] List;
  222. List=Temp;
  223. cout << "Студента видалено!!" << endl;
  224. }
  225.  
  226.  
  227. void delpoimeni(){
  228. string name;
  229. cout << "Вкажіть имя студента, якого бажаєте видалити: ";
  230. cin>>name;
  231. int pos;
  232. for(int i=0;i<N;i++){
  233. if(name==List[i].Name)
  234. pos=i;
  235. }
  236. N--;
  237. Student* Temp=new Student[N];
  238. for(int i=0; i<pos; i++)
  239. Temp[i]=List[i];
  240. for(int i=pos+1; i<N+1; i++)
  241. Temp[i-1]=List[i];
  242. delete[] List;
  243. List=Temp;
  244. cout << "Студента видалено!!" << endl;
  245. }
  246.  
  247. void serchfmark(){
  248. double minim=List[0].Mark;
  249. for(int i=1;i<N;i++){
  250. if(List[i].Mark<minim){
  251. minim=List[i].Mark;
  252. }
  253. }
  254. for(int i=0;i<N;i++){
  255. if(minim==List[i].Mark)
  256. cout<< List[i].Surname <<"\t"
  257. << List[i].Name <<"\t"
  258. << List[i].Patr <<"\t"
  259. << List[i].Birth.day <<"\t"
  260. << List[i].Birth.month <<"\t"
  261. << List[i].Birth.year <<"\t"
  262. << List[i].Mark<<endl;
  263. }
  264. }
  265.  
  266. int main(){
  267.  
  268. system("chcp 1251");
  269. int var;
  270. for(;;){
  271. cout<<endl;
  272. cout << "Меню: " << endl;
  273. cout << "1.Додати нового студента" << endl;
  274. cout << "2.Вивести усю группу" << endl;
  275. cout << "3.Пошук" << endl;
  276. cout << "4.Видалення студента із заданим номером в списку" << endl;
  277. cout << "5.Вихід з програми" << endl;
  278. cout << "6.Поиск самого слаього по оценке" << endl;
  279. cout << endl;
  280. cin >> var;
  281. cout << endl;
  282.  
  283. switch(var){
  284. case 1: {
  285. add_stud();
  286. break;
  287. }
  288. case 2:{
  289. print_group();
  290. break;
  291. }
  292. case 3:{
  293. search_student();
  294. break;
  295. }
  296. case 4:{
  297. del();
  298. break;
  299. }
  300. case 6:{
  301. serchfmark();
  302. break;
  303. }
  304. case 7:{
  305. delpoimeni();
  306. break;
  307. }
  308. case 5:free(List); return 0;
  309. default:{
  310. cout << "Введено невірне значення. Спробуйте ще раз\n" << endl;
  311. break;
  312. }
  313. }
  314.  
  315. }
  316. }
Add Comment
Please, Sign In to add comment