anon20016

Untitled

Nov 23rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.11 KB | None | 0 0
  1. // Добвать валидацию всего чего можно (вывести/удалить студента по номеру которого нет)
  2.  
  3.  
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8.  
  9. namespace Электронныйдневник
  10. {
  11.     public class Student
  12.     {
  13.         public string Name;
  14.         public string Surname;
  15.         public string Data;
  16.         public List<int> Marks;
  17.         public int ResultMark;
  18.  
  19.         // Пропуски
  20.         //
  21.  
  22.         public int Omissions;
  23.         private double average_mark;
  24.         private int[,] BetterMarks;
  25.         private int sum;
  26.  
  27.         // Конструкторы
  28.         public Student(string input)
  29.         {
  30.             // format : NAME SURNAME DOB {MARKS}
  31.             var temp = input.Split();
  32.             Name = temp[0];
  33.             Surname = temp[1];
  34.             Data = temp[2];
  35.             Marks = new List<int>();
  36.             for (int i = 3; i < temp.Length; i++)
  37.             {
  38.                 int c = 0;
  39.                 if (Int32.TryParse(temp[i], out c))
  40.                 {
  41.                     if (c > 0 && c < 6)
  42.                         Marks.Add(c);
  43.                 }
  44.                 else
  45.                 {
  46.                     if (temp[i] == "-")
  47.                     {
  48.                         Omissions++;
  49.                     }
  50.                 }
  51.             }
  52.             Analyse();
  53.         }
  54.         public Student(string name, string surname, string data, List<int> a)
  55.         {
  56.             Name = name;
  57.             Data = data;
  58.             Surname = surname;
  59.             Marks = a;
  60.             Analyse();
  61.         }
  62.  
  63.         // Методы
  64.         private void Analyse()
  65.         {
  66.             sum = 0;
  67.             foreach (var i in Marks)
  68.             {
  69.                 sum += i;
  70.             }
  71.             GetAverageMark();
  72.             ResultMark = GetRusultMark(average_mark);
  73.             GetBetterMarks();
  74.         }
  75.  
  76.         private void GetAverageMark()
  77.         {
  78.             average_mark = 0;
  79.             foreach (var i in Marks)
  80.             {
  81.                 average_mark += i;
  82.             }
  83.             average_mark = GetAverage(average_mark, Marks.Count);
  84.         }
  85.         private int GetRusultMark(double c)
  86.         {
  87.             return (int)(c + 0.5);
  88.         }
  89.         private double GetAverage(double sum, int count)
  90.         {
  91.             return sum / count;
  92.         }
  93.         private void GetBetterMarks()
  94.         {
  95.             BetterMarks = new int[6, 6];
  96.             for (int i = 0; i < 6; i++)
  97.             {
  98.                 // q - оценка, которой будем улучшать
  99.                 for (int q = i; q < 6; q++)
  100.                 {
  101.                     if (i > ResultMark)
  102.                     {
  103.                         int j = 0;
  104.                         for (j = 0; GetRusultMark(GetAverage(sum + j * q, Marks.Count + j)) != i; j++) ;
  105.                         BetterMarks[i, q] = j;
  106.                     }
  107.                 }
  108.             }
  109.         }
  110.  
  111.         /// <summary>
  112.         /// Addes mark to student
  113.         /// </summary>
  114.         /// <param name="m"></param>
  115.         public void SetMark(int m)
  116.         {
  117.            
  118.             Analyse();
  119.         }
  120.  
  121.         public string GetSmalInfo()
  122.         {
  123.             return Name + " " + Surname;
  124.         }
  125.         public string GetMediumInfo()
  126.         {
  127.             return Name + " " + Surname + 'n' + " Result mark: " + ResultMark;
  128.         }
  129.         public string GetLargeInfo() {
  130.             return Name + " " + Surname + '\n' + " Result mark: " + ResultMark + '\n' + "Omissions: " + Omissions;
  131.         }
  132.  
  133.         public int CompareTo_Name(Student b)
  134.         {
  135.             if (string.Compare(Surname, b.Surname) > 0) {
  136.                 return 1;
  137.             }
  138.             if (string.Compare(Surname, b.Surname) < 0)
  139.             {
  140.                 return -1;
  141.             }
  142.             if (string.Compare(Name, b.Name) > 0)
  143.             {
  144.                 return 1;
  145.             }
  146.             if (string.Compare(Name, b.Name) < 0)
  147.             {
  148.                 return -1;
  149.             }
  150.             return 0;
  151.         }
  152.         public override string ToString()
  153.         {
  154.             string result = "Info about student " + Name + " " + Surname + "\n" + "Date of Birth: " + Data + "\n" + "Marks: ";
  155.             for (int i = 0; i < Marks.Count; i++)
  156.             {
  157.                 result += Marks[i].ToString();
  158.                 if (i != Marks.Count - 1)
  159.                 {
  160.                     result += ", ";
  161.                 }
  162.             }
  163.             result += '\n' + "Result mark – " + ResultMark.ToString() + '\n' + "Omissions: " + Omissions + '\n';
  164.  
  165.             for (int i = 0; i < 6; i++)
  166.             {
  167.                 for (int j = 0; j < 6; j++)
  168.                 {
  169.                     if (BetterMarks[i, j] != 0)
  170.                     {
  171.                         result += "To get " + i.ToString() + " you have to get " + BetterMarks[i, j].ToString() + " marks " + j.ToString() + '\n';
  172.                     }
  173.                 }
  174.             }
  175.  
  176.             return result;
  177.         }
  178.     }
  179.     public class Class
  180.     {
  181.         string Name;
  182.         public List<Student> Students;
  183.         int Count;
  184.  
  185.         public Class()
  186.         {
  187.             Name = "None";
  188.             Students = new List<Student>();
  189.         }
  190.         public Class(string name)
  191.         {
  192.             Name = name;
  193.             Students = new List<Student>();        
  194.         }
  195.         public Class(string name, List<Student> a)
  196.         {
  197.             Name = name;
  198.             Students = a;
  199.             Count = a.Count;
  200.             sort();
  201.         }
  202.  
  203.  
  204.         /// <summary>
  205.         /// Adds new student to class
  206.         /// </summary>
  207.         /// <param name="st"></param>
  208.         public void Add(Student st)
  209.         {
  210.             Students.Add(st);
  211.             Count++;
  212.             sort();
  213.         }
  214.         /// <summary>
  215.         /// returns student dy index
  216.         /// </summary>
  217.         /// <param name="x">index in sorted list</param>
  218.         /// <returns></returns>
  219.         public Student GetByIndex(int x)
  220.         {
  221.             return Students[x - 1];
  222.         }
  223.  
  224.         /// <summary>
  225.         /// Deletes Student by index
  226.         /// </summary>
  227.         /// <param name="x"></param>
  228.         public void DeleteByIndex(int x)
  229.         {
  230.             Students.RemoveAt(x - 1);
  231.             Count--;
  232.         }
  233.  
  234.         /// <summary>
  235.         /// Returns list whith Names and Surnames
  236.         /// </summary>
  237.         /// <returns></returns>
  238.         public string GetSmallList()
  239.         {
  240.             string res = "Name of class: " + Name + '\n';
  241.  
  242.             for (int i = 0; i < Count; i++)
  243.             {
  244.                 res += (i + 1).ToString() + ") " + Students[i].GetSmalInfo() + '\n';
  245.             }
  246.             return res;
  247.         }
  248.         /// <summary>
  249.         /// Returns List whith Name Surname Result Mark
  250.         /// </summary>
  251.         /// <returns></returns>
  252.         public string GetMediumList()
  253.         {
  254.             string res = "Name of class: " + Name + '\n';
  255.  
  256.             for (int i = 0; i < Count; i++)
  257.             {
  258.                 res += (i + 1).ToString() + ") " + Students[i].GetMediumInfo() + '\n' ;
  259.             }
  260.             return res;
  261.         }
  262.         /// <summary>
  263.         /// Returns List whith Name Surname Day of Birth Result Mark Omissions
  264.         /// </summary>
  265.         /// <returns></returns>
  266.         public string GetLargeList()
  267.         {
  268.             string res = "Name of class: " + Name + '\n';
  269.  
  270.             for (int i = 0; i < Count; i++)
  271.             {
  272.                 res += (i + 1).ToString() + ") " + Students[i].GetLargeInfo() + '\n' ;
  273.             }
  274.             return res;
  275.         }
  276.  
  277.         /// <summary>
  278.         /// returns rating of student
  279.         /// </summary>
  280.         /// <param name="name"></param>
  281.         /// <param name="surname"></param>
  282.         /// <returns></returns>
  283.         public int Rating(string name, string surname)
  284.         {
  285.  
  286.         }
  287.  
  288.         /// <summary>
  289.         /// Sorts students by parametr
  290.         /// </summary>
  291.         /// <param name="cmp">"name" / "mark"</param>
  292.         private void sort(string cmp)
  293.         {
  294.             for (int i = 0; i < Count; i++)
  295.             {
  296.                 for (int j = 1; j < Count - 1; j++)
  297.                 {
  298.                     //
  299.                     if  (Students[j].CompareTo_Name(Students[j + 1]) < 0)
  300.                     {
  301.                         var temp = Students[j];
  302.                         Students[j] = Students[j + 1];
  303.                         Students[j + 1] = temp;
  304.                     }
  305.                 }
  306.             }
  307.         }
  308.         public override string ToString()
  309.         {
  310.             string res = "Name of class: " + Name + '\n';
  311.  
  312.             for (int i = 0; i < Count; i++)
  313.             {
  314.                 res += (i + 1).ToString() + ") " + Students[i].ToString() + '\n';
  315.             }            
  316.             return res;
  317.         }
  318.     }
  319.  
  320.     class Program
  321.     {
  322.         static void Main(string[] args)
  323.         {
  324.             StreamReader reader = new StreamReader("data.txt");
  325.             int n = Int32.Parse(reader.ReadLine());
  326.             Class t = new Class("Name");
  327.             for (int i =0; i < n; i++)
  328.             {
  329.                 t.Add(new Student(reader.ReadLine()));                
  330.             }
  331.             Console.WriteLine(t);
  332.         }
  333.     }
  334. }
Advertisement
Add Comment
Please, Sign In to add comment