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)
![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:24
using System;
using System.Collections.Generic;
using System.Text;
namespace Lesson6.Deligate.Event.StudentManager
{
class Student
{
public string Roolno { get; set; }
public int Age { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string ParentRoolno { get; set; }
public Student() { }
public Student(string Name, int Age, string Roolno, string Address, string Email, string Phone, string ParentRoolno)
{
this.Name = Name;
this.Roolno = Roolno;
this.Address = Address;
this.Email = Email;
this.Phone = Phone;
this.ParentRoolno = ParentRoolno;
this.Age = Age;
}
public void Input()
{
Console.WriteLine("Nhap ten sinh vien:");
Name = Console.ReadLine();
Console.WriteLine("Nhap tuoi sinh vien:");
Age = Int32.Parse(Console.ReadLine());
Console.WriteLine("Nhap ma sinh vien:");
Roolno = Console.ReadLine();
Console.WriteLine("Nhap dia chi sinh vien:");
Address = Console.ReadLine();
Console.WriteLine("Nhap Email sinh vien:");
Email = Console.ReadLine();
Console.WriteLine("Nhap SDT sinh vien:");
Phone = Console.ReadLine();
Console.WriteLine("Nhap ma phu huynh quan ly:");
ParentRoolno = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Ten SV: {0}, Tuoi SV: {1}, Ma SV: {2}, Dia chi SV: {3}, Email SV: {4}, SDT SV: {5}", Name, Age, Roolno, Address, Email, Phone);
}
}
}
![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:06
using System;
using System.Collections.Generic;
namespace Lesson6.Deligate.Event.StudentManager
{
public delegate void OnAddressPrint(string Address);
class Program
{
static List<Student> StudentList = new List<Student>();
static List<Parent> ParentList = new List<Parent>();
static event OnAddressPrint CalEventOAP = null;
static void Main(string[] args)
{
int option;
do
{
Menu();
option = Int32.Parse(Console.ReadLine());
switch (option)
{
case 1:
InputParentInformation();
break;
case 2:
InputStudentInformationn();
break;
case 3:
FindStudentBaseOnParentName();
break;
case 4:
FindParentBaseOnStudentRoolno();
break;
case 5:
Console.WriteLine("Nhap dia chi sinh vien");
string FindAddress = Console.ReadLine();
//OnAddressPrint OAP = FindAllStudentsBaseOnInputAddress;
//OAP(FindAddress);
CalEventOAP = FindAllStudentsBaseOnInputAddress;
CalEventOAP(FindAddress);
break;
case 6:
Console.WriteLine("Exit...Bye...! ");
break;
}
} while (option != 6);
}
private static void FindAllStudentsBaseOnInputAddress(string FindAddress)
{
foreach (Student student in StudentList)
{
if (student.Address == FindAddress)
{
student.Display();
}
}
}
private static void FindParentBaseOnStudentRoolno()
{
Console.WriteLine("Nhap ma hoc sinh:");
string FindRoolno = Console.ReadLine();
foreach (Student student in StudentList)
{
if (student.Roolno == FindRoolno)
{
foreach (Parent parent in ParentList)
{
if (parent.Roolno == student.ParentRoolno)
{
parent.Display();
}
}
}
}
}
private static void FindStudentBaseOnParentName()
{
Console.WriteLine("Nhap ten phu huynh:");
string FindName = Console.ReadLine();
Console.WriteLine("Danh dach hoc sinh tim duoc nhu sau:");
foreach (Parent parent in ParentList)
{
if(parent.Name == FindName)
{
foreach( Student student in StudentList)
{
if (parent.Roolno == student.ParentRoolno)
{
student.Display();
}
}
}
}
}
private static void InputStudentInformationn()
{
Console.WriteLine("Nhap so luong hoc sinh can them thong tin");
int N = Int32.Parse(Console.ReadLine());
for(int i = 0; i < N; i++)
{
Student student = new Student();
student.Input();
StudentList.Add(student);
}
}
private static void InputParentInformation()
{
Console.WriteLine("Nhap so luong phu huynh can them thong tin");
int M = Int32.Parse(Console.ReadLine());
for (int i = 0; i < M; i++)
{
Parent parent = new Parent();
parent.Input();
ParentList.Add(parent);
}
}
static void Menu()
{
Console.WriteLine("1.Input parent information");
Console.WriteLine("2.Input student information");
Console.WriteLine("3.Find student base on parent name");
Console.WriteLine("4.Find parent base on student roolno");
Console.WriteLine("5.Find all students base on input address");
Console.WriteLine("6.Exit Program");
Console.WriteLine("Input your option: ");
}
}
}
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2021-05-26 09:49:06
using System;
using System.Collections.Generic;
namespace thongtinsinhvien
{
public delegate String OnAddressPrint(String diachi);
class Program
{
static event OnAddressPrint EventAddressPrint = null;
public static List<Sinvien> svlist = new List<Sinvien>();
public static List<Phuhuynh> phlist = new List<Phuhuynh>();
static void Main(string[] args)
{
int lc;
do {
menu();
Console.WriteLine("Nhap su lua chon");
lc = Int32.Parse(Console.ReadLine());
switch (lc) {
case 1:
int m;
Console.WriteLine("Nhap so luong phu huynh can them: ");
m = Int32.Parse(Console.ReadLine());
for (int i = 0; i < m; i++)
{
Phuhuynh ph = new Phuhuynh();
ph.Nhap();
phlist.Add(ph);
}
break;
case 2:
int n;
Console.WriteLine("Nhap so luong sinh vien can them: ");
n = Int32.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
Sinvien sv = new Sinvien();
sv.nhap();
svlist.Add(sv);
}
break;
case 3:
Console.WriteLine("Nhap ten phu huynh");
String ten = Console.ReadLine();
String t = Timten(ten);
foreach (Sinvien sv in svlist) {
if (sv.Sv_maphuhuynh == t) {
sv.hienthi();
}
}
break;
case 4:
Console.WriteLine("Nhap ma sinh vien: ");
String masv = Console.ReadLine();
String maph = Timph(masv);
foreach (Phuhuynh ph in phlist)
{
if (ph.Ph_ma == maph)
{
ph.hienthi();
}
}
break;
case 5:
String diachi;
Console.WriteLine("Nhap dia chi");
diachi = Console.ReadLine();
List<OnAddressPrint> list = new List<OnAddressPrint>();
list.Add(Timdiachi);
foreach (OnAddressPrint o in list) {
o(diachi);
}
Console.WriteLine("even!!");
EventAddressPrint = Timdiachi;
EventAddressPrint(diachi);
break;
}
} while (lc > 0);
}
public static void menu() {
Console.WriteLine(" 1 Nhap thong tin phu huynh: ");
Console.WriteLine(" 2 Nhap thong tin sinh vien: ");
Console.WriteLine(" 3 Tim sinh vien theo ma phu huynh: ");
Console.WriteLine(" 4 Tim phu huynh theo ma sinh vien");
Console.WriteLine(" 5 tim sinh vien theo dia chi");
}
public static String Timten(String ten) {
String t = "";
foreach (Phuhuynh ph in phlist) {
if (ph.Ph_ten == ten) {
t = ph.Ph_ma;
}
}
return t;
}
public static String Timph(String ma)
{
String t = "";
foreach (Sinvien sv in svlist)
{
if (sv.Sv_ma == ma)
{
t = sv.Sv_maphuhuynh;
}
}
return t;
}
public static String Timdiachi(String dc) {
String svl = "" ;
foreach (Sinvien sv in svlist) {
if (sv.Sv_diachi == dc)
{
svl = sv.tostring();
sv.hienthi();
}
}
return svl;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace thongtinsinhvien
{
class Sinvien
{
public String Sv_ten { get; set; }
public int Sv_tuoi { get; set; }
public String Sv_ma { set; get; }
public String Sv_diachi { set; get; }
public String Sv_email { get; set; }
public int Sv_sdt { get; set; }
public String Sv_maphuhuynh { get; set; }
public Sinvien() { }
public void nhap() {
Console.WriteLine(" Nhap ma sinh vien: ");
Sv_ma = Console.ReadLine();
Console.WriteLine("Nhap ten sinh vien: ");
Sv_ten = Console.ReadLine();
Console.WriteLine("Nhap tuoi sinh vien: ");
Sv_tuoi = Int32.Parse(Console.ReadLine());
Console.WriteLine("Nhap email sinh vienL: ");
Sv_email = Console.ReadLine();
Console.WriteLine("Nhap so dien thoai: ");
Sv_sdt = Int32.Parse(Console.ReadLine());
Console.WriteLine("Nhap dia chi sinh vien: ");
Sv_diachi = Console.ReadLine();
Console.WriteLine("Nhap ma phu huynh: ");
Sv_maphuhuynh = Console.ReadLine();
}
public void hienthi() {
Console.WriteLine("Ma sinh vien: " + Sv_ma + " , Ten sinh vien: " + Sv_ten + " , Tuoi sinh vien: " + Sv_tuoi + " , Email: " + Sv_email + " , so dien thoai: " + Sv_sdt + " , Dia chi sinh vien: " + Sv_diachi + " , ma phu huynh: " + Sv_maphuhuynh);
}
public String tostring() {
return "Ma sinh vien: " + Sv_ma + " , Ten sinh vien: " + Sv_ten + " , Tuoi sinh vien: " + Sv_tuoi + " , Email: " + Sv_email + " , so dien thoai: " + Sv_sdt + " , Dia chi sinh vien: " + Sv_diachi + " , ma phu huynh: " + Sv_maphuhuynh;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace thongtinsinhvien
{
class Phuhuynh
{
public String Ph_ten { get; set; }
public String Ph_diachi { set; get; }
public int Ph_sdt { get; set; }
public String Ph_ma { get; set; }
public Phuhuynh() { }
public void Nhap() {
Console.WriteLine("Nhap ma phu huynh");
Ph_ma = Console.ReadLine();
Console.WriteLine("Nhap ten phu huynh: ");
Ph_ten = Console.ReadLine();
Console.WriteLine("Nhap so dien thoai phui huynh: ");
Ph_sdt = Int32.Parse(Console.ReadLine()) ;
Console.WriteLine("Nhap dia chi phu huynh: ");
Ph_diachi = Console.ReadLine();
}
public void hienthi() {
Console.WriteLine("Ma phu huynh: " + Ph_ma + " , Ten phu huynh: " + Ph_ten + " , So dien thoai phu huynh: " + Ph_sdt + " , Dia chi phu huynh: " + Ph_diachi);
}
}
}
![Hoàng Quang Huy [C1907L]](https://www.gravatar.com/avatar/76e646e11f1674fba03bddd0ae020813.jpg?s=80&d=mm&r=g)
Hoàng Quang Huy
2020-07-13 08:48:17
using System;
using System.Collections.Generic;
using System.Text;
namespace Project7
{
class PhuHuynh
{
public string Ten { get; set; }
public string Address { get; set; }
public string Sdt { get; set; }
public string MaPH { get; set; }
public PhuHuynh(string ten, string address, string sdt, string maPH)
{
Ten = ten;
Address = address;
Sdt = sdt;
MaPH = maPH;
}
public PhuHuynh()
{
}
public void Input()
{
Console.WriteLine("Nhập tên: ");
this.Ten = Console.ReadLine();
Console.WriteLine("Nhập địa chỉ: ");
this.Address = Console.ReadLine();
Console.WriteLine("Nhập số điện thoại: ");
this.Sdt = Console.ReadLine();
Console.WriteLine("Nhập mã phụ huynh: ");
this.MaPH = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Tên phụ huynh: " + Ten);
Console.WriteLine("Địa chỉ: " + Address);
Console.WriteLine("Số điện thoại: " + Sdt);
Console.WriteLine("Mã phụ huynh: " + MaPH);
}
}
}
-------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace Project7
{
class SinhVien
{
public string Ten { get; set; }
public int Tuoi { get; set; }
public string MaSV { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string Sdt { get; set; }
public string MaPH { get; set; }
public SinhVien(string ten, int tuoi, string maSV, string address, string email, string sdt, string maPH)
{
Ten = ten;
Tuoi = tuoi;
MaSV = maSV;
Address = address;
Email = email;
Sdt = sdt;
MaPH = maPH;
}
public SinhVien()
{
}
public void Input()
{
Console.WriteLine("Nhập tên: ");
this.Ten = Console.ReadLine();
Console.WriteLine("Nhập tuổi: ");
this.Tuoi = int.Parse(Console.ReadLine());
Console.WriteLine("Nhập mã sinh viên: ");
this.MaSV = Console.ReadLine();
Console.WriteLine("Nhập địa chỉ: ");
this.Address = Console.ReadLine();
Console.WriteLine("Nhập email: ");
this.Email = Console.ReadLine();
Console.WriteLine("Nhập số điện thoại: ");
this.Sdt = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Tên sinh viên: "+Ten);
Console.WriteLine("Tuổi: " + Tuoi);
Console.WriteLine("Mã sinh viên: "+MaSV);
Console.WriteLine("Địa chỉ: "+Address);
Console.WriteLine("Email: "+Email);
Console.WriteLine("Số điện thoại: "+Sdt);
Console.WriteLine("Mã phụ huynh: "+MaPH);
}
}
}
-------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
namespace Project7
{
public delegate void OnAddressPrint();
public class Test
{
static event OnAddressPrint EventAddressPrint;
static List<PhuHuynh> ListPhuHuynh = new List<PhuHuynh>();
static List<SinhVien> ListSinhVien = new List<SinhVien>();
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.Unicode;
int choose;
do
{
ShowMenu();
choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Nhập số lượng phụ huynh: ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
PhuHuynh ph = new PhuHuynh();
ph.Input();
ListPhuHuynh.Add(ph);
}
break;
case 2:
Console.WriteLine("Nhập số lượng sinh viên: ");
int m = int.Parse(Console.ReadLine());
int flag;
for (int i = 0; i < m; i++)
{
flag = 0;
SinhVien sv = new SinhVien();
sv.Input();
do
{
Console.WriteLine("Nhập mã phụ huynh: ");
sv.MaPH = Console.ReadLine();
foreach (PhuHuynh ph in ListPhuHuynh)
{
if (sv.MaPH.Equals(ph.MaPH))
{
ListSinhVien.Add(sv);
flag = 1;
}
}
if (flag == 0)
{
Console.WriteLine("Không có mã phụ huynh phù hợp");
}
} while (flag == 0);
}
break;
case 3:
Console.WriteLine("Nhập tên phụ huynh cần tìm kiếm: ");
string namePh = Console.ReadLine();
string codePH = "";
foreach (PhuHuynh ph in ListPhuHuynh)
{
if (ph.Ten.Equals(namePh))
{
codePH = ph.MaPH;
}
}
foreach (SinhVien sv in ListSinhVien)
{
if (codePH.Equals(sv.MaPH))
{
sv.Display();
}
}
break;
case 4:
Console.WriteLine("Nhập mã sinh viên cần tìm kiếm: ");
string masv = Console.ReadLine();
foreach (SinhVien sv in ListSinhVien)
{
if (masv.Equals(sv.MaSV))
{
foreach (PhuHuynh ph in ListPhuHuynh)
{
if (sv.MaPH.Equals(ph.MaPH))
{
ph.Display();
}
}
}
}
break;
case 5:
TestEvent();
break;
case 6:
Environment.Exit(0);
break;
default:
break;
}
} while (choose != 6);
}
static void ShowMenu()
{
Console.WriteLine("1. Nhập thông tin N phụ huynh");
Console.WriteLine("2. Nhập thông tin M sinh viên");
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("6.Thoát");
}
static void TestEvent()
{
EventAddressPrint = new OnAddressPrint(OnAddressEvent);
EventAddressPrint();
}
static void OnAddressEvent()
{
Console.WriteLine("Nhập địa chỉ cần tìm kiếm");
string address = Console.ReadLine();
foreach (SinhVien sv in ListSinhVien)
{
if (address.Equals(sv.Address))
{
sv.Display();
}
}
}
}
}
![Nguyễn Hoàng Anh [C1907L]](https://www.gravatar.com/avatar/5b7bb435cae0d0a0fd414f6fdd0adc87.jpg?s=80&d=mm&r=g)
Nguyễn Hoàng Anh
2020-07-11 05:10:23
using System;
using System.Collections.Generic;
namespace StudentManagerDelegate
{
class Program
{
public delegate void OnAddressPrint(List<SinhVien> ListSV);
static event OnAddressPrint EventAddressPrint;
static void Menu()
{
Console.WriteLine("1.Nhap thong tin N phu huynh");
Console.WriteLine("2.Nhap thong tin M sinh vien");
Console.WriteLine("3.Tim kiem thong tin sinh vien(dung ma phu huynh)");
Console.WriteLine("4.Tim kiem thong tin phu huynh(dung ma hoc sinh)");
Console.WriteLine("5.In thong tin sinh vien theo dia chi nhap vao");
Console.WriteLine("6.Exit");
}
static void ThemPhuHuynh(List<PhuHuynh> ListPH)
{
Console.WriteLine("Nhap N phu huynh : ");
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++)
{
while (true)
{
Console.WriteLine("Nhap thong tin phu huynh {0}.", (ListPH.Count));
PhuHuynh ph = new PhuHuynh();
ph.input();
int j;
for (j = 0; j < ListPH.Count; j++)
{
if (ListPH[j].MaPH.Equals(ph.MaPH))
{
Console.WriteLine("Ma phu huynh da ton tai.");
break;
}
}
if (j == ListPH.Count)
{
ListPH.Add(ph);
break;
}
}
}
}
static void ThemSinhVien(List<PhuHuynh> ListPH, List<SinhVien> ListSV)
{
Console.WriteLine("Nhap N sinh vien : ");
int M = int.Parse(Console.ReadLine());
for (int j = 0; j < M; j++)
{
SinhVien sv = new SinhVien();
while (true) {
Console.WriteLine("Nhap thong tin sinh vien {0}.", (ListSV.Count));
sv.input();
int k;
for (k = 0; k < ListSV.Count; k++)
{
if (ListSV[k].MaSV.Equals(sv.MaSV))
{
Console.WriteLine("Ma sinh vien da ton tai.");
break;
}
}
if (k == ListSV.Count)
{
break;
}
}
while (true)
{
Console.WriteLine("Nhap ma phu huynh : ");
string maPH = Console.ReadLine();
int i;
for (i = 0; i < ListPH.Count; i++)
{
if (ListPH[i].MaPH.Equals(maPH))
{
break;
}
}
if (i == ListPH.Count)
{
Console.WriteLine("Khong tim thay phu huynh");
}
else
{
sv.MaPH = maPH;
ListSV.Add(sv);
break;
}
}
}
}
static void TimPH(List<SinhVien> ListSV, List<PhuHuynh> ListPH)
{
Console.WriteLine("Nhap ma sinh vien : ");
string maSV = Console.ReadLine();
int i;
string maPH = "";
for (i = 0; i < ListSV.Count; i++)
{
if (ListSV[i].MaSV.Equals(maSV))
{
maPH = ListSV[i].MaPH;
break;
}
}
if (i == ListSV.Count)
{
Console.WriteLine("Khong tim thay sinh vien nao");
}
else
{
for (i = 0; i < ListPH.Count; i++)
{
if (ListPH[i].MaPH.Equals(maPH)) ;
{
ListPH[i].display();
break;
}
}
}
}
static void TimSV(List<SinhVien> ListSV)
{
Console.WriteLine("Nhap ma phu huynh : ");
string maPH = Console.ReadLine();
int i = 0;
for (i = 0; i < ListSV.Count; i++)
{
if (ListSV[i].MaPH.Equals(maPH))
{
ListSV[i].display();
break;
}
}
if (i == ListSV.Count)
{
Console.WriteLine("Khong tim thay sinh vien nao");
}
}
static void ClickOnAddressPrintEvent(List<SinhVien> ListSV)
{
EventAddressPrint = new OnAddressPrint(OnAddressPrint_);
EventAddressPrint(ListSV);
}
static void OnAddressPrint_(List<SinhVien> ListSV)
{
Console.WriteLine("Enter address : ");
string adress = Console.ReadLine();
for (int i = 0; i < ListSV.Count; i++)
{
if (ListSV[i].DiaChi.Equals(adress))
{
ListSV[i].display();
}
}
}
static void Main(string[] args)
{
List<PhuHuynh> ListPH = new List<PhuHuynh>();
List<SinhVien> ListSV = new List<SinhVien>();
while (true)
{
Menu();
int choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
ThemPhuHuynh(ListPH);
break;
case 2:
ThemSinhVien(ListPH, ListSV);
break;
case 3:
TimSV(ListSV);
break;
case 4:
TimPH(ListSV, ListPH);
break;
case 5:
ClickOnAddressPrintEvent(ListSV);
break;
case 6:
break;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace StudentManagerDelegate
{
class SinhVien
{
public string MaSV { get; set; }
public string Ten { get; set; }
public string DiaChi { get; set; }
public string Email { get; set; }
public string MaPH { get; set; }
public SinhVien(string maSV, string ten, string diaChi, string email, string maPH)
{
MaSV = maSV;
Ten = ten;
DiaChi = diaChi;
Email = email;
MaPH = maPH;
}
public SinhVien()
{
}
public void input() {
Console.WriteLine("Nhap ma sinh vien : ");
MaSV = Console.ReadLine();
Console.WriteLine("Nhap ten sinh vien : ");
Ten = Console.ReadLine();
Console.WriteLine("Nhap dia chi : ");
DiaChi = Console.ReadLine();
Console.WriteLine("Nhap email : ");
Email = Console.ReadLine();
}
public void display() {
Console.WriteLine("Ma sinh vien : {0} , Ten sinh vien : {1} , Dia chi : {2} , Email : {3} , Ma phu huynh : {4}", MaSV,Ten,DiaChi,Email,MaPH);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace StudentManagerDelegate
{
class PhuHuynh
{
public string MaPH { get; set; }
public string DiaChi { get; set; }
public string SDT { get; set; }
public PhuHuynh()
{
}
public PhuHuynh(string maPH, string diaChi, string sDT)
{
MaPH = maPH;
DiaChi = diaChi;
SDT = sDT;
}
public void input() {
Console.WriteLine("Nhap ma phu huynh : ");
MaPH = Console.ReadLine();
Console.WriteLine("Nhap dia chi : ");
DiaChi = Console.ReadLine();
Console.WriteLine("Nhap SDT : ");
SDT = Console.ReadLine();
}
public void display() {
Console.WriteLine("Ma phu huynh : {0} , Dia chi : {1} , SDT : {2}", MaPH, DiaChi,SDT);
}
}
}
![trung [C1907L]](https://www.gravatar.com/avatar/67c23432e4710f33dd14e580d41b0379.jpg?s=80&d=mm&r=g)
trung
2020-07-10 14:07:06
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationtest
{
public class DataMgr
{
private static DataMgr _instance = null;
public List<PhuHuynh> ListPhuHuynh;
public List<SinhVien> ListSinhVien;
private DataMgr()
{
ListPhuHuynh = new List<PhuHuynh>();
ListSinhVien = new List<SinhVien>();
}
public static DataMgr Instance
{
get
{
if (_instance == null)
{
_instance = new DataMgr();
}
return _instance;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationtest
{
public class PhuHuynh
{
// 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ị
public string Ten { get; set; }
public string SoDT { get; set; }
public string MaPH { get; set; }
public PhuHuynh()
{
}
public void Input()
{
Console.WriteLine("Nhap vao ma phu huynh di ban oi");
MaPH = Console.ReadLine();
Console.WriteLine("Nhap vao ten phu huynh di ban oi");
Ten = Console.ReadLine();
Console.WriteLine("Nhap vao so dien thoai di ban oi");
SoDT = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Ma phu huynh la {0} | Ten phu huynh la {1} | So dien thoai la {2}", MaPH, Ten, SoDT);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationtest
{
public class SinhVien
{
//tên, tuổi, mã sinh viên, địa chỉ, email, sđt, mã phụ huynh
public string Ten { get; set; }
public string MaSV { get; set; }
public string DiaChi { get; set; }
public string Email { get; set; }
public string SoDT { get; set; }
public string MaPH { get; set; }
public SinhVien()
{ }
public void Input()
{
Console.WriteLine("Nhap vao ten sinh vien");
Ten = Console.ReadLine();
Console.WriteLine("Nhap vao ma sinh vien");
MaSV = Console.ReadLine();
Console.WriteLine("Nhap vao dia chi");
DiaChi = Console.ReadLine();
Console.WriteLine("Nhap vao email");
Email = Console.ReadLine();
Console.WriteLine("Nhap vao so dien thoai");
SoDT = Console.ReadLine();
Console.WriteLine("Nhap vao ma phu huynh");
string mph = Console.ReadLine();
foreach (PhuHuynh ph in DataMgr.Instance.ListPhuHuynh)
{
if (mph.Equals(ph.MaPH))
{
return;
}
}
// neu khong ton tai ma phu huynh thi bao nhap moi nhe'
Console.WriteLine("Bay gio nhap phu huynh moi nhe");
PhuHuynh newph = new PhuHuynh();
newph.Input();
DataMgr.Instance.ListPhuHuynh.Add(newph);
MaPH = mph;
}
public void Display()
{
Console.WriteLine("Ma sinh vien la {0} | Ten sinh vien la {1} | Dia chi la {2} | Email la {3} | So dien thoai {4} | Ma phu huynh {5}", MaSV, Ten, DiaChi, Email, SoDT, MaPH);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationtest
{
public delegate void OnAddressPrint();
public class Program
{
static event OnAddressPrint OnSave;
public static void Main(string[] args)
{
int choice = 0;
do
{
ShowMenu();
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
Console.WriteLine("Nhap vao so luong phu huynh");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
PhuHuynh newph = new PhuHuynh();
newph.Input();
DataMgr.Instance.ListPhuHuynh.Add(newph);
}
break;
case 2:
Console.WriteLine("Nhap vao so luong sinh vien");
int m = int.Parse(Console.ReadLine());
for (int i = 0; i < m; i++)
{
SinhVien newsv = new SinhVien();
newsv.Input();
DataMgr.Instance.ListSinhVien.Add(newsv);
}
break;
case 3:
Console.WriteLine("Nhap vao ma phu huynh");
string mph = Console.ReadLine();
foreach (SinhVien sv in DataMgr.Instance.ListSinhVien)
{
if (sv.MaPH.Equals(mph))
{
sv.Display();
}
}
break;
case 4:
Console.WriteLine("Nhap vao ma sinh vien");
string msv = Console.ReadLine();
foreach (SinhVien sv in DataMgr.Instance.ListSinhVien)
{
if (sv.MaPH.Equals(msv))
{
foreach(PhuHuynh ph in DataMgr.Instance.ListPhuHuynh)
{
if (ph.MaPH.Equals(sv.MaPH))
{
ph.Display();
break;
}
}
}
}
break;
case 5:
TestEvents();
break;
case 6:
Console.WriteLine("Exit");
break;
default:
Console.WriteLine("Invalid input ...");
break;
}
} while (choice != 6);
}
static void TestEvents()
{
OnSave = new OnAddressPrint(OnSaveEvent);
OnSave();
}
static void OnSaveEvent()
{
Console.WriteLine("Nhap vao dia chi sinh vien");
string diaChi = Console.ReadLine();
foreach(SinhVien sv in DataMgr.Instance.ListSinhVien)
{
if (sv.DiaChi.Equals(diaChi))
{
sv.Display();
}
}
}
static void ShowMenu()
{
Console.WriteLine("1.Nhập thông tin N phụ huynh");
Console.WriteLine("2.Nhập thông tin M sinh viên");
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("6. Exit.");
Console.WriteLine("Your choice : ...");
}
}
}
![Ngô Quang Huy [C1907L]](https://www.gravatar.com/avatar/8e54dbf5994077ce599f49278164ae79.jpg?s=80&d=mm&r=g)
Ngô Quang Huy
2020-07-10 14:05:37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QLSV
{
public delegate void OnAddressPrint();
class Program
{
static event OnAddressPrint EventAddressPrint;
static List<Parents> parentsList = new List<Parents>();
static List<Student> studentList = new List<Student>();
static void Main(string[] args)
{
while (true)
{
Menu();
int choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
InsertParent();
break;
case 2:
InsertStudent();
break;
case 3:
FindStudent();
break;
case 4:
FindParent();
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 InsertParent()
{
Console.Write("N = ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
Parents p = new Parents();
p.input();
parentsList.Add(p);
}
}
static void InsertStudent()
{
Console.Write("M = ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
Student p = new Student();
p.input();
int flag;
do
{
Console.WriteLine("Insert Code Parent: ");
p.CodePrt = Console.ReadLine();
flag = 0;
foreach (Parents prt in parentsList)
{
if (prt.Code.Equals(p.CodePrt))
{
flag = 1;
}
}
if (flag==0)
{
Console.WriteLine("No parent have this code");
}
} while (flag == 0);
studentList.Add(p);
}
}
static void FindStudent()
{
Console.Write("Parent Name: ");
string search = Console.ReadLine();
foreach (Parents p in parentsList)
{
if (p.Name.Equals(search))
{
Console.WriteLine("\tParent: ");
p.display();
Console.WriteLine("\tStudent: ");
foreach (Student s in studentList)
{
if (s.CodePrt.Equals(p.Code))
{
s.display();
}
}
return;
}
}
}
static void FindParent()
{
Console.Write("Student Code: ");
string search = Console.ReadLine();
foreach (Student s in studentList)
{
if (s.CodeStd.Equals(search))
{
Console.WriteLine("\tStudent: ");
s.display();
Console.WriteLine("\tParent: ");
foreach (Parents p in parentsList)
{
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 (Student s in studentList)
{
if (s.Address.Equals(addr))
{
s.display();
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QLSV
{
class Parents
{
public string Name { get; set; }
public string Address { get; set; }
public string sdt { get; set; }
public string Code { get; set; }
public Parents()
{
}
public Parents(string name, string address, string sdt, string code)
{
Name = name;
Address = address;
this.sdt = sdt;
Code = code;
}
public void input()
{
Console.WriteLine("\nInsert Name: ");
Name = Console.ReadLine();
Console.WriteLine("Insert Address: ");
Address = Console.ReadLine();
Console.WriteLine("Insert sdt: ");
sdt = Console.ReadLine();
Console.WriteLine("Insert Code: ");
Code = Console.ReadLine();
}
public void display()
{
Console.WriteLine("Name: {0}; Address: {1}; sdt: {2}; Code: {3}", Name, Address, sdt, Code);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QLSV
{
class Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public string sdt { get; set; }
public string Email { get; set; }
public string CodeStd { get; set; }
public string CodePrt { get; set; }
public Student()
{
}
public Student(string name, int age, string address, string sdt, string email, string codeStd, string codePrt)
{
Name = name;
Age = age;
Address = address;
this.sdt = sdt;
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 sdt: ");
sdt = Console.ReadLine();
Console.WriteLine("Insert Email: ");
Email = Console.ReadLine();
Console.WriteLine("Insert Code Student: ");
CodeStd = Console.ReadLine();
}
public void display()
{
Console.WriteLine("Name: {0}; Age: {1}; Address: {2}; sdt: {3}; Email: {4}; CodeStd: {5}; CodePrt: {6}", Name, Age, Address, sdt, Email, CodeStd, CodePrt);
}
}
}
![Trần Ngọc Hải [T1907A]](https://www.gravatar.com/avatar/9f7a27af52cbf0d52c32019e1354d60a.jpg?s=80&d=mm&r=g)
Trần Ngọc Hải
2020-06-05 08:52:01
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaiThiC
{
class ContactManager
{
static void Main(string[] args)
{
Hashtable hash = new Hashtable();
int choose;
do
{
show();
choose = Int32.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Nhap so luong so nhap:");
int n = Int32.Parse(Console.ReadLine());
Input(n, hash);
break;
case 2:
Search(hash);
break;
case 3:
Display(hash);
break;
case 4:
Console.WriteLine("Exit success");
break;
default:
Console.WriteLine("Error");
break;
}
} while (choose != 4);
}
private static void show()
{
Console.WriteLine("1. Add new contact");
Console.WriteLine("2. Find a contact by name");
Console.WriteLine("3. Display contacts");
Console.WriteLine("4. Exit");
Console.WriteLine("Enter choose: ");
}
private static void Input(int n, Hashtable hash)
{
for(int i =0; i < n; i++)
{
Phone phone = new Phone();
phone.Input();
hash.Add(phone.Name, phone.PhoneNumber);
}
}
private static void Display(Hashtable hash)
{
ICollection key = hash.Keys;
foreach (string k in key)
{
Console.WriteLine(k + ": " + hash[k]);
}
}
private static void Search(Hashtable hash) {
ICollection key = hash.Keys;
Console.WriteLine("Enter name to searh: ");
string name = Console.ReadLine();
foreach (string k in key)
{
if (name.Equals(k))
{
Console.WriteLine(k + ": " + hash[k]);
}
else
{
Console.WriteLine("No names in contacts");
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaiThiC
{
class Phone
{
public string FullName { get; set; }
public int PhoneNumber { get; set; }
public void Input()
{
bool ischeck = true;
while (ischeck)
{
Console.Write("Nhap ten: ");
FullName = Console.ReadLine();
if (string.IsNullOrEmpty(FullName) == false)
{
ischeck = false;
}
else
{
Console.WriteLine("Loi.");
}
}
Console.WriteLine("Nhap so dien thoai: ");
PhoneNumber = Int32.Parse(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("Ten: {0}; So dien thoai: {1}", FullName, PhoneNumber);
}
}
}
![Trương Công Vinh [T1907A]](https://www.gravatar.com/avatar/223a7e3a46f4a747f81b921fe023fcc4.jpg?s=80&d=mm&r=g)
Trương Công Vinh
2020-05-30 07:44:13
using System;
using System.Collections.Generic;
using System.Text;
namespace Inforstudent
{
class Student
{
public string studentID { get; set; }
public string name { get; set; }
public int age { get; set; }
public string address { get; set; }
public string email { get; set; }
public string sdt { get; set; }
public string prtId { get; set; }
public Student()
{
}
public void input(List<Parent> lParent, List<string> vs)
{
inputStudentID(vs);
Console.WriteLine("Name of student : ");
name = Console.ReadLine();
inputAge();
Console.WriteLine("Address : ");
address = Console.ReadLine();
inputSdt();
inputemail();
inputParentId(lParent);
}
private void inputParentId(List<Parent> lParent)
{
Console.WriteLine("ParentID : ");
prtId = Console.ReadLine();
bool ischeck = false;
foreach (var item in lParent)
{
if (item.prtId.Equals(prtId))
{
ischeck = true;
break;
}
}
if (!ischeck)
{
Parent parent = new Parent();
parent.input(prtId);
}
}
private void inputAge()
{
bool ischeck = true;
while (ischeck)
{
Console.WriteLine("Age :");
string c2 = Console.ReadLine();
if (checkc(c2) && c2.Length == 10&&string.IsNullOrEmpty(c2)==false)
{
age = int.Parse(c2);
ischeck = false;
break;
}
else
{
Console.WriteLine("Error !!");
}
}
}
private void inputSdt()
{
bool ischeck = true;
while (ischeck)
{
Console.WriteLine("Telephone number : ");
sdt = Console.ReadLine();
if (checkc(sdt) && sdt.Length == 10)
{
ischeck = false;
break;
}
}
}
bool checkc(string s)
{
bool check = true;
foreach (char item in s)
{
if (item < 48 || item > 57)
{
check = false;
break;
}
}
return check;
}
private void inputemail()
{
bool isCheck = true;
while (isCheck)
{
Console.WriteLine("email : ");
email = Console.ReadLine();
if (!email.Contains("@") || email.Contains(" ")||email.Length<12)
{
Console.WriteLine("Error : email is constaining '@' or space");
}
else
{
isCheck = false;
}
}
}
public void display()
{
Console.WriteLine("tên : {0}, tuổi : {1}, mã sinh viên {2}, địa chỉ : {3}," +
" email : {4} , sđt : {5}, mã phụ huynh : {6}"
, name, age, studentID, address, email, sdt, prtId);
}
private void inputStudentID(List<string> vs)
{
bool ischeck = false;
for (; ischeck == false;)
{
Console.WriteLine("ID : ");
studentID = Console.ReadLine();
foreach (string str in vs)
{
if (studentID.Equals(str))
{
Console.WriteLine("StudentID da ton tai !!");
ischeck = true;
break;
}
}
if (!ischeck&&string.IsNullOrEmpty(studentID)==false)
{
vs.Add(studentID);
ischeck = true;
break;
}
else
{
Console.WriteLine("Error !!");
ischeck = false;
}
}
}
}
}
using Inforstudent;
using System;
using System.Collections.Generic;
using System.Text;
namespace InforStudent
{
public delegate void OnAddressPrint(string str);
class Program
{
static event OnAddressPrint EventAddressPrint;
static List<Parent> lParent = new List<Parent>();
static List<Student> lStudent = new List<Student>();
static List<string> ids = new List<string>();
static int c;
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine("Hello World!");
do
{
menu();
inputc();
switch (c)
{
case 1:
case1();
break;
case 2:
case2();
break;
case 3:
case3();
break;
case 4:
case4();
break;
case 5:
case5();
break;
default:
Console.WriteLine("nhap sai !!!");
break;
}
} while (c != 6);
}
static void inputc()
{
bool ischeck = true;
while (ischeck)
{
string c2 = Console.ReadLine();
if (checkc(c2) && string.IsNullOrEmpty(c2)==false )
{
c = int.Parse(c2);
ischeck = false;
break;
}
else
{
Console.WriteLine("Error !!");
}
}
}
static bool checkc(string s)
{
bool check = true;
foreach (char item in s)
{
if (item < 48 || item > 57)
{
check = false;
break;
}
}
return check;
}
static void menu()
{
Console.WriteLine("1. Nhập thông tin N phụ huynh");
Console.WriteLine("2. Nhập thông tin M sinh viên");
Console.WriteLine("3. thông tin các sinh viên được tham chiếu bởi phụ huynh");
Console.WriteLine("4. thông tin tra cứu phụ huynh");
Console.WriteLine("5. in thông tin sinh viên theo địa chỉ nhập vào.");
Console.WriteLine("6. thoat");
Console.WriteLine("chon : ");
}
static void case5()
{
Console.WriteLine("Enter address to search : ");
string find = Console.ReadLine();
EventAddressPrint += new OnAddressPrint(FindStdByAddress);
EventAddressPrint(find);
}
static void FindStdByAddress(string address)
{
foreach (Student student in lStudent)
{
if (student.address.Equals(address))
{
student.display();
}
}
}
static void case4()
{
bool ischeck = false;
Console.WriteLine("Enter studentId: ");
string find = Console.ReadLine();
foreach (var item in lStudent)
{
if (find.Equals(item.prtId))
{
ischeck = true;
break;
}
}
if (!ischeck)
{
Console.WriteLine("khoong ton tai studentId !!");
}
foreach (var item in lParent)
{
if (item.prtId.Equals(find))
{
Console.WriteLine("Information of parent : ");
item.display();
break;
}
}
}
static void case2()
{
int count = 0;
while (true)
{
Console.WriteLine("nhap thong tin student {0}", ++count);
Student student = new Student();
student.input(lParent, ids);
lStudent.Add(student);
Console.WriteLine("nhap them thong tin student : (y/n) ");
string option = Console.ReadLine();
if (option.Equals("n"))
{
break;
}
}
}
static void case3()
{
bool ischeck = false;
Console.WriteLine("nhap ma phu huynh : ");
string find = Console.ReadLine();
foreach (var item in lParent)
{
if (find.Equals(item.prtId))
{
ischeck = true;
break;
}
}
if (!ischeck)
{
Console.WriteLine("khoong ton tai ParentID !!");
}
foreach (var item in lStudent)
{
if (item.prtId.Equals(find))
{
item.display();
}
}
}
static void case1()
{
int count = 0;
while (true)
{
Console.WriteLine("nhap thong tin parent {0}", ++count);
Parent parent = new Parent();
parent.input(ids);
lParent.Add(parent);
Console.WriteLine("nhap them thong tin parent : (y/n) ");
string option = Console.ReadLine();
if (option.Equals("n"))
{
break;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Inforstudent
{
class Parent
{
public string name { get; set; }
public string address { get; set; }
public string sdt { get; set; }
public string prtId { get; set; }
public Parent()
{
}
public void input(List<string> vs)
{
inputParentID(vs);
input(prtId);
}
public void input(string prtID)
{
Console.WriteLine("Name of parent : ");
name = Console.ReadLine();
Console.WriteLine("Address : ");
address = Console.ReadLine();
inputSdt();
this.prtId = prtID;
}
public void display()
{
Console.WriteLine("Name of parent : {0} | Address : {1} | Telephone number : {2} | ParentID : {3}",name,address,sdt,prtId);
}
private void inputSdt()
{
bool ischeck = true;
while (ischeck)
{
Console.WriteLine("Telephone number : ");
sdt = Console.ReadLine();
if (checkc(sdt) && sdt.Length == 10 && string.IsNullOrEmpty(sdt) == false)
{
ischeck = false;
break;
}
}
}
bool checkc(string s)
{
bool check = true;
foreach (char item in s)
{
if (item < 48 || item > 57)
{
check = false;
break;
}
}
return check;
}
private void inputParentID(List<string> vs)
{
bool ischeck = false;
for (; ischeck == false ; )
{
Console.WriteLine("ParentId :");
prtId = Console.ReadLine();
foreach (string str in vs)
{
if (prtId.Equals(str))
{
Console.WriteLine("ParantId da ton tai !!");
ischeck = true;
break;
}
}
if (!ischeck && string.IsNullOrEmpty(prtId)== false)
{
vs.Add(prtId);
ischeck = true;
break;
}
else
{
ischeck = false;
}
}
}
}
}
![NguyenHuuThanh [T1907A]](https://www.gravatar.com/avatar/035e4f4fed661b8e1c3e066e43cd5e41.jpg?s=80&d=mm&r=g)
NguyenHuuThanh
2020-05-29 09:09:52
using System;
using System.Collections.Generic;
namespace Lession07Project
{
public delegate void OnAddressPrint();
class Program
{
static event OnAddressPrint EventAddressPrint;
static void Main(string[] args)
{
List<Parent> parentlist = new List<Parent>();
List<People> peoplelist = new List<People>();
int choice;
do
{
showMenu();
Console.WriteLine("Moi ban nhap lua chon :");
choice = int.Parse(Console.ReadLine());
switch(choice)
{
case 1:
for (; ; )
{
Console.WriteLine(" Moi ban nhap thong tin sinh vien :");
People people = new People();
people.input();
peoplelist.Add(people);
Console.WriteLine(" Ban co muon nhap nua khong ? : Y/N");
String option;
option = Console.ReadLine();
if (option.Equals("N"))
{
break;
}
}
break;
case 2:
for (; ; )
{
Console.WriteLine(" Moi ban nhap thong tin phu huynh :");
Parent parent = new Parent();
parent.input();
parentlist.Add(parent);
Console.WriteLine(" Ban co muon nhap nua khong ? : Y/N");
String option;
option = Console.ReadLine();
if (option.Equals("N"))
{
break;
}
}
break;
case 3:
Console.WriteLine("Moi ban nhap ten phu huynh :");
String Parentname = Console.ReadLine();
foreach(Parent parent in parentlist)
{
if (parent.name.Equals(Parentname))
{
foreach (People people in peoplelist)
{
if (parent.Parentrollnumber.Equals(people.Parentrollnumber))
{
people.display();
}
}
}
}
break;
case 4:
Console.WriteLine("Moi ban nhap ten sinh vien :");
String Studentname = Console.ReadLine();
foreach(People student in peoplelist)
{
if (student.name.Equals(Studentname))
{
foreach(Parent parent in parentlist)
{
if(student.Parentrollnumber.Equals(parent.Parentrollnumber))
{
parent.display();
}
}
}
}
break;
case 5:
// EventAddressPrint += new OnAddressPrint(showPeople);
//EventAddressPrint();
Console.WriteLine("Moi ban nhap vao dia chi sinh vien :");
String address = Console.ReadLine();
foreach (People people in peoplelist)
{
if (address.Equals(people.address))
{
people.display();
}
}
break;
case 6:
Console.WriteLine("Exit");
break;
default:
Console.WriteLine("Wrong input");
break;
}
} while (choice != 6);
}
static void showMenu()
{
Console.WriteLine("1. Nhập thông tin N phụ huynh");
Console.WriteLine("2. Nhập thông tin M sinh viên");
Console.WriteLine("3. Nhập tên phụ huynh -> hiện ra các sinh viên được tham chiếu");
Console.WriteLine("4. Nhập tên sinh viên -> hiện ra phụ huynh được tham chiếu");
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("6. Exit");
}
/* static void showPeople() // How to access a link in another method ?
{
Console.WriteLine("Moi ban nhap vao dia chi sinh vien :");
String address = Console.ReadLine();
foreach(People people in peoplelist )
{
if ( address.Equals(people.address))
{
people.display();
}
}
} */
}
}