Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Students
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- }
- private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
- {
- }
- }
- class Group
- {
- class Student : Group
- {
- private string Surname;
- private string Name;
- private string Middlename;
- private int salary;
- private bool sessionclosed = false;
- private int[] Marks;
- private int[] Credits;
- public Student()
- {
- Surname = null;
- Name = null;
- Middlename = null;
- salary = 0;
- sessionclosed = false;
- Marks = null;
- Credits = null;
- }
- public Student(string SN, string N, string MN, int[] marks, int[] credits, int Salary)
- {
- if ((SN != null) && (N != null) && (MN != null))
- {
- Surname = SN;
- Name = N;
- Middlename = MN;
- }
- else
- {
- Surname = null;
- Name = null;
- Middlename = null;
- }
- if (marks.Length != 0)
- {
- Marks = new int[marks.Length];
- for (int i = 0; i < marks.Length; i++)
- {
- Marks[i] = marks[i];
- }
- }
- else
- Marks = null;
- if ((credits.Length > 0) && (credits.Length < 13))
- {
- Credits = new int[credits.Length];
- for (int i = 0; i < credits.Length; i++)
- {
- Credits[i] = credits[i];
- }
- }
- else
- Credits = null;
- if (Salary != 0)
- salary = Salary;
- else
- salary = 0;
- }
- public string surname
- {
- get { return Surname; }
- set { Surname = value; }
- }
- public string name
- {
- get { return Name; }
- set { Name = value; }
- }
- public string middlename
- {
- get { return Middlename; }
- set { Middlename = value; }
- }
- public int SALARY
- {
- get { return salary; }
- set { salary = value; }
- }
- public bool Sessionclosed
- {
- get { return sessionclosed; }
- set { sessionclosed = value; }
- }
- public int[] MARKS
- {
- get { return Marks; }
- set { Marks = value; }
- }
- public int[] CREDITS
- {
- get { return Credits; }
- set { Credits = value; }
- }
- public static bool operator ==(Student A, Student B) //перегрузка операторов == !=
- {
- string Id1 = A.Surname + ' ' + A.Name + ' ' + A.Middlename;
- string Id2 = B.Surname + ' ' + B.Name + ' ' + B.Middlename;
- if ((Id1 == Id2) && (A.Marks == B.Marks) && (A.Credits == B.Credits) && (A.salary == B.salary))
- return true;
- else
- return false;
- }
- public static bool operator !=(Student A, Student B)
- {
- string Id1 = A.Surname + ' ' + A.Name + ' ' + A.Middlename;
- string Id2 = B.Surname + ' ' + B.Name + ' ' + B.Middlename;
- if ((Id1 == Id2) && (A.Marks == B.Marks) && (A.Credits == B.Credits) && (A.salary == B.salary))
- return false;
- else
- return true;
- }
- public static bool operator true(Student A) //перегрузка операторов true false
- {
- bool B = false;
- bool C = false;
- for (int i = 0; i < A.Marks.Length; i++)
- {
- if ((A.Marks[i] == 4) || (A.Marks[i] == 5)) //добавить про кредитс
- B = true;
- else
- C = true;
- }
- if (B && !C)
- return true;
- else
- return false;
- }
- public static bool operator false(Student A)
- {
- bool B = false;
- for (int i = 0; i < A.Marks.Length; i++)
- {
- if ((A.Marks[i] != 4) || (A.Marks[i] != 5)) //добавить про кредитс
- B = true;
- }
- if (B)
- return true;
- else
- return false;
- }
- }
- private string namegroup;
- private int countStudents;
- private LinkedList<Student> listGroup;
- private int countMarks;
- private int countCredits;
- private string[] NameSubject;
- private string[] NameCredits;
- private int course;
- public Group()
- { namegroup = null; listGroup = null; countStudents = 0; countCredits = 0; countMarks = 0; course = 0;
- NameCredits = null; NameSubject = null;}
- public Group(string NameG, int crs, string[] NameS, string[] NameC)
- {
- if (NameG != null)
- namegroup = NameG;
- else
- namegroup = null;
- if ((crs > 0) && (crs <7))
- course = crs;
- else
- course = 0;
- if (NameS.Length != 0)
- {
- countMarks = NameS.Length;
- for (int i=0; i<NameS.Length;i++)
- NameSubject[i] = NameS[i];
- }
- else
- {
- countMarks = 0;
- NameSubject = null;
- }
- if (NameC.Length != 0)
- {
- countCredits = NameC.Length;
- for (int i=0; i<NameC.Length;i++)
- NameCredits[i] = NameC[i];
- }
- else
- {
- countCredits = 0;
- NameCredits = null;
- }
- countStudents = 0;
- listGroup = null;
- }
- public string NameGr
- {
- get { return namegroup;}
- set { namegroup = value;}
- }
- public int countStuds
- {
- get { return countStudents;}
- set { countStudents = value;}
- }
- public int countMrks
- {
- get { return countMarks;}
- set { countMarks = value;}
- }
- public int countCreds
- {
- get { return countCredits;}
- set { countCredits = value;}
- }
- public int Course
- {
- get { return course;}
- set { course = value;}
- }
- public string[] Subs
- {
- get { return NameSubject;}
- set { NameSubject = value;}
- }
- public string[] Creds
- {
- get { return NameCredits;}
- set { NameCredits = value;}
- }
- public LinkedList<Student> List
- {
- get { return listGroup; }
- set { listGroup = value;}
- }
- public Group ReadFromFile(string NameFile) //считывает файл
- {
- Group G = new Group();
- if (NameFile != null)
- {
- try
- {
- StreamReader stream = new StreamReader(NameFile);
- string Str = stream.ReadToEnd();
- char[] sprt = { '\n', ':' };
- string[] Mas = Str.Split(sprt);
- for (int i = 0; i < Mas.Length; i++)
- {
- if (Mas[i] == "Group")
- namegroup = Mas[i + 1];
- if (Mas[i] == "Course")
- course = Convert.ToInt32(Mas[i + 1]);
- if (Mas[i] == "Subjects")
- {
- for (int q = i + 1; Mas[i] != "Credits"; q++)
- {
- int k = 0;
- NameSubject[k] = Mas[q];
- k++;
- }
- }
- if (Mas[i] == "Credits")
- {
- for (int f = i + 1; Mas[i] != "Students"; f++)
- {
- int m = 0;
- NameCredits[m] = Mas[f];
- m++;
- }
- }
- if (Mas[i] == "Students") //добавление студентов в список
- {
- char[] sprt2 = { ' ', '[', ']', '{', '}' };
- string[] Info;
- int n = 0; //считает количество студентов
- for (int j = i + 1; j < Mas.Length; j++)
- {
- n++;
- Info = Mas[j].Split(sprt2);
- Student S = new Student();
- listGroup.AddLast(S);
- }
- countStudents = n;
- }
- }
- }
- catch
- {
- MessageBox.Show("Неверный формат данных");
- }
- }
- else
- G = null;
- return G;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement