Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- using System.Text;
- using System.Threading.Tasks;
- namespace Лаба2
- {
- class Program
- {
- public static void Main(string[] args)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Title = " База данных ";
- string menu = null;
- string end = "1";
- while (end != "2")
- {
- while (menu != "1" && menu != "2" && menu != "3" && menu != "4")
- {
- Console.WriteLine($"\nСтуденты: \nВывести список - 1 \n\nДобавить студента в список - 2 \n\nУдалить студента из списка - 3 \n\nНайти студента по ФИО в списке - 4 \n\nНайти студента по дате рождения в спике - 5 \n\nСортировать список - 6");
- menu = Console.ReadLine();
- }
- switch (menu)
- {
- case ("1"):
- TeloBD();
- break;
- case ("2"):
- showbd();
- break;
- case ("3"):
- sort();
- break;
- case ("4"):
- Poisk();
- break;
- }
- menu = null;
- Console.WriteLine($"\nПовторить программу? 1 - да. 2 - нет.");
- end = Console.ReadLine();
- }
- }
- public static void showbd()
- {
- //StreamReader fr = new StreamReader("BD.txt", Encoding.Default);
- //string[] Filemass = fr.ReadToEnd().Split(Console.WriteLine());
- string[] name = File.ReadAllLines("BD.txt", Encoding.Default);
- foreach (string show in name)
- {
- Console.WriteLine(show);
- }
- }
- public static void TeloBD()
- {
- StreamReader fr = new StreamReader("BD.txt", Encoding.Default);
- string[] Filemass = fr.ReadToEnd().Split('\n' );
- StreamReader fileRead = new StreamReader("BD.txt", Encoding.Default);
- string[] Filemass1 = fileRead.ReadToEnd().Split('#');
- int countBds = Filemass1.Length - 1;
- string[,] bds = new string[countBds,8];
- int n = 0;
- double[] ocenka = new double[countBds];
- for (int i = 0; i<countBds; i++)
- {
- for (int j = 0; j < 8; j++)
- {
- bds[i,j] += $" {Filemass[n]}";
- n++;
- }
- }
- for (int i=0; i< countBds; i++)
- {
- ocenka[i] = Convert.ToDouble(bds[i, 6]);
- }
- string[] maxOcenka = new string[countBds];
- maxOcenka[0] = Convert.ToString($" Максимальный балл - {ocenka.Max()} имеет(имеют):");
- string[] minOcenka = new string[countBds];
- minOcenka[0] = Convert.ToString($" Минимальный балл - {ocenka.Min()} имеет(имеют): ");
- double middleOcenka = 0;
- for(int i = 0; i < countBds; i++)
- {
- middleOcenka += ocenka[i];
- if (ocenka.Max() == Convert.ToDouble(bds[i, 6]))
- {
- if (i == 0)
- {
- maxOcenka[i] += $"\n-{bds[i, 1]} ";
- }
- else
- {
- maxOcenka[i] += $"-{bds[i,1]} ";
- }
- }
- if (ocenka.Min() == Convert.ToDouble(bds[i, 6]))
- {
- if (i == 0)
- {
- minOcenka[i] += $"\n-{bds[i, 1]} ";
- }
- else
- {
- minOcenka[i] += $"-{bds[i,1]} ";
- }
- }
- }
- middleOcenka = middleOcenka / countBds;
- for (int i = 0; i < countBds; i++)
- {
- //Console.WriteLine("\n");
- for(int j =0; j<8; j++)
- {
- Console.WriteLine(bds[i,j]);
- }
- }
- foreach (string show in maxOcenka)
- {
- if (show != null)
- {
- Console.WriteLine($"{show}");
- }
- }
- Console.WriteLine("\n");
- foreach (string show in minOcenka)
- {
- if (show != null)
- {
- Console.WriteLine($"{show}");
- }
- }
- Console.WriteLine("\n");
- Console.WriteLine($" Средняя оценка студентов - {middleOcenka}");
- }
- public static void Poisk()
- {
- Console.WriteLine("\nВведите имя студента или его дату рождения:");
- StreamReader fileRead = new StreamReader("BD.txt", Encoding.Default);
- string[] Filemass1 = fileRead.ReadToEnd().Split('#');
- int countBds = Filemass1.Length - 1;
- string[] Filemass = File.ReadAllLines("BD.txt", Encoding.Default);
- string[,] bds = new string[countBds, 8];
- int n = 0;
- for (int i = 0; i < countBds; i++)
- {
- for (int j = 0; j < 8; j++)
- {
- bds[i, j] = Filemass[n];
- n++;
- }
- }
- //string name1;
- string name;
- name = Console.ReadLine();
- Console.WriteLine();
- for (int i = 0; i < countBds; i++)
- {
- if (Equals(name, bds[i, 1]))
- {
- Console.WriteLine($"\nДосье на {name}: ");
- for (int j = 0; j < 8; j++)
- {
- Console.WriteLine(bds[i,j]);
- }
- }
- if (Equals(name, bds[i, 2]))
- {
- Console.WriteLine($"\nДосье на на студента с датой рождениея {name} ");
- for (int j = 0; j < 8; j++)
- {
- Console.WriteLine(bds[i, j]);
- }
- }
- }
- Console.WriteLine($"\nКонец поиска.");
- }
- static void trydo()
- {
- int n = 0;
- StreamReader fileRead = new StreamReader("BD.txt", Encoding.Default);
- string[] Filemass1 = fileRead.ReadToEnd().Split('#');
- int countBds = Filemass1.Length - 1;
- string [] text = File.ReadAllLines("BD.txt", Encoding.Default);
- string[,] bds = new string[countBds, 8];
- for (int i = 0; i < countBds; i++)
- {
- for (int j = 0; j < 8; j++)
- {
- bds[i, j] = text[n];
- n++;
- Console.WriteLine($"{bds[i,j]}");
- }
- }
- }
- static void sort()
- {
- StreamReader fileRead = new StreamReader("BD.txt", Encoding.Default);
- string[] Filemass1 = fileRead.ReadToEnd().Split('#');
- int countBds = Filemass1.Length - 1;
- string[] Filemass = File.ReadAllLines("BD.txt", Encoding.Default);
- string[,] bds = new string[countBds, 8];
- int n = 0;
- string[] sort = new string[countBds];
- int[] getsort = new int[countBds];
- for (int i = 0; i < countBds; i++)
- {
- for (int j = 0; j < 8; j++)
- {
- bds[i, j] = Filemass[n];
- n++;
- }
- }
- for (int i = 0; i< countBds; i++)
- {
- sort[i] = $"{bds[i,1]} {i}";
- }
- Array.Sort(sort);
- string help = null;
- for (int i = 0; i < countBds; i++)
- {
- help = sort[i];
- sort[i] = help[help.Length-1].ToString();
- getsort[i] = Convert.ToInt32(sort[i]);
- }
- Console.WriteLine($"\nСортировка по алфовиту:\n");
- for (int i =0; i<countBds; i++)
- {
- for (int j = 0; j<8; j++)
- {
- Console.WriteLine(bds[getsort[i], j]);
- }
- }
- //sort data.
- }
- static void ADDDELL()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement