Viết chương trình quản lý sinh viên + delegate & event trong C# - Lập Trình C# - Lập Trình C Sharp
Viết chương trình quản lý thông tin sinh viên.
Thông tin sinh viên gồm các thuộc tính sau : tên, tuổi, mã sinh viên, địa chỉ, email, sđt, mã phụ huynh -> Viết hàm nhập và hàm hiển thị
Thông tin phụ huynh gồm các thuộc tính : tên, địa chỉ, sđt, mã phụ huynh -> Mỗi sinh viên sẽ được liên kết vs một phụ huynh -> Viết hàm nhập và hàm hiển thị
(Chú ý 1 phụ huynh có thể được liên kết vs nhiều sv)
Yêu cầu tạo menu chương trình
1. Nhập thông tin N phụ huynh
2. Nhập thông tin M sinh viên
3. Nhập tên phu huynh -> In ra thông tin các sinh viên được tham chiếu bởi phụ huynh này
4. Nhập thông tinh sv -> In ra thông tin tra cứu phụ huynh
5. Tạo delegate OnAddressPrint và sự kiện EventAddressPrint -> Thực hiện in thông tin sinh viên theo địa chỉ nhập vào.
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Đào Mạnh Dũng [C2010L]](https://www.gravatar.com/avatar/6a111fa53fd75dc87034660a8857df16.jpg?s=80&d=mm&r=g)
Đào Mạnh Dũng
2021-10-09 16:50:03
#Parent.cs
using System;
namespace _1523
{
internal class Parent
{
public string name, address, phone, parentID;
public Parent()
{
}
public Parent(string name, string address, string phone, string parentID)
{
this.name = name;
this.address = address;
this.phone = phone;
this.parentID = parentID;
}
public void input()
{
System.Console.WriteLine("nhap name : ");
this.name = Console.ReadLine();
System.Console.WriteLine("nhap address : ");
this.address = Console.ReadLine();
System.Console.WriteLine("nhap phone : ");
this.phone = Console.ReadLine();
System.Console.WriteLine("nhap parentID : ");
this.parentID = Console.ReadLine();
}
public void display()
{
System.Console.WriteLine(this);
}
public override string ToString()
{
return "Parent{" + "name=" + name + ", address=" + address + ", phone=" + phone + ", parentID=" + parentID + '}';
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace _1523
{
internal class Program
{
private delegate void OnAddressPrint(Dictionary<string, Student> students, string address);
private static event OnAddressPrint EventAddressPrint;
private static void Main(string[] args)
{
Dictionary<string, Parent> parents = new Dictionary<string, Parent>();
Dictionary<string, Student> students = new Dictionary<string, Student>();
Console.WriteLine("Hello World!");
while (true)
{
switch (Menu())
{
case 1:
{
Console.WriteLine("nhap n : ");
int n = ReadInt();
for (int i = 0; i < n; i++)
{
Parent parent = new Parent();
Console.WriteLine("--------------");
parent.input();
parents.Add(parent.parentID, parent);
}
break;
}
case 2:
{
Console.WriteLine("nhap m : ");
int n = ReadInt();
for (int i = 0; i < n; i++)
{
Student student = new Student();
Console.WriteLine("--------------");
student.input();
students.Add(student.rollnum, student);
}
break;
}
case 3:
{
Console.WriteLine("nhap parentID : ");
string parentID = Console.ReadLine();
Console.WriteLine("--------------");
foreach (var student in students)
{
if (student.Value.parentID.Equals(parentID))
{
student.Value.display();
Console.WriteLine("--------------");
}
}
break;
}
case 4:
{
Console.WriteLine("nhap rollnum : ");
string rollnum = Console.ReadLine();
if (students.ContainsKey(rollnum))
{
if (parents.ContainsKey(students[rollnum].parentID))
{
parents[students[rollnum].parentID].display();
}
else
{
Console.WriteLine("parentID is null");
}
}
else
{
Console.WriteLine("rollnum is null");
}
break;
}
case 5:
{
OnAddressPrint address = (students, address) =>
{
Console.WriteLine("--------------");
foreach (var student in students)
{
if (student.Value.address.Equals(address))
{
student.Value.display();
Console.WriteLine("--------------");
}
}
};
EventAddressPrint = address;
Console.WriteLine("nhap address : ");
EventAddressPrint(students, Console.ReadLine());
break;
}
case 6:
{
Environment.Exit(0);
break;
}
default:
{
break;
}
}
}
}
private static int Menu()
{
Console.WriteLine("1. Nhập thông tin N phụ huynh\n" +
"2.Nhập thông tin M sinh viên\n" +
"3.Nhập ID phu huynh\n" +
"4.Nhập rollnum sv\n" +
"5.Tạo delegate OnAddressPrint và sự kiện EventAddressPrint\n" +
"6.Exit : \n" +
"chon : ");
return ReadInt();
}
public static int ReadInt()
{
int integer = 0;
while (true)
{
try
{
integer = int.Parse(Console.ReadLine());
break;
}
catch (Exception)
{
Console.WriteLine("du lieu dau vao khong hop le, nhap lai ");
}
}
return integer;
}
}
}
#Student.cs
using System;
namespace _1523
{
internal class Student
{
public string name, rollnum, email, address, phone, parentID;
public int age;
public Student()
{
}
public Student(string name, int age, string rollnum, string email, string address, string phone, string parentID)
{
this.name = name;
this.age = age;
this.rollnum = rollnum;
this.email = email;
this.address = address;
this.phone = phone;
this.parentID = parentID;
}
public void input()
{
System.Console.WriteLine("nhap name : ");
this.name = Console.ReadLine();
System.Console.WriteLine("nhap age : ");
this.age = Program.ReadInt();
System.Console.WriteLine("nhap rollnum : ");
this.rollnum = Console.ReadLine();
System.Console.WriteLine("nhap email : ");
this.email = Console.ReadLine();
System.Console.WriteLine("nhap address : ");
this.address = Console.ReadLine();
System.Console.WriteLine("nhap phone : ");
this.phone = Console.ReadLine();
System.Console.WriteLine("nhap parentID : ");
this.parentID = Console.ReadLine();
}
public void display()
{
System.Console.WriteLine(this);
}
public override string ToString()
{
return "Student{" + "name=" + name + ", age=" + age + ", rollnum=" + rollnum + ", email=" + email + ", address=" + address + ", phone=" + phone + ", parentID=" + parentID + '}';
}
}
}
![Hoàng Thiện Thanh [community,AAHN-C2009G]](https://www.gravatar.com/avatar/58e377dde293f6da38c0b5168578557a.jpg?s=80&d=mm&r=g)
Hoàng Thiện Thanh
2021-10-05 09:21:01
#Parent.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelegeatStudentManager
{
class Parent
{
private string parentNo;
public string ParentNo { get { return parentNo; } set {
/*
foreach(Parent p in Program.PList)
{
while (value.Equals(p.ParentNo))
{
Console.WriteLine("The same parent code already exists.");
value = Utility.ReadNum();
}
}*/
this.parentNo = value; } }
public string Name { get; set; }
public string Address { get; set; }
public string PhoneNumber { get; set; }
public int Age { get; set; }
public List<Student> students;
public Parent()
{
this.students = new List<Student>();
}
public Parent(List<Student> students)
{
this.students = students;
}
public Parent(string ParentNo, string Name, string Address, string PhoneNumber, int Age) {
this.ParentNo = ParentNo;
this.Name = Name;
this.Address = Address;
this.PhoneNumber = PhoneNumber;
this.Age = Age;
if(this.students == null)
{
this.students = new List<Student>();
}
}
public Parent(string ParentNo, string Name, string Address, string PhoneNumber, int Age, List<Student> students)
{
this.ParentNo = ParentNo;
this.Name = Name;
this.Address = Address;
this.PhoneNumber = PhoneNumber;
this.Age = Age;
this.students = students;
}
public void input()
{
Console.WriteLine("Enter Parent Code:");
ParentNo = Utility.ReadNum();
Console.WriteLine("Enter Name:");
Name = Utility.ReadAlp();
Console.WriteLine("Enter Address:");
Address = Console.ReadLine();
Console.WriteLine("Enter Phone:");
PhoneNumber = Utility.ReadNum();
Console.WriteLine("Enter Age:");
Age = Utility.ReadInt();
if (Program.SList.Count != 0)
{
Console.WriteLine("Enter the amounts of students to associate with the parent:");
int N = Utility.ReadInt();
for (int i = 0; i < N; i++)
{
Console.WriteLine("[" + (i + 1) + "] Enter Student Code:");
string StudentNo = Utility.ReadNum();
foreach (Student s in Program.SList)
{
while (!StudentNo.Equals(s.StudentNo) && !students.Contains(s))
{
Console.WriteLine("No matching Student Code");
StudentNo = Utility.ReadNum();
if (s.StudentNo.Equals(StudentNo) && s.ParentNo.Equals(ParentNo))
{
students.Add(s);
if (s.ParentNo == null || s.ParentNo == "")
{
s.ParentNo = ParentNo;
}
if (!s.parent.Contains(this))
{
s.parent.Add(this);
Console.WriteLine("Add Success");
break;
}
else
{
Console.WriteLine("Parent already exists");
break;
}
}
}
}
}
}
}
public void display()
{
Console.WriteLine("Name :{0}, Address :{1}, Parent No :{2}, Phone :{3}", Name, Address, ParentNo, PhoneNumber);
if (students.Count != 0)
{
Console.Write("Parent No's :\n");
foreach (Student s in students)
{
Console.Write(s.StudentNo + "\n");
}
}
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace DelegeatStudentManager
{
public delegate void OnAddressPrint(string address);
class Program
{
public static List<Student> SList = new List<Student>();
public static List<Parent> PList = new List<Parent>();
static void ShowMenu()
{
Console.WriteLine("1.Add Parents" +
"\n2.Add Students" +
"\n3.Find Students by Parent" +
"\n4.Find Parent by Student Name" +
"\n5.Print EventAddressPrint");
}
static void InputParents()
{
Console.WriteLine("Enter the number of parents to add:");
int N = Utility.ReadInt();
for (int i = 0; i < N; i++)
{
Console.WriteLine("Parent[" + (i + 1) + "]");
Parent p = new Parent();
p.input();
PList.Add(p);
}
}
static void InputStudents()
{
Console.WriteLine("Enter the number of students to add:");
int N = Utility.ReadInt();
for (int i = 0; i < N; i++)
{
Console.WriteLine("Student[" + (i + 1) + "]");
Student s = new Student();
s.input();
SList.Add(s);
}
}
static void FindStudentOfParent()
{
Console.WriteLine("Enter the name of the parent:");
string str = Utility.ReadAlp();
foreach(Parent p in PList)
{
if (p.Name.Equals(str))
{
foreach(Student s in SList)
{
if (s.ParentNo.Equals(p.ParentNo))
{
s.display();
}
}
}
}
}
static void FindParentOfStudent()
{
Console.WriteLine("Enter the name of the parent:");
string StudentNo = Utility.ReadNum();
foreach (Student s in SList)
{
if (s.StudentNo.Equals(StudentNo))
{
foreach (Parent p in s.parent)
{
p.display();
}
} else
{
Console.WriteLine("No parent found for student");
}
}
}
static void PrintEventAddress()
{
Console.WriteLine("Enter address of Student :");
string address = Console.ReadLine();
OnAddressPrint EventAddressPrint = delegate (string addr)
{
foreach (Student s in SList)
{
if (s.Address.Equals(address))
{
s.display();
}
else
{
Console.WriteLine("Address of the student is not found");
}
}
};
EventAddressPrint(address);
}
static void Main(string[] args)
{
int choice;
do
{
ShowMenu();
Console.WriteLine("Enter choice number :");
choice = Utility.ReadInt();
switch (choice)
{
case 1:
InputParents();
break;
case 2:
InputStudents();
break;
case 3:
FindStudentOfParent();
break;
case 4:
FindParentOfStudent();
break;
case 5:
PrintEventAddress();
break;
default:
Console.WriteLine("Must be value 1 -> 5");
break;
}
} while (choice >= 0);
}
}
}
#Student.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace DelegeatStudentManager
{
class Student
{
public string Name { get; set; }
public int Age { get; set; }
private string studentNo;
public string StudentNo
{
get { return studentNo; }
set
{
foreach (Student s in Program.SList)
{
while (value.Equals(s.StudentNo))
{
Console.WriteLine("The same student code already exists.");
value = Utility.ReadNum();
}
}
this.studentNo = value;
}
}
public string Address { get; set; }
public string Email { get; set; }
public string ParentNo { get; set; }
public string PhoneNumber { get; set; }
public List<Parent> parent;
public Student()
{
this.parent = new List<Parent>();
}
public Student(string Name, int Age, string StudentNo, string Address, string Email, string ParentNo, string PhoneNumber, List<Parent> parent)
{
this.Name = Name;
this.Age = Age;
this.StudentNo = StudentNo;
this.Address = Address;
this.Email = Email;
this.ParentNo = ParentNo;
this.PhoneNumber = PhoneNumber;
this.parent = parent;
}
public void input()
{
Console.WriteLine("Input Name: ");
Name = Utility.ReadAlp();
Console.WriteLine("Input Age: ");
Age = Utility.ReadInt();
Console.WriteLine("Input Student No:");
StudentNo = Utility.ReadNum();
Console.WriteLine("Input Address:");
Address = Console.ReadLine();
Console.WriteLine("Input Email:");
Email = Console.ReadLine();
Console.WriteLine("Input Phone Number:");
PhoneNumber = Utility.ReadNum();
if (Program.PList.Count != 0)
{
Console.WriteLine("Enter the amount of parents to associate with students:");
int N = Utility.ReadInt();
while (N < 0 || N > 2)
{
Console.WriteLine("Must be between 0 or 2 parents");
N = Utility.ReadInt();
}
for (int i = 0; i < N; i++)
{
//Console.WriteLine("[" + (i + 1) + "]Input Parent No:");
string ParentNo = Utility.ReadNum();
foreach (Parent p in Program.PList)
{
while (!p.ParentNo.Equals(ParentNo))
{
Console.WriteLine("No matching Parent No, enter again:");
ParentNo = Utility.ReadNum();
}
if (p.ParentNo.Equals(ParentNo))
{
this.ParentNo = ParentNo;
if (!parent.Contains(p))
{
parent.Add(p);
p.students.Add(this);
Console.WriteLine("Add Success");
}
}
}
}
}
}
public void display()
{
Console.Write("\nStudent Name :{0}, Student Age :{1}, Student No :{2}, Address Student :{3}, Email Student :{4}, Phone Student :{5}\n"
, Name, Age, StudentNo, Address, Email, PhoneNumber + ", ");
if (parent.Count != 0)
{
Console.Write("Parent No's :\n");
foreach (Parent p in parent)
{
Console.Write(p.ParentNo + "\n");
}
}
}
}
}
#Utility.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace DelegeatStudentManager
{
public class Utility
{
public static int ReadInt()
{
string str = Console.ReadLine();
bool check()
{
try { int.Parse(str); } catch (Exception e) { return false; }
return true;
}
while (!check())
{
Console.WriteLine("Enter a valid numeric input");
str = Console.ReadLine();
}
return int.Parse(str);
}
public static float ReadFloat()
{
string str = Console.ReadLine();
bool check()
{
try { float.Parse(str); } catch (Exception e) { return false; }
return true;
}
while (!check())
{
Console.WriteLine("Enter a valid float numeric input");
str = Console.ReadLine();
}
return float.Parse(str);
}
public static string ReadNum()
{
string str = Console.ReadLine();
while(!Regex.Match(str, "^[0-9]*$").Success)
{
Console.WriteLine("Enter the correct numbers string");
str = Console.ReadLine();
}
return str;
}
public static string ReadAlp()
{
string str = Console.ReadLine();
while (!Regex.Match(str, "^([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)*$").Success)
{
Console.WriteLine("No number or special characters is allowed");
str = Console.ReadLine();
}
return str;
}
}
}
![Nguyễn Việt Hoàng [community,AAHN-C2009G]](https://www.gravatar.com/avatar/bdbde8074d82148dcda6927ccb016466.jpg?s=80&d=mm&r=g)
Nguyễn Việt Hoàng
2021-10-02 17:44:39
#Parents.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ss6
{
class Parents
{
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string RollNoPar { get; set; }
public List<Student> StudentsList { get; set; }
public Parents()
{
StudentsList = new List<Student>();
}
public Parents(string name, string address, string phone, string rollNoPar, List<Student> studentlist)
{
this.Name = name;
this.Address = address;
this.Phone = phone;
this.RollNoPar = rollNoPar;
this.StudentsList = studentlist;
}
public void input()
{
Console.WriteLine("Enter Parents Name :");
Name = Console.ReadLine();
Console.WriteLine("Enter Address Parents :");
Address = Console.ReadLine();
Console.WriteLine("Enter Phone Parents :");
Phone = Console.ReadLine();
Console.WriteLine("Enter RollNo Parents :");
RollNoPar = Console.ReadLine();
}
public void display()
{
Console.WriteLine("Name Parents :{0}, Address Parents :{1}, RollNo Parents :{2}, Phone :{3}"
, Name, Address, RollNoPar,Phone);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace Ss6
{
public delegate string OnAddressPrint(string addr);
class Program
{
static event OnAddressPrint EventAddressPrint = null;
public static List<Parents> ParentsList = new List<Parents>();
public static List<Student> StudentList = new List<Student>();
static void showMenu()
{
Console.WriteLine("1.Enter information N parents ");
Console.WriteLine("2.Enter information M students ");
Console.WriteLine("3.Enter Name Parent . Print all student for parents name ");
Console.WriteLine("4.Enter information students . Print all parents for students");
Console.WriteLine("5.Print all information student to Address input");
}
static void Input_Par()
{
int sum;
Console.WriteLine("Enter Sum of Parents :");
sum = int.Parse(Console.ReadLine());
for (int i = 0; i < sum; i++)
{
Console.WriteLine("Parents[" + (i + 1) + "]");
Parents p = new Parents();
p.input();
ParentsList.Add(p);
}
}
static void Input_Std()
{
Console.WriteLine("Enter Sum of Students :");
int sum = int.Parse(Console.ReadLine());
for (int i = 0; i < sum; i++)
{
Console.WriteLine("Students[" + (i + 1) + "]");
Student s = new Student();
s.input();
Console.WriteLine("Enter RollNo Parents :");
string roll = Console.ReadLine();
if(ParentsList.Count == 0)
{
Console.WriteLine("RollNo Parents not exists ");
}
foreach (Parents p in ParentsList)
{
while (p.RollNoPar.Equals(roll) || !p.RollNoPar.Equals(roll))
{
if (p.RollNoPar.Equals(roll))
{
p.StudentsList.Add(s);
s.ParentList.Add(p);
break;
}
else if (!p.RollNoPar.Equals(roll))
{
Console.WriteLine("Error");
Console.WriteLine("Enter again :");
roll = Console.ReadLine();
}
}
}
StudentList.Add(s);
}
}
static void Inf_Std_By_Par()
{
if (ParentsList.Count == 0)
{
Console.WriteLine("Parents not exists ");
return;
}
Console.WriteLine("Enter Name Parents :");
string namePr = Console.ReadLine();
foreach (Parents p in ParentsList)
{
if(p.Name == namePr)
{
foreach(Student s in p.StudentsList)
{
s.display();
}
}else
{
Console.WriteLine("No parents with matching name");
}
}
}
static void Inf_Par_By_Std()
{
if (StudentList.Count == 0)
{
Console.WriteLine("Students not exists ");
return;
}
Console.WriteLine("Enter RollNo Student :");
string roll = Console.ReadLine();
foreach(Student st in StudentList)
{
if(st.RollNoStd.Equals(roll))
{
foreach(Parents p in st.ParentList)
{
p.display();
}
}else
{
Console.WriteLine("RollNo Student not exists");
}
}
}
static void Print_Inf_By_Addr()
{
Console.WriteLine("Enter Address Student :");
string address = Console.ReadLine();
OnAddressPrint EventAddressPrint = delegate (string addr)
{
foreach (Student s in StudentList)
{
if (s.Address.Equals(address))
{
s.display();
}
else
{
Console.WriteLine("Address Students not exists");
}
}
return addr;
};
EventAddressPrint(address);
}
static void listMenu()
{
int choose;
do
{
showMenu();
Console.WriteLine("Enter choose value to Memu :");
choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Input_Par();
break;
case 2:
Input_Std();
break;
case 3:
Inf_Std_By_Par();
break;
case 4:
Inf_Par_By_Std();
break;
case 5:
Print_Inf_By_Addr();
break;
default:
Console.WriteLine("Must be value 1 -> 5");
break;
}
} while (choose >= 0);
}
static void Main(string[] args)
{
listMenu();
}
}
}
#Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ss6
{
class Student
{
public string Name { get; set; }
public int Age { get; set; }
public string RollNoStd { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public List<Parents> ParentList { get; set; }
public Student()
{
ParentList = new List<Parents>();
}
public Student(string name, int age, string rollnostd, string address, string email, string phone, List<Parents> rollnopar)
{
this.Name = name;
this.Age = age;
this.RollNoStd = rollnostd;
this.Address = address;
this.Email = email;
this.Phone = phone;
this.ParentList = rollnopar;
}
public void input()
{
Console.WriteLine("Enter Student Name :");
Name = Console.ReadLine();
Console.WriteLine("Enter Student Age :");
Age = int.Parse(Console.ReadLine());
Console.WriteLine("Enter RollNo Student :");
RollNoStd = Console.ReadLine();
Console.WriteLine("Enter Address Student :");
Address = Console.ReadLine();
Console.WriteLine("Enter Email Student :");
Email = Console.ReadLine();
Console.WriteLine("Enter Phone Student :");
Phone = Console.ReadLine();
}
public void display()
{
Console.Write("Student Name :{0}, Student Age :{1}, RollNoStudent :{2}, Address Student :{3}, Email Student :{4}, Phone Student :{5}"
, Name, Age, RollNoStd, Address, Email, Phone + ", ");
foreach (Parents p in ParentList)
{
Console.Write("RollNo Parents :{0}",p.RollNoPar + "\n");
}
}
}
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2021-05-28 09:01:05
#Program.cs
using System;
using System.Collections.Generic;
using StudentDelegate.Modals;
namespace StudentDelegate
{
public delegate void OnAddressPrint(string address);
class Program
{
static event OnAddressPrint EventAddressPrint = null;
static List<Parent> parentList = new List<Parent>();
static List<Student> studentList = new List<Student>();
static void Main(string[] args)
{
int choose = 0;
do
{
showMenu();
choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Nhap so luong phu huynh muon them:");
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++)
{
Console.WriteLine("Nhap thong tin phu huynh thu: ", parentList.Count + i + 1);
Parent parent = new Parent();
parent.input();
parentList.Add(parent);
}
break;
case 2:
Console.WriteLine("Nhap so luong sinh vien muon them:");
int M = int.Parse(Console.ReadLine());
for (int i = 0; i < M; i++)
{
Console.WriteLine("Nhap thong tin sinh vien thu: ", studentList.Count + i + 1);
Student student = new Student();
Console.WriteLine("Nhap ma phu huynh:");
while (true)
{
student.parentKey = Console.ReadLine();
int check = 0;
foreach (Parent parent in parentList)
{
if(parent.parentKey == student.parentKey)
{
check++;
break;
}
}
if (check == 0) Console.WriteLine("Khong co phu huynh hop le, yeu cau nhap lai!!");
else break;
}
student.input();
studentList.Add(student);
}
break;
case 3:
Console.WriteLine("Nhap ten phu huynh:");
string name = Console.ReadLine();
foreach (Parent parent in parentList)
{
if(parent.name == name)
{
Console.WriteLine("Phu huynh co ten {0} va ma PH la {1}, co cac sinh vien la:", parent.name, parent.parentKey);
int check = 0;
foreach (Student student in studentList)
{
if(student.parentKey == parent.parentKey)
{
student.display();
check++;
}
}
if (check == 0) Console.WriteLine("Khong co sinh vien nao");
}
}
break;
case 4:
Console.WriteLine("Nhap ma sinh vien:");
string rollno = Console.ReadLine();
foreach (Student std in studentList)
{
if (std.rollno == rollno)
{
Console.WriteLine("Sinh vien co ten {0} va ma sinh vien la {1}, co phu huynh la:", std.name, std.rollno);
int check = 0;
foreach (Parent p in parentList)
{
if (std.parentKey == p.parentKey)
{
p.display();
check++;
break;
}
}
if (check == 0) Console.WriteLine("Khong co phu huynh nao");
}
}
break;
case 5:
Console.WriteLine("Dia chi sinh vien can tim kiem:");
string address = Console.ReadLine();
EventAddressPrint = showInfo;
EventAddressPrint(address);
break;
case 6:
Console.WriteLine("Tam biet!!");
break;
default:
Console.WriteLine("Nhap sai!!");
break;
}
} while (choose != 6);
}
private static void showMenu()
{
Console.WriteLine("Lua chon chuong trinh:");
Console.WriteLine("1.Nhap thong tin N phu huynh");
Console.WriteLine("2.Nhap thong tin M sinh vien");
Console.WriteLine("3.Nhap ten PH -> tim sinh vien");
Console.WriteLine("4.Nhap ma sinh vien -> tim PH");
Console.WriteLine("5.In thong tin sinh vien tim kiem theo delegate");
Console.WriteLine("6.Thoat");
}
private static void showInfo(string address)
{
int check = 0;
foreach (Student student in studentList)
{
if(student.address == address)
{
check++;
student.display();
}
}
if (check == 0) Console.WriteLine("Khong co sinh vien nao hop le!!");
}
}
}
#Parent.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace StudentDelegate.Modals
{
class Parent
{
public string name { get; set; }
public string address { get; set; }
public string phoneNum { get; set; }
public string parentKey { get; set; }
public Parent()
{
}
public virtual void input()
{
Console.WriteLine("Nhap ten phu huynh:");
name = Console.ReadLine();
Console.WriteLine("Nhap dia chi phu huynh:");
address = Console.ReadLine();
Console.WriteLine("Nhap so dien thoai:");
phoneNum = Console.ReadLine();
Console.WriteLine("Nhap ma phu huynh:");
parentKey = Console.ReadLine();
}
public virtual void display()
{
Console.WriteLine("Ten PH: {0}, Dia chi: {1}, SDT: {2}, Ma PH: {3}", name, address, phoneNum, parentKey);
}
}
}
#Student.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace StudentDelegate.Modals
{
class Student : Parent
{
public int age { get; set; }
public string rollno { get; set; }
public string email { get; set; }
public Student()
{
}
public override void input()
{
Console.WriteLine("Nhap ten sinh vien:");
name = Console.ReadLine();
Console.WriteLine("Tuoi:");
age = int.Parse(Console.ReadLine());
Console.WriteLine("Ma sinh vien:");
rollno = Console.ReadLine();
Console.WriteLine("Nhap dia chi sinh vien:");
address = Console.ReadLine();
Console.WriteLine("Nhap email sinh vien:");
email = Console.ReadLine();
Console.WriteLine("Nhap so dien thoai:");
phoneNum = Console.ReadLine();
}
public override void display()
{
Console.WriteLine("Ten sinh vien: {0}, Tuoi: {1}, MSV: {2}, Dia chi: {3}, Email: {4}, SDT: {5}, Ma PH: {6}", name, age, rollno, address, email, phoneNum, parentKey);
}
}
}
![nguyễn Sử [T2008A]](https://www.gravatar.com/avatar/47487be2776ac2ec915b0936ef7ab5ae.jpg?s=80&d=mm&r=g)
nguyễn Sử
2021-05-27 00:46:49
using System;
using System.Collections.Generic;
namespace qlsv
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
List<sinhvien> svList = new List<sinhvien>();
List<phuhuynh> phList = new List<phuhuynh>();
int chon;
do
{
Menu();
Console.WriteLine("moi nhap lua chon");
chon = Int32.Parse(Console.ReadLine());
switch (chon)
{
case 1:
Console.WriteLine("nhap thong tin phu huynh: ");
int n;
n = Int32.Parse(Console.ReadLine());
for(int i = 0; i < n; i++)
{
phuhuynh phuhuynh = new phuhuynh();
phuhuynh.Input();
phList.Add(phuhuynh);
}
break;
case 2:
Console.WriteLine("nhap thong tin sinh vien: ");
int m;
m = Int32.Parse(Console.ReadLine());
for(int i = 0; i < m; i++)
{
sinhvien sinhvien = new sinhvien();
sinhvien.Input();
svList.Add(sinhvien);
}
break;
case 3:
Console.WriteLine("Nhap ten phu huynh");
string ten = Console.ReadLine();
string t = ten(ten);
foreach (sinhvien sv in svList)
{
if (sv.ma_phuhuynh == t)
{
sv.Input();
}
}
break;
case 4:
Console.WriteLine("Nhap ma sinh vien: ");
string masv = Console.ReadLine();
string maph = Timphuhuynh(masv);
foreach (phuhuynh ph in phList)
{
if (ph.ten == maph)
{
ph.Input();
}
}
break;
case 5:
break;
case 6:
Console.WriteLine("thoat chuong trinh: ........");
break;
default:
Console.WriteLine("nhap sai !!!!!!");
break;
}
} while (chon > 0);
}
public static void Menu()
{
Console.WriteLine("----------------Menu----------------");
Console.WriteLine("1: nhap thong tin phu huynh: ");
Console.WriteLine("2: nhap thong tin sinh vien: ");
Console.WriteLine("3: tim phu huynh theo ma sinh vien: ");
Console.WriteLine("4: tim sinh vien theo ma phu huynh: ");
Console.WriteLine("5: thong tin sinh vien theo dia chi: ");
Console.WriteLine("chon: ");
}
}
}
![nguyễn Sử [T2008A]](https://www.gravatar.com/avatar/47487be2776ac2ec915b0936ef7ab5ae.jpg?s=80&d=mm&r=g)
nguyễn Sử
2021-05-27 00:45:16
#phuhuynh
using System;
using System.Collections.Generic;
using System.Text;
namespace qlsv
{
class phuhuynh
{
public string ten { get; set; }
public string diachi { get; set; }
public string sđt { get; set; }
public string ma_phuhuynh { get; set; }
public phuhuynh()
{
}
public phuhuynh( string ten, string diachi, string sdt, string ma_phuhuynh)
{
this.ten = ten;
this.diachi = diachi;
this.sđt = sdt;
this.ma_phuhuynh = ma_phuhuynh;
}
public void Input()
{
Console.WriteLine("nhap ten phu huynh: ");
string ten = Console.ReadLine();
Console.WriteLine("nhap dia chi phu huynh: ");
string diachi = Console.ReadLine();
Console.WriteLine("nhap sđt phu huynh: ");
string sđt = Console.ReadLine();
Console.WriteLine("nhap ma so phu huynh: ");
string ma_phuhuynh = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("ten: {0}, diachi: {1}, sdt: {2}, ma_phuhuynh: {3}", ten, diachi, sđt, ma_phuhuynh);
}
}
}
![nguyễn Sử [T2008A]](https://www.gravatar.com/avatar/47487be2776ac2ec915b0936ef7ab5ae.jpg?s=80&d=mm&r=g)
nguyễn Sử
2021-05-27 00:44:56
#sinhvien
using System;
using System.Collections.Generic;
using System.Text;
namespace qlsv
{
class sinhvien
{
public string ten { get; set; }
public string tuoi { get; set; }
public string ma_sv { get; set; }
public string diachi { get; set; }
public string email { get; set; }
public string sdt { get; set; }
public string ma_phuhuynh { get; set; }
public sinhvien()
{
}
public sinhvien( string ten, string tuoi, string ma_sv, string diachi, string email, string sdt, string ma_phuhuynh)
{
this.ten = ten;
this.tuoi = tuoi;
this.ma_sv = ma_sv;
this.diachi = diachi;
this.email = email;
this.sdt = sdt;
this.ma_phuhuynh = ma_phuhuynh;
}
public void Input()
{
Console.WriteLine(" nhap ten: ");
string ten = Console.ReadLine();
Console.WriteLine(" nhap tuoi: ");
string tuoi = Console.ReadLine();
Console.WriteLine(" nhap ma sinh vien: ");
string ma_sv = Console.ReadLine();
Console.WriteLine(" nhap diachi: ");
string diachi = Console.ReadLine();
Console.WriteLine(" nhap email: ");
string email = Console.ReadLine();
Console.WriteLine(" nhap sdt: ");
string sdt = Console.ReadLine();
Console.WriteLine(" nhap ma phu huynh: ");
string ma_phuhuynh = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("ten: {0}, tuoi: {1}, ma_sv: {2}, diachi: {3}, email: {4}, sdt: {5}, ma_phuhuynh: {6} ", ten, tuoi, ma_sv, diachi, email, sdt, ma_phuhuynh);
}
}
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2021-05-26 10:35:33
#PhuHuynh.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace BT1523
{
class PhuHuynh
{
public string Ten { get; set; }
public string DiaChi { get; set; }
public string Sdt { get; set; }
public string MaPH { get; set; }
public PhuHuynh() { }
public PhuHuynh(string ten, string diachi, string sdt, string maPH)
{
this.Ten = ten;
this.DiaChi = diachi;
this.Sdt = sdt;
this.MaPH = maPH;
}
public void Input()
{
Console.WriteLine("Nhap Ten: ");
Ten = Console.ReadLine();
Console.WriteLine("Nhap DiaChi: ");
DiaChi = Console.ReadLine();
Console.WriteLine("Nhap Sdt: ");
Sdt = Console.ReadLine();
Console.WriteLine("Nhap MaPH: ");
MaPH = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Ten: = {0}", Ten);
Console.WriteLine("DiaChi: = {0}", DiaChi);
Console.WriteLine("Sdt: = {0}", Sdt);
Console.WriteLine("MaPH: = {0}", MaPH);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace BT1523
{
public delegate void OnAddressPrint();
class Program
{
static event OnAddressPrint EventAddressPrint = null;
static void Main(string[] args)
{
List<PhuHuynh> listPH = new List<PhuHuynh>();
List<Student> listSd = new List<Student>();
int choose;
do
{
showMenu();
choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Nhap N PH: ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
PhuHuynh ph = new PhuHuynh();
ph.Input();
listPH.Add(ph);
}
break;
case 2:
Console.WriteLine("NHap M Sv: ");
int m = int.Parse(Console.ReadLine());
int num;
for (int i = 0; i < m; i++)
{
num = 0;
Student sd = new Student();
sd.Input();
do
{
Console.WriteLine("Nhap MaPH: ");
sd.MaPH = Console.ReadLine();
foreach(PhuHuynh ph in listPH)
{
if (sd.MaPH.Equals(ph.MaPH))
{
listSd.Add(sd);
num = 1;
}
}
if(num == 0)
{
Console.WriteLine("Khong tim thay ket qua phu hop !");
}
} while (num == 0);
}
break;
case 3:
Console.WriteLine("Nhap ten Ph can tim: ");
string namePH = Console.ReadLine();
string codePh = "";
foreach(PhuHuynh ph in listPH)
{
if (ph.Ten.Equals(namePH))
{
codePh = ph.MaPH;
}
}
foreach(Student sd in listSd)
{
if (codePh.Equals(sd.MaSV))
{
sd.Display();
}
}
break;
case 4:
Console.WriteLine("Nhap MaSv can tim: ");
string masv = Console.ReadLine();
foreach(Student sd in listSd)
{
if (masv.Equals(sd.MaSV))
{
foreach(PhuHuynh ph in listPH)
{
if (sd.MaPH.Equals(ph.MaPH))
{
ph.Display();
}
}
}
}
break;
case 5:
EventAddressPrint = new OnAddressPrint(OnAddressEvent);
EventAddressPrint();
break;
case 6:
Environment.Exit(0);
break;
default:
Console.WriteLine("Fail!");
break;
}
} while (choose != 6);
}
static void showMenu()
{
Console.WriteLine("1. Nhap thong tin N phu huynh");
Console.WriteLine("2. Nhap thjong tin M SV");
Console.WriteLine("3. Nhập tên phu huynh -> In ra thông tin các sinh viên được tham chiếu bởi phụ huynh này");
Console.WriteLine("4. Nhập thông tinh sv -> In ra thông tin tra cứu phụ huynh");
Console.WriteLine("5. Tạo delegate OnAddressPrint và sự kiện EventAddressPrint -> Thực hiện in thông tin sinh viên theo địa chỉ nhập vào.");
Console.WriteLine("Chon: ");
}
public static void OnAddressEvent()
{
Console.WriteLine("Nhập địa chỉ cần tìm kiếm");
string address = Console.ReadLine();
foreach (Student sd in listSd)
{
if (address.Equals(sd.DiaChi))
{
sd.Display();
}
}
}
}
}
#Student.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace BT1523
{
class Student
{
public string Ten { get; set; }
public int Tuoi { get; set; }
public string MaSV { get; set; }
public string DiaChi { get; set; }
public string Email { get; set; }
public string Sdt { get; set; }
public string MaPH { get; set; }
public Student() { }
public Student(string ten, int tuoi, string maSV, string diachi, string email, string sdt, string maPH)
{
this.Ten = ten;
this.Tuoi = tuoi;
this.MaSV = maSV;
this.DiaChi = diachi;
this.Email = email;
this.Sdt = sdt;
this.MaPH = maPH;
}
public void Input()
{
Console.WriteLine("Nhap Ten: ");
Ten = Console.ReadLine();
Console.WriteLine("Nhap Tuoi: ");
Tuoi = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap MaSV: ");
MaSV = Console.ReadLine();
Console.WriteLine("Nhap DiaChi: ");
DiaChi = Console.ReadLine();
Console.WriteLine("Nhap Email: ");
Email = Console.ReadLine();
Console.WriteLine("Nhap Sdt: ");
Sdt = Console.ReadLine();
Console.WriteLine("Nhap MaPH: ");
MaPH = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Ten: = {0}", Ten);
Console.WriteLine("Tuoi: = {0}", Tuoi);
Console.WriteLine("MaSV: = {0}", MaSV);
Console.WriteLine("DiaChi: = {0}", DiaChi);
Console.WriteLine("Email: = {0}", Email);
Console.WriteLine("Sdt: = {0}", Sdt);
Console.WriteLine("MaPH: = {0}", MaPH);
}
}
}
![Nguyễn Anh Vũ [T2008A]](https://www.gravatar.com/avatar/8863d24ed74b396082becbc4db8331fd.jpg?s=80&d=mm&r=g)
Nguyễn Anh Vũ
2021-05-26 10:23:08
using System;
using System.Collections.Generic;
namespace QuảnLySinhVien1532
{
public delegate void OnAddressPrint();
class Program
{
static event OnAddressPrint EventAddressPrint;
static List<PhuHuynh> phuhuynhList = new List<PhuHuynh>();
static List<SinhVien> sinhvientList = new List<SinhVien>();
static void Main(string[] args)
{
while (true)
{
Menu();
int choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
InsertPhuHuynh();
break;
case 2:
InsertSinhVien();
break;
case 3:
FindSinhVien();
break;
case 4:
FindPhuHuynh();
break;
case 5:
DisplayStdAddress();
break;
default:
break;
}
}
}
static void Menu()
{
Console.WriteLine("1. Nhap n phu huynh");
Console.WriteLine("2. Nhap m sinh vien");
Console.WriteLine("3. In ra sinh vien theo Phu huynh");
Console.WriteLine("4. In ra phu huynh theo Sinh vien");
Console.WriteLine("5. In ra sinh vien theo dia chi");
Console.Write("Choose: ");
}
static void InsertPhuHuynh()
{
Console.Write("N = ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
PhuHuynh p = new PhuHuynh();
p.input();
phuhuynhList.Add(p);
}
}
static void InsertSinhVien()
{
Console.Write("M = ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
SinhVien p = new SinhVien();
p.input();
int flag;
do
{
Console.WriteLine("Insert Code PhuHuynh: ");
p.CodePrt = Console.ReadLine();
flag = 0;
foreach (PhuHuynh prt in phuhuynhList)
{
if (prt.Code.Equals(p.CodePrt))
{
flag = 1;
}
}
if (flag == 0)
{
Console.WriteLine("Không phu huynh nao có ma này");
}
} while (flag == 0);
sinhvientList.Add(p);
}
}
static void FindSinhVien()
{
Console.Write("PhuHuynh Name: ");
string search = Console.ReadLine();
foreach (PhuHuynh p in phuhuynhList)
{
if (p.Name.Equals(search))
{
Console.WriteLine("\tPHuHuynh: ");
p.display();
Console.WriteLine("\tSinhVien: ");
foreach (SinhVien s in sinhvienList)
{
if (s.CodePrt.Equals(p.Code))
{
s.display();
}
}
return;
}
}
}
static void FindPhuHuynh()
{
Console.Write("SinhVien Code: ");
string search = Console.ReadLine();
foreach (SinhVien s in sinhvienList)
{
if (s.CodeStd.Equals(search))
{
Console.WriteLine("\tSinhVien: ");
s.display();
Console.WriteLine("\tPhuHuynh: ");
foreach (PhuHuynh p in phuhuynhList)
{
if (p.Code.Equals(s.CodePrt))
{
p.display();
}
}
}
}
}
static void DisplayStdAddress()
{
EventAddressPrint = new OnAddressPrint(AddressPrint);
EventAddressPrint();
}
static void AddressPrint()
{
Console.Write("Dia chi: ");
string addr = Console.ReadLine();
foreach (SinhVien s in sinhvientList)
{
if (s.Address.Equals(addr))
{
s.display();
}
}
}
}
}
#PhuHuynh
using System;
using System.Collections.Generic;
using System.Text;
namespace QuảnLySinhVien1523
{
class PhuHuynh
{
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Code { get; set; }
public PhuHuynh()
{
}
public PhuHuynh(string name, string address, string phone, string code)
{
Name = name;
Address = address;
this.Phone = phone;
Code = code;
}
public void input()
{
Console.WriteLine("\nInsert Name: ");
Name = Console.ReadLine();
Console.WriteLine("Insert Address: ");
Address = Console.ReadLine();
Console.WriteLine("Insetr Phone: ");
Phone = Console.ReadLine();
Console.WriteLine("Insert Code: ");
Code = Console.ReadLine();
}
public void display()
{
Console.WriteLine("Name: {0}; Address: {1}; Phone: {2}; Code: {3}", Name, Address, Phone, Code);
}
}
}
#SinhVien
using System;
using System.Collections.Generic;
using System.Text;
namespace QuảnLySinhVien1523
{
class SinhVien
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string CodeStd { get; set; }
public string CodePrt { get; set; }
public SinhVien()
{
}
public SinhVien(string name, int age, string address, string phone, string email, string codeStd, string codePrt)
{
Name = name;
Age = age;
Address = address;
this.Phone = phone;
Email = email;
CodeStd = codeStd;
CodePrt = codePrt;
}
public void input()
{
Console.WriteLine("\nInsert Name: ");
Name = Console.ReadLine();
Console.WriteLine("Insert Age: ");
Age = int.Parse(Console.ReadLine());
Console.WriteLine("Insert Address: ");
Address = Console.ReadLine();
Console.WriteLine("Insert Phone: ");
Phone = Console.ReadLine();
Console.WriteLine("Insert Email: ");
Email = Console.ReadLine();
Console.WriteLine("Insert Code Sinhvien: ");
CodeStd = Console.ReadLine();
Console.WriteLine("Insert Code SinhVien: ");
CodePrt = Console.ReadLine();
}
public void display()
{
Console.WriteLine("Name: {0}; Age: {1}; Address: {2}; Phone: {3}; Email: {4}; CodeStd: {5}; CodePrt: {6}", Name, Age, Address, Phone, Email, CodeStd, CodePrt);
}
}
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-05-26 10:21:41
using System;
using System.Collections.Generic;
using System.Text;
namespace Lesson6.Deligate.Event.StudentManager
{
class Parent
{
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Roolno { get; set; }
public Parent() { }
public Parent(string Name, string Address, string Phone, string Roolno)
{
this.Name = Name;
this.Address = Address;
this.Phone = Phone;
this.Roolno = Roolno;
}
public void Input()
{
Console.WriteLine("Nhap ten phu huynh:");
Name = Console.ReadLine();
Console.WriteLine("Nhap dia chi phu huynh:");
Address = Console.ReadLine();
Console.WriteLine("Nhap SDT phu huynh:");
Phone = Console.ReadLine();
Console.WriteLine("Nhap ma phu hiunh:");
Roolno = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Ten PH: {0}, Dia chi PH: {1}, SDT PH: {2}, Ma PH; {3}", Name, Address, Phone, Roolno);
}
}
}