Advertisement
Guest User

Why

a guest
Jun 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _5.Students__LAB
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string students = string.Empty;
  12. List<Student> savedStudentsInfo = new List<Student>();
  13. while ((students = Console.ReadLine()) != "end")
  14. {
  15.  
  16. List<string> studentsInfo = students.Split().ToList();
  17. string firstNameOfStudent = studentsInfo[0];
  18. string secondNameOfStudent = studentsInfo[1];
  19. int ageOfStudent = int.Parse(studentsInfo[2]);
  20. string homeTownOfStudent = studentsInfo[3];
  21.  
  22. Student student = new Student();
  23. student.firstName = firstNameOfStudent;
  24. student.lastName = secondNameOfStudent;
  25. student.age = ageOfStudent;
  26. student.hometown = homeTownOfStudent;
  27.  
  28. if (IsStudentExicist(savedStudentsInfo, student.firstName, student.lastName))
  29. {
  30.  
  31. if (GetStudent(savedStudentsInfo, student.firstName ,student.lastName))
  32. {
  33.  
  34. }
  35. }
  36. else
  37. {
  38. savedStudentsInfo.Add(student);
  39. }
  40.  
  41. }
  42. string inputStudents = Console.ReadLine();
  43.  
  44.  
  45. foreach (var town in savedStudentsInfo)
  46. {
  47. if (inputStudents == town.hometown)
  48. {
  49. Console.WriteLine($"{town.firstName} {town.lastName} is {town.age} years old.");
  50. }
  51. }
  52.  
  53. }
  54.  
  55. static bool IsStudentExicist(List<Student> students, string firstName, string lastName)
  56. {
  57. foreach (Student student in students)
  58. {
  59. if (student.firstName == firstName && student.lastName == lastName)
  60. {
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. static Student GetStudent(List<Student> students, string firstName, string lastName)
  67. {
  68. Student existingStudent = null;
  69. foreach (Student student in students)
  70. {
  71. if (student.firstName == firstName && student.lastName == lastName)
  72. {
  73. existingStudent = student;
  74. }
  75. }
  76. return existingStudent;
  77. }
  78. }
  79. class Student
  80. {
  81. public string firstName { get; set; }
  82. public string lastName { get; set; }
  83. public int age { get; set; }
  84. public string hometown { get; set; }
  85.  
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement