_egorka_

3 номер в лабах

Mar 16th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ConsoleApp14
  4. // номер три(список чего то там)
  5. {
  6.  
  7. class Student_Test
  8. {
  9. public string Name;//имя
  10. public string Surname;//фамилия
  11. public int test_mark;//оценка
  12. public Student_Test(string name, string surname, int Test_Mark)//конструктор
  13. {
  14. Name = name;
  15. Surname = surname;
  16. test_mark = Test_Mark;
  17. }
  18. }
  19. class Program
  20. {
  21. public static void List_Add(List<Student_Test> list)
  22. {
  23. string name, surname;
  24. int mark;
  25. Console.Write("Enter student's name:");
  26. name = Console.ReadLine();
  27. Console.Write("Enter student's surname:");
  28. surname = Console.ReadLine();
  29. Console.Write("Enter student's test mark:");
  30. mark = Convert.ToInt32(Console.Read());
  31. Student_Test student = new Student_Test(name, surname, mark);
  32. list.Add(student);
  33. Console.WriteLine("Student added sucessfuly");
  34. }
  35.  
  36. public static void List_Print(List<Student_Test> list)
  37. {
  38. int counter = 1;
  39. foreach (Student_Test student in list)
  40. {
  41. Console.WriteLine($"{counter}) Name:{student.Name} Surname:{student.Surname} Mark:{student.test_mark} ");
  42. counter++;
  43. }
  44. if (counter == 1)
  45. {
  46. Console.WriteLine("Your list is empty");
  47. }
  48. Console.ReadLine();
  49. }
  50.  
  51.  
  52. static void Main(string[] args)
  53. {
  54. List<Student_Test> myFirstList = new List<Student_Test>();
  55. while (true)
  56. {
  57. Console.WriteLine("Введите 1 если хотите добавить студента в список (введите 2 для вывода списка ): ");
  58. int x = Convert.ToInt32(Console.ReadLine());
  59. switch (x)
  60. {
  61. case 1:
  62. List_Add(myFirstList);
  63. break;
  64. case 2:
  65. List_Print(myFirstList);
  66. break;
  67. default:
  68. {
  69. Console.WriteLine("Некорректный ввод(");
  70. break;
  71. }
  72. }
  73. x = 0;
  74. }
  75. }
  76. }
  77. }
Add Comment
Please, Sign In to add comment