Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct Student {
- int nr;
- char familie[30];
- char nume[30];
- char adresa[30];
- char telefon[20];
- char specialitate[30];
- int clasa;
- float nota;
- Student *next;
- } *p, *q, *q1;
- void swap(Student *l1, Student *l2) {
- l1->nr = l2->nr;
- strcpy(l1->familie, l2->familie);
- strcpy(l1->nume, l2->nume);
- strcpy(l1->adresa, l2->adresa);
- strcpy(l1->telefon, l2->telefon);
- strcpy(l1->specialitate, l2->specialitate);
- l1->clasa = l2->clasa;
- l1->nota = l2->nota;
- }
- void Create() {
- int n, i;
- cout << "Введите количество студентов:";
- cin >> n;
- if (n <= 0) {
- p = NULL;
- cout << "Количество не может быть отрицательной." << endl;
- } else {
- q = new Student;
- q->nr = 1;
- cout << "Введите фамилию, имя, адрес, телефон, специализацию, класс и оценку для первого студента: ";
- cin >> q->familie >> q->nume >> q->adresa >> q->telefon >> q->specialitate >> q->clasa >> q->nota;
- q->next = NULL;
- p = q;
- for (i = 2; i <= n; i++) {
- q1 = new Student;
- q1->nr = i;
- cout << "Введите фамилию, имя, адрес, телефон, специализацию, класс и оценку для " << i
- << "-го студента: ";
- cin >> q1->familie >> q1->nume >> q1->adresa >> q1->telefon >> q1->specialitate >> q1->clasa >> q1->nota;
- q1->next = NULL;
- q->next = q1;
- q = q1;
- }
- }
- }
- void Show() {
- if (p) {
- cout << "Список студентов: " << endl;
- q = p;
- while (q) {
- cout << q->nr
- << "\t" << q->familie
- << "\t" << q->nume
- << "\t" << q->adresa
- << "\t" << q->telefon
- << "\t" << q->specialitate
- << "\t" << q->clasa
- << "\t" << q->nota << endl;
- q = q->next;
- }
- } else
- cout << "Список пустой." << endl;
- }
- void Add() {
- if (p) {
- q = p;
- int i = 1;
- while (q->next) {
- i = q->nr;
- q = q->next;
- }
- i += 2;
- q1 = new Student;
- q1->nr = i;
- cout << "Введите фамилию, имя, адрес, телефон, специализацию, класс и оценку для " << i
- << "-го студента: ";
- cin >> q1->familie >> q1->nume >> q1->adresa >> q1->telefon >> q1->specialitate >> q1->clasa >> q1->nota;
- q1->next = NULL;//q->next;
- q->next = q1;
- q = q1;
- } else {
- cout << "Список пустой. Создание списка:" << endl;
- Create();
- }
- }
- Student *Find() {
- int nr;
- if (p == NULL) {
- return NULL;
- }
- cout << "Введите номер студента: ";
- cin >> nr;
- q = p;
- while ((q) && (q->nr != nr)) {
- q = q->next;
- }
- if (q)
- cout << q->nr
- << "\t" << q->familie
- << "\t" << q->nume
- << "\t" << q->adresa
- << "\t" << q->telefon
- << "\t" << q->specialitate
- << "\t" << q->clasa
- << "\t" << q->nota << endl;
- else
- cout << "Студент не найден!";
- return q;
- }
- void Edit() {
- Show();
- Student *q;
- q = Find();
- if (q) {
- cout << "Введите фамилию, имя, адрес, телефон, специализацию, класс и оценку для нужного студента: ";
- cin >> q1->familie >> q1->nume >> q1->adresa >> q1->telefon >> q1->specialitate >> q1->clasa >> q1->nota;
- cout << "Обновленный список студентов: " << endl;
- Show();
- }
- }
- bool Delete() {
- Show();
- Student *q;
- q = Find();
- if (q) {
- if (q == p) {
- p = p->next;
- } else {
- q1 = p;
- while (q1->next != q)
- q1 = q1->next;
- if (q == p)
- p = p->next;
- q1->next = q->next;
- }
- delete q;
- cout << "Обновленный список студентов: " << endl;
- Show();
- return true;
- } else
- return false;
- }
- bool Sort() {
- Student *l;
- l = new Student;
- bool change;
- if (p == NULL)
- return false;
- do {
- q = p;
- change = false;
- while (q->next) {
- if (q->nr < q->next->nr) {
- swap(l, q);
- swap(q, q->next);
- swap(q->next, l);
- change = true;
- }
- q = q->next;
- }
- } while (change);
- return true;
- }
- void DeleteList() {
- p = NULL;
- }
- int main(int argc, char **argv) {
- int menu;
- do {
- cout << "Создание списка...........1" << endl;
- cout << "Показать список студентов.2" << endl;
- cout << "Добавить студента.........3" << endl;
- cout << "Редактировать студента....4" << endl;
- cout << "Удалить студента..........5" << endl;
- cout << "Поиск студента............6" << endl;
- cout << "Сортировать список........7" << endl;
- cout << "Удалить список............8" << endl;
- cout << "Выход из программы........0" << endl;
- cin >> menu;
- switch (menu) {
- case 1:
- Create();
- break;
- case 2:
- Show();
- break;
- case 3:
- Add();
- break;
- case 4:
- Edit();
- break;
- case 5:
- if (Delete())
- cout << "Удаление было успешно!" << endl;
- else
- cout << "Удаление было не успешно!" << endl;
- break;
- case 6:
- Find();
- break;
- case 7:
- if (Sort()) {
- cout << "Отсортированный список: " << endl;
- Show();
- } else
- cout << "Список пустой! Сортировка была не успешной" << endl;
- break;
- case 8:
- DeleteList();
- break;
- }
- } while (menu != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement