vitalya1

← разместить еще код

Расшаренный код:

#include "pch.h"
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

using namespace std;

struct Stud {
  char surname[24];
  char name[24];
  char middleName[28];

  int age;
  
  double performance;

  Stud* next;
};


void filling(Stud* head) {
  cout << "Enter student is last name ";
  cin >> head->surname;
  cout << "Enter student name ";
  cin >> head->name;
  cout << "Enter the student is middle name ";
  cin >> head->middleName;
  cout << "Enter the age ";
  cin >> head->age;

  bool tmp = true;
  while (tmp) {
    tmp = false;
    cout << "Enter grade level ";
    cin >> head->performance;
    if (head->performance < 0 || head->performance >100) {
      cout << "Input correct value\n";
      tmp = true;
    }
  }

}

void add_in_start(Stud** head) {
  Stud* newStud = (Stud*)malloc(sizeof( Stud));
  filling(newStud);
  newStud->next = *head;
  *head = newStud;
}

void add_in_end(Stud** head)
{
  Stud* current = *head;
  Stud* newStud;
  newStud = (Stud*)malloc(sizeof(Stud));
  filling(newStud);
  newStud->next = NULL;

  if (current == NULL) {
    *head = newStud;
  }
  else {
    while (current->next != NULL) {
      current = current->next;
    }
    current->next = newStud;
  }
}

void add_SE(Stud** head) 
{
  Stud* current = *head;
  char tmpsurname[24];
  cout << "After whom enter?\n";
  cin >> tmpsurname;
  
  Stud* newStud = (Stud*)malloc(sizeof(Stud));
  filling(newStud);

  
  if (!strcmp(current->surname, tmpsurname )) {
    newStud->next = current->next->next;
    current->next = newStud;
  }
  else {
    while (strcmp(current->surname, tmpsurname)) {
      current = current->next;
    }
    newStud->next = current->next;
    current->next = newStud;
  }

}

void print(struct Stud* head) {

  while (head != NULL) {

    cout << "Last name: " << head->surname << "\n";
    cout << "name: " << head->name << "\n";
    cout << "Middle name: " << head->middleName << "\n";
    cout << "Age: " << head->age << "\n";
    cout << "Performance: " << head->performance << "\n";
    head = head->next;
  }
  cout << "\n";
}

void s_for_surname(Stud* head) {

  char tmp_surname[24];
  cout << "input surname for search\n";
  cin >> tmp_surname;

  while (head != NULL) {
    if (!strcmp(tmp_surname, head->surname)) {
      print(head);
    }
    head = head->next;
  }

}

void s_for_perfor(Stud* un_sat) {
  Stud* fine= un_sat;
  Stud* good = un_sat;
  Stud* sat = un_sat;
  cout << "Fine (90-100):\n";
  while (fine != NULL) {
    if (fine->performance>=90 ) {
      cout << "Last name: " << fine->surname << "\n";
      cout << "name: " << fine->name << "\n";
      cout << "Middle name: " << fine->middleName << "\n";
      cout << "Age: " << fine->age << "\n";
      cout << "Performance: " << fine->performance << "\n";
    }
    fine = fine->next;
  }
  cout << "Good (70-89):\n";
  while (good != NULL) {
    if (good->performance >=70 && good->performance<90) {
      cout << "Last name: " << good->surname << "\n";
      cout << "name: " << good->name << "\n";
      cout << "Middle name: " << good->middleName << "\n";
      cout << "Age: " << good->age << "\n";
      cout << "Performance: " << good->performance << "\n";
    }
    good = good->next;
  }
  cout << "Satisfactory (50-69):\n";
  while (sat != NULL) {
    if (sat->performance >= 50 && sat->performance < 70) {
      cout << "Last name: " << sat->surname << "\n";
      cout << "name: " << sat->name << "\n";
      cout << "Middle name: " << sat->middleName << "\n";
      cout << "Age: " << sat->age << "\n";
      cout << "Performance: " << sat->performance << "\n";
    }
    sat = sat->next;
  }
  cout << "Unsatisfactory (0-49):\n";
  while (un_sat != NULL) {
    if (un_sat->performance<50) {
      cout << "Last name: " << un_sat->surname << "\n";
      cout << "name: " << un_sat->name << "\n";
      cout << "Middle name: " << sat->middleName << "\n";
      cout << "Age: " << un_sat->age << "\n";
      cout << "Performance: " << un_sat->performance << "\n";
    }
    un_sat = un_sat->next;
  }
}
void sort(Stud** head) {
  bool check = true;
  Stud* current = *head;
  while (check) {
    check = false;
    while (current->next != NULL) {
      if (strcmp(current->surname, current->next->surname)>0) {
        check = true;
        Stud* tmp = current;
        current = tmp->next;
        current->next = tmp;
        check = true;
      }
      current = current->next;
    }
    
  }
}

int main()
{
    
  Stud* head=NULL;

  int ans;
  while (true) {
    cout << "Enter \"1\" for print all students \n";
    cout << "Enter \"2\" for add students in start \n";
    cout << "Enter \"3\" for add students in end \n";
    cout << "Enter \"4\" for add students after preset \n";
    cout << "Enter \"5\" for serch students by surname \n";
    cout << "Enter \"6\" for print students by level of performance\n";
    cout << "Enten \"7\" for sort student\n";
    cin >> ans;
    switch (ans) {

      case 1: {
        print(head);
        break;
      }
  
      case 2: {
        add_in_start(&head);
        break;
      }
      case 3: {
        add_in_end(&head);
        break;
      }
      case 4: {
        add_SE(&head);
        break;
      }
      case 5: {
        s_for_surname(head);
        break;
      }
      case 6: {
        s_for_perfor(head);
        break;
      }
      case 7: {
        sort(&head);
        break;
      }
    }
  }
}