Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading;
- namespace university
- {
- //class Money
- //{
- // public int first { get; set; }
- // public int second { get; set; }
- // public Money(int f, int s)
- // {
- // first = f;
- // second = s;
- // }
- // public int All_money()
- // {
- // return first * second;
- // }
- // public bool Enough_Money(int n)
- // {
- // if (All_money() >= n)
- // return true;
- // return false;
- // }
- // //Money m = new Money(500, 3);
- // //Console.WriteLine(String.Format("Номинал = {0} рублей, количество = {1}, общая сумма = {2} рублей", m.first, m.second, m.All_money()));
- // //Console.WriteLine("Введите стоимость товара");
- // //int n = Convert.ToInt32(Console.ReadLine());
- // //if (m.Enough_Money(n))
- // // Console.WriteLine(String.Format("Денег хватит на покупку товара стоимостью {0} рублей." +
- // // "\nУ вас останется {1} рублей", n, m.All_money() - n));
- // //else
- // // Console.WriteLine(String.Format("Вам не хватает {0}", n - m.All_money()));
- //}
- class Person
- {
- private string first_name;
- private string second_name;
- private DateTime DateOfBirth;
- public string F_name
- {
- get
- {
- return first_name;
- }
- }
- public string S_name
- {
- get
- {
- return second_name;
- }
- }
- public DateTime Date
- {
- get
- {
- return DateOfBirth;
- }
- }
- public int DateYear
- {
- get
- {
- return DateOfBirth.Year;
- }
- set
- {
- DateOfBirth = new DateTime(value, DateOfBirth.Month, DateOfBirth.Day);
- }
- }
- public Person(string f_n, string s_n, System.DateTime dob)
- {
- first_name = f_n;
- second_name = s_n;
- DateOfBirth = dob;
- }
- public Person()
- {
- first_name = "Ivan";
- second_name = "Ivanov";
- DateOfBirth = System.DateTime.Now;
- }
- public override string ToString()
- {
- return first_name.ToString() + ", " + second_name.ToString() + ", " + DateOfBirth.ToString();
- }
- public virtual string ToShortString()
- {
- return first_name.ToString() + ", " + second_name.ToString();
- }
- }
- enum Education
- {
- Specialist = 0,
- Вachelor = 1,
- SecondEducation = 2
- }
- class Exam
- {
- public string name { get; set; }
- public int rating { get; set; }
- public DateTime exam_date { get; set; }
- public Exam(string n, int r, DateTime d)
- {
- name = n;
- rating = r;
- exam_date = d;
- }
- public Exam()
- {
- name = "Unknown";
- rating = 0;
- exam_date = DateTime.Now;
- }
- public override string ToString()
- {
- return name.ToString() + ", " + rating.ToString() + ", " + exam_date.ToString();
- }
- }
- class Student
- {
- public Person student_data { get; set; }
- public Education education_type { get; set; }
- public int group_number { get; set; }
- List<Exam> passed_exams { get; set; } = new List<Exam>();
- public double average_score
- {
- get
- {
- int sum = 0;
- for (int i = 0; i< passed_exams.Count; i++)
- {
- sum += passed_exams[i].rating;
- }
- if (passed_exams.Count > 0)
- return sum * 1.0/ passed_exams.Count;
- return 0.0;
- }
- }
- public Student(Person p, Education e, int g)
- {
- student_data = p;
- education_type = e;
- group_number = g;
- }
- public Student()
- {
- student_data = new Person();
- education_type = Education.Вachelor;
- group_number = 0;
- }
- public bool this [Education e]
- {
- get
- {
- if (education_type == e)
- return true;
- return false;
- }
- }
- public void AddExam(Exam[] e)
- {
- for (int i =0; i< e.Length; i++)
- {
- passed_exams.Add(e[i]);
- }
- }
- public override string ToString()
- {
- string t = "";
- for (int i = 0; i< passed_exams.Count; i++)
- {
- t += passed_exams[i].ToString() + '\n';
- }
- if (t == "")
- t = "not found exams";
- return String.Format("about student: {0}\neducation_type: {1}\ngroup number: {2}\naverage score: {3}\nexams: {4}",
- student_data.ToString(), education_type.ToString(), group_number.ToString(), average_score.ToString(), t);
- }
- public virtual string ToShortString()
- {
- return String.Format("about student: {0}\neducation_type: {1}\ngroup number: {2}\naverage score: {3}",
- student_data.ToString(), education_type.ToString(), group_number.ToString(), average_score.ToString());
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- // одномерный массив
- Stopwatch sw = new Stopwatch();
- sw.Start();
- Exam[] exams1 = new Exam[1000000];
- for (int i = 0; i < 1000000; i++)
- {
- exams1[i] = new Exam();
- }
- sw.Stop();
- Console.WriteLine("одномерный массив");
- Console.WriteLine((sw.ElapsedMilliseconds / 1000.0).ToString());
- // прямоугольный
- Stopwatch sw2 = new Stopwatch();
- sw2.Start();
- Exam[,] exams2 = new Exam[200, 5000];
- int rows = exams2.GetUpperBound(0) + 1;
- int columns = exams2.Length / rows;
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < columns; j++)
- {
- exams2[i, j] = new Exam();
- }
- }
- sw2.Stop();
- Console.WriteLine("прямоугольный массив");
- Console.WriteLine((sw2.ElapsedMilliseconds / 1000.0).ToString());
- // ступенчатый (зубчатым)
- Stopwatch sw3 = new Stopwatch();
- sw3.Start();
- Exam[][] exams3 = new Exam[5][];
- exams3[0] = new Exam[300000];
- exams3[1] = new Exam[20000];
- exams3[2] = new Exam[30000];
- exams3[3] = new Exam[50000];
- exams3[4] = new Exam[600000];
- for (int i = 0; i < exams3.Length; i++)
- {
- for (int j = 0; j < exams3[i].Length; j++)
- {
- exams3[i][j] = new Exam();
- }
- }
- sw3.Stop();
- Console.WriteLine("ступенчатый массив");
- Console.WriteLine((sw3.ElapsedMilliseconds / 1000.0).ToString());
- ////////////////////////////////////////////////////////////////////////////////////////
- // первая часть задания
- Student student = new Student();
- Console.WriteLine(student.ToShortString());
- Console.WriteLine("----------------------------");
- // вторая часть
- foreach (Education e in Enum.GetValues(typeof(Education)))
- {
- Console.WriteLine(student[e]);
- }
- // получили True для Bachelor, так как по умолчанию задается Education.Bachelor
- Console.WriteLine("----------------------------");
- //третья часть
- Console.Write("Введите имя: ");
- string first_name = Console.ReadLine();
- Console.Write("Введите фамилию: ");
- string second_name = Console.ReadLine();
- Console.Write("Введите дату рождения и время (в формате: год месяц день час минута cекунда): ");
- int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
- DateTime dof = new DateTime(a[0], a[1], a[2], a[3], a[4], a[5]);
- //Console.Write("Введите год рождения: ");
- //int y = Convert.ToInt32(Console.ReadLine());
- //Console.Write("Введите месяц рождения: ");
- //int m = Convert.ToInt32(Console.ReadLine());
- //Console.Write("Введите день рождения: ");
- //int d = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите номер группы: ");
- int g = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите уровень образования: ");
- string l = Console.ReadLine();
- if (l == " Second Education ")
- student.education_type = Education.SecondEducation;
- else if (l == "Specialist")
- student.education_type = Education.Specialist;
- else
- student.education_type = Education.Вachelor;
- student.student_data = new Person(first_name, second_name, dof);
- student.group_number = g;
- Console.WriteLine("----------------------------");
- Console.WriteLine(student.ToString());
- // четвертая часть
- Console.WriteLine("----------------------------");
- Console.Write("Введите количество экзаменов: ");
- int k = Convert.ToInt32(Console.ReadLine());
- Exam[] exams = new Exam[k];
- for (int i = 0;i<k;i++)
- {
- Console.Write("Введите название предмета: ");
- string p_name = Console.ReadLine();
- Console.Write("Введите оценку за экзамен: ");
- int rate = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите дату предмета и время (в формате: год месяц день час минута cекунда): ");
- int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
- DateTime dt = new DateTime(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]);
- exams[i] = new Exam(p_name, rate, dt);
- Console.WriteLine("Информация об экзамене добавлена");
- }
- student.AddExam(exams);
- Console.WriteLine("Экзамены добавлены");
- Console.WriteLine("----------------------------");
- Console.WriteLine(student.ToString());
- Console.WriteLine("----------------------------");
- ////пятая часть
- //// одномерный массив
- //Stopwatch sw = new Stopwatch();
- //sw.Start();
- //Exam[] exams1 = new Exam[1000000];
- //for (int i=0;i< 1000000; i++)
- //{
- // exams1[i] = new Exam();
- //}
- //sw.Stop();
- //Console.WriteLine("одномерный массив");
- //Console.WriteLine((sw.ElapsedMilliseconds / 1000.0).ToString());
- //// прямоугольный
- //Stopwatch sw2 = new Stopwatch();
- //sw2.Start();
- //Exam[,] exams2 = new Exam[200, 5000];
- //int rows = exams2.GetUpperBound(0) + 1;
- //int columns = exams2.Length / rows;
- //for (int i = 0; i < rows; i++)
- //{
- // for (int j = 0; j < columns; j++)
- // {
- // exams2[i,j] = new Exam();
- // }
- //}
- //sw2.Stop();
- //Console.WriteLine("прямоугольный массив");
- //Console.WriteLine((sw2.ElapsedMilliseconds / 1000.0).ToString());
- //// ступенчатый (зубчатым)
- //Stopwatch sw3 = new Stopwatch();
- //sw3.Start();
- //Exam[][] exams3 = new Exam[5][];
- //exams3[0] = new Exam[300000];
- //exams3[1] = new Exam[20000];
- //exams3[2] = new Exam[30000];
- //exams3[3] = new Exam[50000];
- //exams3[4] = new Exam[600000];
- //for (int i = 0; i< exams3.Length; i++)
- //{
- // for (int j = 0; j < exams3[i].Length; j++)
- // {
- // exams3[i][j] = new Exam();
- // }
- //}
- //sw3.Stop();
- //Console.WriteLine("ступенчатый массив");
- //Console.WriteLine((sw3.ElapsedMilliseconds / 1000.0).ToString());
- }
- }
- }
Add Comment
Please, Sign In to add comment