Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Добвать валидацию всего чего можно (вывести/удалить студента по номеру которого нет)
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace Электронныйдневник
- {
- public class Student
- {
- public string Name;
- public string Surname;
- public string Data;
- public List<int> Marks;
- public int ResultMark;
- // Пропуски
- //
- public int Omissions;
- private double average_mark;
- private int[,] BetterMarks;
- private int sum;
- // Конструкторы
- public Student(string input)
- {
- // format : NAME SURNAME DOB {MARKS}
- var temp = input.Split();
- Name = temp[0];
- Surname = temp[1];
- Data = temp[2];
- Marks = new List<int>();
- for (int i = 3; i < temp.Length; i++)
- {
- int c = 0;
- if (Int32.TryParse(temp[i], out c))
- {
- if (c > 0 && c < 6)
- Marks.Add(c);
- }
- else
- {
- if (temp[i] == "-")
- {
- Omissions++;
- }
- }
- }
- Analyse();
- }
- public Student(string name, string surname, string data, List<int> a)
- {
- Name = name;
- Data = data;
- Surname = surname;
- Marks = a;
- Analyse();
- }
- // Методы
- private void Analyse()
- {
- sum = 0;
- foreach (var i in Marks)
- {
- sum += i;
- }
- GetAverageMark();
- ResultMark = GetRusultMark(average_mark);
- GetBetterMarks();
- }
- private void GetAverageMark()
- {
- average_mark = 0;
- foreach (var i in Marks)
- {
- average_mark += i;
- }
- average_mark = GetAverage(average_mark, Marks.Count);
- }
- private int GetRusultMark(double c)
- {
- return (int)(c + 0.5);
- }
- private double GetAverage(double sum, int count)
- {
- return sum / count;
- }
- private void GetBetterMarks()
- {
- BetterMarks = new int[6, 6];
- for (int i = 0; i < 6; i++)
- {
- // q - оценка, которой будем улучшать
- for (int q = i; q < 6; q++)
- {
- if (i > ResultMark)
- {
- int j = 0;
- for (j = 0; GetRusultMark(GetAverage(sum + j * q, Marks.Count + j)) != i; j++) ;
- BetterMarks[i, q] = j;
- }
- }
- }
- }
- /// <summary>
- /// Addes mark to student
- /// </summary>
- /// <param name="m"></param>
- public void SetMark(int m)
- {
- Analyse();
- }
- public string GetSmalInfo()
- {
- return Name + " " + Surname;
- }
- public string GetMediumInfo()
- {
- return Name + " " + Surname + 'n' + " Result mark: " + ResultMark;
- }
- public string GetLargeInfo() {
- return Name + " " + Surname + '\n' + " Result mark: " + ResultMark + '\n' + "Omissions: " + Omissions;
- }
- public int CompareTo_Name(Student b)
- {
- if (string.Compare(Surname, b.Surname) > 0) {
- return 1;
- }
- if (string.Compare(Surname, b.Surname) < 0)
- {
- return -1;
- }
- if (string.Compare(Name, b.Name) > 0)
- {
- return 1;
- }
- if (string.Compare(Name, b.Name) < 0)
- {
- return -1;
- }
- return 0;
- }
- public override string ToString()
- {
- string result = "Info about student " + Name + " " + Surname + "\n" + "Date of Birth: " + Data + "\n" + "Marks: ";
- for (int i = 0; i < Marks.Count; i++)
- {
- result += Marks[i].ToString();
- if (i != Marks.Count - 1)
- {
- result += ", ";
- }
- }
- result += '\n' + "Result mark – " + ResultMark.ToString() + '\n' + "Omissions: " + Omissions + '\n';
- for (int i = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++)
- {
- if (BetterMarks[i, j] != 0)
- {
- result += "To get " + i.ToString() + " you have to get " + BetterMarks[i, j].ToString() + " marks " + j.ToString() + '\n';
- }
- }
- }
- return result;
- }
- }
- public class Class
- {
- string Name;
- public List<Student> Students;
- int Count;
- public Class()
- {
- Name = "None";
- Students = new List<Student>();
- }
- public Class(string name)
- {
- Name = name;
- Students = new List<Student>();
- }
- public Class(string name, List<Student> a)
- {
- Name = name;
- Students = a;
- Count = a.Count;
- sort();
- }
- /// <summary>
- /// Adds new student to class
- /// </summary>
- /// <param name="st"></param>
- public void Add(Student st)
- {
- Students.Add(st);
- Count++;
- sort();
- }
- /// <summary>
- /// returns student dy index
- /// </summary>
- /// <param name="x">index in sorted list</param>
- /// <returns></returns>
- public Student GetByIndex(int x)
- {
- return Students[x - 1];
- }
- /// <summary>
- /// Deletes Student by index
- /// </summary>
- /// <param name="x"></param>
- public void DeleteByIndex(int x)
- {
- Students.RemoveAt(x - 1);
- Count--;
- }
- /// <summary>
- /// Returns list whith Names and Surnames
- /// </summary>
- /// <returns></returns>
- public string GetSmallList()
- {
- string res = "Name of class: " + Name + '\n';
- for (int i = 0; i < Count; i++)
- {
- res += (i + 1).ToString() + ") " + Students[i].GetSmalInfo() + '\n';
- }
- return res;
- }
- /// <summary>
- /// Returns List whith Name Surname Result Mark
- /// </summary>
- /// <returns></returns>
- public string GetMediumList()
- {
- string res = "Name of class: " + Name + '\n';
- for (int i = 0; i < Count; i++)
- {
- res += (i + 1).ToString() + ") " + Students[i].GetMediumInfo() + '\n' ;
- }
- return res;
- }
- /// <summary>
- /// Returns List whith Name Surname Day of Birth Result Mark Omissions
- /// </summary>
- /// <returns></returns>
- public string GetLargeList()
- {
- string res = "Name of class: " + Name + '\n';
- for (int i = 0; i < Count; i++)
- {
- res += (i + 1).ToString() + ") " + Students[i].GetLargeInfo() + '\n' ;
- }
- return res;
- }
- /// <summary>
- /// returns rating of student
- /// </summary>
- /// <param name="name"></param>
- /// <param name="surname"></param>
- /// <returns></returns>
- public int Rating(string name, string surname)
- {
- }
- /// <summary>
- /// Sorts students by parametr
- /// </summary>
- /// <param name="cmp">"name" / "mark"</param>
- private void sort(string cmp)
- {
- for (int i = 0; i < Count; i++)
- {
- for (int j = 1; j < Count - 1; j++)
- {
- //
- if (Students[j].CompareTo_Name(Students[j + 1]) < 0)
- {
- var temp = Students[j];
- Students[j] = Students[j + 1];
- Students[j + 1] = temp;
- }
- }
- }
- }
- public override string ToString()
- {
- string res = "Name of class: " + Name + '\n';
- for (int i = 0; i < Count; i++)
- {
- res += (i + 1).ToString() + ") " + Students[i].ToString() + '\n';
- }
- return res;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- StreamReader reader = new StreamReader("data.txt");
- int n = Int32.Parse(reader.ReadLine());
- Class t = new Class("Name");
- for (int i =0; i < n; i++)
- {
- t.Add(new Student(reader.ReadLine()));
- }
- Console.WriteLine(t);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment