Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. // вар16.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string.h>
  7. using namespace std;
  8. struct student{
  9. char name[15], sname[15], pob[15], group[7];
  10. short int bal1, bal2, bal3;
  11. double serbal; student *next;
  12. };
  13. student *p, *pp, *head, *nov;
  14. void stvor()
  15. {
  16. p = new student;
  17. head = p;
  18. int i = 1;
  19. do
  20. {
  21. cout << "---Для окончания работы введите во все поля '0'---" << endl;
  22. cout << "----- Студент № " << i << " -----" << endl;
  23. pp = p;
  24. cout << "Введите фамилию: "; cin >> p->sname; cin.get();
  25. cout << "Введите имя: "; cin.getline(p->name, 15);
  26. cout << "Введите отчество: "; cin.getline(p->pob, 15);
  27. cout << "Введите групу (2букви-3цифры): "; cin.getline(p->group, 7);
  28. cout << "Введите оценку по математике: "; cin >> p->bal1;
  29. cout << "Введите оценку по програмированию: "; cin >> p->bal2;
  30. cout << "Введите оценку по английскому: "; cin >> p->bal3;
  31. p->next = new student;
  32. p = p->next;
  33. i++;
  34. } while ((pp->bal1 != 0) && ((pp->bal2 != 0) && (pp->bal3 != 0)));
  35. pp->next = NULL;
  36. }
  37. void srbal()
  38. {
  39. p = head;
  40. while (p != 0)
  41. {
  42. p->serbal = (p->bal1 + p->bal2 + p->bal3) / 3;
  43. p = p->next;
  44. }
  45. }
  46. void print()
  47. {
  48. p=head;
  49. cout << "Мы имеем такую информацию о студнентах: " << endl;
  50. cout << "№" << "t" << "Имя" << "t" << "Фамилия" << "t" << "Отч-во" << "t" << "Бал.Мат" << "t" << "Бал.ПР" << "t" << "Бал.англ" << "t" << "Ср.бал" << endl;
  51.  
  52. int i = 1;
  53. while (p != 0)
  54. {
  55. cout << i << "t" << p->name << "t" << p->sname << "t" << p->pob << "t" << p->bal1 << "t" << p->bal2 << "t" << p->bal3 << "t" << p->serbal << endl;
  56. p=p->next;
  57. i++;
  58. }
  59.  
  60. void sort()
  61. {
  62. int m=0;
  63. head = p;
  64.  
  65. while (p != 0)
  66. {
  67. pp = p;
  68. if (pp->serbal > p->serbal){
  69. m = pp->serbal;
  70. pp->serbal = p->serbal;
  71. p->serbal = m;
  72.  
  73. }
  74. p = p->next;
  75.  
  76. }
  77.  
  78. }
  79.  
  80. void del(student *head)
  81. {
  82. if (head != NULL)
  83. {
  84. del(head->next); delete head;
  85. }
  86.  
  87. }
  88. int _tmain(int argc, _TCHAR* argv[])
  89. {
  90. setlocale(LC_ALL, "Russian");
  91. stvor();
  92. srbal();
  93. sort();
  94. print();
  95.  
  96. del(head);
  97.  
  98. setlocale(LC_ALL, "OCP");
  99.  
  100. system("pause");
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement