Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // вар16.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string.h>
- using namespace std;
- struct student{
- char name[15], sname[15], pob[15], group[7];
- short int bal1, bal2, bal3;
- double serbal; student *next;
- };
- student *p, *pp, *head, *nov;
- void stvor()
- {
- p = new student;
- head = p;
- int i = 1;
- do
- {
- cout << "---Для окончания работы введите во все поля '0'---" << endl;
- cout << "----- Студент № " << i << " -----" << endl;
- pp = p;
- cout << "Введите фамилию: "; cin >> p->sname; cin.get();
- cout << "Введите имя: "; cin.getline(p->name, 15);
- cout << "Введите отчество: "; cin.getline(p->pob, 15);
- cout << "Введите групу (2букви-3цифры): "; cin.getline(p->group, 7);
- cout << "Введите оценку по математике: "; cin >> p->bal1;
- cout << "Введите оценку по програмированию: "; cin >> p->bal2;
- cout << "Введите оценку по английскому: "; cin >> p->bal3;
- p->next = new student;
- p = p->next;
- i++;
- } while ((pp->bal1 != 0) && ((pp->bal2 != 0) && (pp->bal3 != 0)));
- pp->next = NULL;
- }
- void srbal()
- {
- p = head;
- while (p != 0)
- {
- p->serbal = (p->bal1 + p->bal2 + p->bal3) / 3;
- p = p->next;
- }
- }
- void print()
- {
- p=head;
- cout << "Мы имеем такую информацию о студнентах: " << endl;
- cout << "№" << "t" << "Имя" << "t" << "Фамилия" << "t" << "Отч-во" << "t" << "Бал.Мат" << "t" << "Бал.ПР" << "t" << "Бал.англ" << "t" << "Ср.бал" << endl;
- int i = 1;
- while (p != 0)
- {
- cout << i << "t" << p->name << "t" << p->sname << "t" << p->pob << "t" << p->bal1 << "t" << p->bal2 << "t" << p->bal3 << "t" << p->serbal << endl;
- p=p->next;
- i++;
- }
- void sort()
- {
- int m=0;
- head = p;
- while (p != 0)
- {
- pp = p;
- if (pp->serbal > p->serbal){
- m = pp->serbal;
- pp->serbal = p->serbal;
- p->serbal = m;
- }
- p = p->next;
- }
- }
- void del(student *head)
- {
- if (head != NULL)
- {
- del(head->next); delete head;
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "Russian");
- stvor();
- srbal();
- sort();
- print();
- del(head);
- setlocale(LC_ALL, "OCP");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement