Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int N=0;
- struct date{
- int day;
- int month;
- int year;
- };
- struct Student{
- string Surname ;
- string Name;
- string Patr;
- date Birth;
- double Mark;
- };
- Student* List;
- Student* Temp;
- void add_stud(){
- N++;
- if(N==1)
- List=new Student[N];
- else{
- Student* Temp=new Student[N];
- for(int i=0; i<N-1; i++)
- Temp[i]=List[i];
- delete[] List;
- List=Temp;
- }
- cout << "Введіть данні нового студента:\nПрізвище: ";
- cin >>List[N-1].Surname;
- cout << "Ім'я: ";
- cin >>List[N-1].Name;
- cout << "По-батькові: ";
- cin >>List[N-1].Patr;
- cout << "День народження: ";
- cin >> List[N-1].Birth.day;
- cout << "Місяць народження: ";
- cin >> List[N-1].Birth.month;
- cout << "Рік народження: ";
- cin >> List[N-1].Birth.year;
- cout << "Середній бал(от 0 до 100 балів): ";
- cin>>List[N-1].Mark;
- }
- void sorting(){
- Student Temp;
- for(int j=0; j<N; j++)
- for(int i=0; i<N-1; i++)
- if(List[i].Surname>List[i+1].Surname){
- Temp=List[i];
- List[i]=List[i+1];
- List[i+1]=Temp;
- }
- }
- void print_group(){
- cout << "Номер\tПрізвище\tІм'я\t\tПо-батькові\tДата народження\tСередній бал\n";
- for(int i=0; i<N; i++){
- cout << i+1 << ".\t" << List[i].Surname;
- if(List[i].Surname.size()>=8)cout<<"\t"; //контроль табуляций
- else cout << "\t\t";
- cout << List[i].Name;
- if(List[i].Name.size()>=8)cout<<"\t";
- else cout << "\t\t";
- cout << List[i].Patr;
- if(List[i].Patr.size()>=8)cout<<"\t";
- else cout << "\t\t";
- if(List[i].Birth.day<10)cout <<"0"; //нули для даты
- cout << List[i].Birth.day <<".";
- if(List[i].Birth.month<10)cout <<"0";
- cout << List[i].Birth.month <<"."<< List[i].Birth.year <<"\t"<< List[i].Mark << endl;
- }
- }
- void surn(){
- char surn[20];int check=0;
- cout<<"Введіть прізвище\n";
- cin>>surn;
- for(int i=0;i<N;i++){
- if(List[i].Surname==surn){
- cout<< List[i].Surname <<"\t"
- << List[i].Name <<"\t"
- << List[i].Patr <<"\t"
- << List[i].Birth.day <<"\t"
- << List[i].Birth.month <<"\t"
- << List[i].Birth.year <<"\t"
- << List[i].Mark<<endl;
- check++;
- }
- }
- if(check==0)
- cout<<"Студенти не знайдені\n";
- }
- void mark(){
- int beg,fin;
- bool flag=false;
- cout << "Введіть діапазон баллів успішності(В межах від 0 до 100 включно):\nЗ: ";
- cin>>beg;
- while((beg<0)||(beg>100)){
- cout << "Неправильна межа(0 до 100): ";
- cin>>beg;
- }
- cout << "По: ";
- cin>>fin;
- while((fin<0)||(fin>100)){
- cout << "Неправильна межа(0 до 100): ";
- cin>>fin;
- }
- for(int i=0; i<N; i++)
- if((List[i].Mark>=beg)&&(List[i].Mark<=fin)){
- cout << "\nСтуденти :\nНомер\tПрізвище\tІм'я\t\tПо-батькові\n";
- flag=true;
- break;
- }
- if(flag==false){
- cout << "Студенти не знайдені" << endl;
- return;
- }
- for(int i=0; i<N; i++)
- if((List[i].Mark>=beg)&&(List[i].Mark<=fin)){
- cout << i+1 << ".\t" << List[i].Surname;
- if(List[i].Surname.size()>=8)cout<<"\t";
- else cout << "\t\t";
- cout << List[i].Name;
- if(List[i].Name.size()>=8)cout<<"\t";
- else cout << "\t\t";
- cout << List[i].Patr;
- if(List[i].Patr.size()>=8)cout<<"\t";
- else cout << "\t\t";
- cout<<endl;
- }
- }
- void bd(){
- bool flag=false;
- int day;
- int month;
- cout<<"Введіть дату нароження у форматі ДД.ММ: \n";
- cin>>day;
- cin>>month;
- for(int i=0; i<N; i++){
- if((List[i].Birth.day==day)&&(List[i].Birth.month==month)){
- cout << "\nСтуденти знайдені:\nНомер\tПрізвище\tІм'я\t\tПо-батькові\tДата народження\tСередня успішність\n";
- flag=true;
- break;
- }
- if(flag==false){
- cout << "Студенти не знайдені" << endl;
- return;
- }
- }
- for(int i=0; i<N;i++){
- if((List[i].Birth.day==day)&&(List[i].Birth.month==month)){
- cout << i+1 << ".\t" << List[i].Surname;
- if(List[i].Surname.size()>=8)cout<<"\t";
- else cout << "\t\t";
- cout << List[i].Name;
- if(List[i].Name.size()>=8)cout<<"\t";
- else cout << "\t\t";
- cout << List[i].Patr;
- if(List[i].Patr.size()>=8)cout<<"\t";
- else cout << "\t\t";
- if(List[i].Birth.day<10)cout <<"0";
- cout << List[i].Birth.day <<".";
- if(List[i].Birth.month<10)cout <<"0";
- cout << List[i].Birth.month <<"."<< List[i].Birth.year <<"\t"<< List[i].Mark << endl;
- }
- }
- }
- void search_student(){
- int var;
- cout<<"Оберіть тип сортування: \n1.За прізвищем\n2.За середнім балом\n3.За датою народження\n";
- cout<<endl;
- cin>>var;
- switch (var){
- case 1: {
- surn();
- break;
- }
- case 2: {
- mark();
- break;
- }
- case 3: {
- bd();
- break;
- }
- default: cout<<"Оберіть один з видів сортування!\n";
- return search_student();
- }
- }
- void del(){
- int pos;
- cout << "Вкажіть номер студента, якого бажаєте видалити: ";
- cin>>pos;
- pos--;
- N--;
- Student* Temp=new Student[N];
- for(int i=0; i<pos; i++)
- Temp[i]=List[i];
- for(int i=pos+1; i<N+1; i++)
- Temp[i-1]=List[i];
- delete[] List;
- List=Temp;
- cout << "Студента видалено!!" << endl;
- }
- int main(){
- system("chcp 1251");
- int var;
- for(;;){
- cout<<endl;
- cout << "Меню: " << endl;
- cout << "1.Додати нового студента" << endl;
- cout << "2.Вивести усю группу" << endl;
- cout << "3.Пошук" << endl;
- cout << "4.Видалення студента із заданим номером в списку" << endl;
- cout << "5.Вихід з програми" << endl;
- cout << endl;
- cin >> var;
- cout << endl;
- switch(var){
- case 1: {
- add_stud();
- break;
- }
- case 2:{
- print_group();
- break;
- }
- case 3:{
- search_student();
- break;
- }
- case 4:{
- del();
- break;
- }
- case 5:free(List); return 0;
- default:{
- cout << "Введено невірне значення. Спробуйте ще раз\n" << endl;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement