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.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- public class Person /////Определить класс Person, который имеет
- {
- private string name1; ////////////· закрытое поле типа string, в котором хранится имя;
- ///////· конструктор без параметров, инициализирующий все поля класса некоторыми значениями по умолчанию.
- private string name2; /////////· закрытое поле типа string, в котором хранится фамилия;
- private System.DateTime birth; ///////////////· закрытое поле типа System.DateTime для даты рождения.
- public Person()
- {
- name1 = "polya";
- name2 = "ivanova";
- birth = new DateTime(1999, 11, 22);
- }
- public Person(string n1, string n2, DateTime b)
- {
- this.name1 = n1;
- this.name2 = n2;
- this.birth = b;
- }
- /////////////////
- public string Name
- {
- get
- {
- return name1;
- }
- set
- {
- name1 = value;
- }
- }
- public string SecondName
- {
- get
- {
- return name2;
- }
- set
- {
- name2 = value;
- }
- }
- ////////////
- public DateTime Birth
- {
- get
- {
- return birth;
- }
- set
- {
- birth = value;
- }
- }
- public int Year
- {
- get
- {
- return birth.Year;
- }
- set
- {
- birth = new DateTime(value, birth.Month, birth.Day);
- }
- }
- /////////////
- public override string ToString()
- {
- return Name + " " + SecondName +" " + Birth.ToString();
- }
- public virtual string ToShortString()
- {
- return Name + " " + SecondName;
- }
- }
- ////////////////////////////
- public enum Education { Specialist, Вachelor, SecondEducation }
- public class Exam
- {
- string subject;
- int rate;
- DateTime examday;
- ///////////////
- public string Subject
- {
- get
- {
- return subject;
- }
- set
- {
- subject = value;
- }
- }
- public int Rate
- {
- get
- {
- return rate;
- }
- set
- {
- rate = value;
- }
- }
- ////////////
- public DateTime Examday
- {
- get
- {
- return examday;
- }
- set
- {
- examday = value;
- }
- }
- public Exam()
- {
- subject = "pract";
- rate = 5;
- examday = new DateTime(2017, 05, 30);
- }
- public Exam(string sub, int r, DateTime ed)
- {
- this.subject = sub;
- this.rate = r;
- this.examday = ed;
- }
- public override string ToString()
- {
- return Subject + " " + Rate.ToString() + " " + Examday.ToString();
- }
- }
- ///////////////
- //////////////
- public class Student
- {
- private Person pers;
- private Education fo;
- private int gruppa;
- private List<Exam> exams=new List<Exam>();
- /////
- public Person Pers
- {
- get
- {
- return pers;
- }
- set
- {
- pers = value;
- }
- }
- public Education Fo
- {
- get
- {
- return fo;
- }
- set
- {
- fo = value;
- }
- }
- List<Exam> Exams
- {
- get
- {
- return exams;
- }
- set
- {
- exams = value;
- }
- }
- ////////
- private double sr = 0;
- public double Exsr()
- {
- int l = Exams.Count;
- for (int i = 1; i < l; i++)
- {
- sr += Exams[i].Rate ;
- }
- sr /= l;
- return sr;
- }
- public double Sr
- {
- get
- {
- return sr;
- }
- }
- ///////////
- public bool this[Education educ]
- {
- get
- {
- return educ == fo;
- }
- }
- public void AddExams(params Exam[] exames)
- {
- this.exams.AddRange(exames);
- }
- public override string ToString()
- {
- string s = pers.ToString() + " " + fo.ToString() + " " + gruppa.ToString() + " ";
- for (int i = 0; i < Exams.Count; i++)
- s += Exams[i].Subject + " "+Exams[i].Rate.ToString()+Exams[i].Examday.ToString()+" ";
- return s;
- }
- public virtual string ToShortString()
- {
- return pers.ToShortString()+" " + fo.ToString() + " " + gruppa.ToString() + " " + Sr.ToString();
- }
- ////////////
- public int Gruppa
- {
- get
- {
- return gruppa;
- }
- set
- {
- gruppa = value;
- }
- }
- public Student()
- {
- pers = new Person("polya", "ivanova", new DateTime(1999, 11, 22));
- fo = Education.Вachelor;
- gruppa = 862;
- }
- public Student(Person per, Education edu, int g)
- {
- this.pers = new Person(per.Name, per.SecondName, per.Birth);
- this.fo = edu;
- this.gruppa = g;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Создать один объект типа Student, преобразовать данные в текстовый вид с помощью метода ToShortString() и вывести данные.");
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine();
- Student stud = new Student();
- Console.WriteLine(stud.ToShortString());
- DateTime d = new DateTime(1999, 11, 22);
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine();
- //List<Exam> ex=new List<Exam>();
- Console.WriteLine("Вывести значения индексатора для значений индекса Education.Specialist, Education.Bachelor и Education.SecondEducation.");
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine(Education.Specialist + " " + stud[Education.Specialist]);
- Console.WriteLine(Education.Вachelor + " " + stud[Education.Вachelor]);
- Console.WriteLine(Education.SecondEducation + " " + stud[Education.SecondEducation]);
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine("Присвоить значения всем определенным в типе Student свойствам, преобразовать данные в текстовый вид с помощью метода ToString() и вывести данные.");
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine();
- //stud.AddExams(new Exam("fdhhd", 5, d));
- stud = new Student(new Person("polya", "ivanova", d), Education.Specialist, 862);
- Console.WriteLine(stud.ToString());
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine("C помощью метода AddExams( params Exam*+ ) добавить элементы в список экзаменов и вывести данные объекта Student, используя метод ToString().");
- stud.AddExams(new Exam( "fjgkkhkh", 5, new DateTime(2017, 05, 30)));
- Console.WriteLine(stud.ToString());
- Console.WriteLine();
- Console.WriteLine();
- Console.WriteLine();
- // Person per = new Person("polya", "ivanova", d);
- //per.Year = 2000;
- //Console.WriteLine(per.Year);
- // Console.WriteLine(per.ToString());
- // Console.WriteLine(per.ToShortString());
- // Education edu = Education.Вachelor;
- //Console.WriteLine(edu);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement