Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class SinhVien
- {
- public string maSV;
- public int tuoiSV;
- public bool gioiTinh;
- public string MaSV {
- get {
- return this.maSV;
- }
- set {
- this.maSV = value;
- }
- }
- public int TuoiSV {
- get {
- return this.tuoiSV;
- }
- set {
- this.tuoiSV = value;
- }
- }
- public bool GioiTinh {
- get {
- return this.GioiTinh;
- }
- set {
- this.GioiTinh = value;
- }
- }
- public SinhVien(string maSV, int tuoiSV, bool gioiTinh) {
- this.maSV = maSV;
- this.tuoiSV = tuoiSV;
- this.gioiTinh = gioiTinh;
- }
- public void ToString() {
- Console.WriteLine("Ma Sinh Vien: " + this.maSV);
- Console.WriteLine("Tuoi Sinh Vien: " + this.tuoiSV);
- Console.WriteLine("Gioi Tinh Sinh Vien: " + this.gioiTinh);
- }
- public static void Input(SinhVien objSV) {
- Console.WriteLine("Nhap ma so sinh vien can them");
- objSV.MaSV = Console.ReadLine();
- Console.WriteLine("Nhap tuoi sinh vien can them");
- objSV.TuoiSV = Int32.Parse(Console.ReadLine());
- Console.WriteLine("Nhap gioi sinh vien can them (Nam/Nu) (1/0)");
- objSV.GioiTinh = false;
- int temp = Int32.Parse(Console.ReadLine());
- if(temp == 1) objSV.GioiTinh = true;
- else objSV.GioiTinh = false;
- }
- }
- public class ListSV
- {
- public SinhVien[] listSV;
- public int maxSV;
- public SinhVien getSV(int i) {
- return this.listSV[i];
- }
- public void setSV(int i, string maSV, int tuoiSV, bool gioiTinh) {
- this.listSV[i] = new SinhVien(maSV, tuoiSV, gioiTinh);
- }
- public int MaxSV {
- get {
- return this.maxSV;
- }
- set {
- this.maxSV = value;
- }
- }
- public ListSV(SinhVien[] listSV, int maxSV) {
- this.listSV = listSV;
- this.maxSV = maxSV;
- }
- public void Add(SinhVien objSV) {
- if(listSV.Length == maxSV) {
- Console.WriteLine("So luong sinh vien toi da, khong the them SV");
- return;
- }
- SinhVien[] newList = new SinhVien[listSV.Length + 1];
- this.listSV = newList;
- newList[newList.Length -1] = objSV;
- }
- public void Edit(SinhVien objSV, int i) {
- if(i > listSV.Length - 1) {
- Console.WriteLine("Vi tri khong ton tai");
- return;
- }
- listSV[i] = objSV;
- }
- public void Show(string kw) {
- if(kw.Equals("all"))
- for(int i=0; i<listSV.Length; i++) {
- listSV[i].ToString();
- }
- else for(int i=0; i<listSV.Length; i++) {
- if(listSV[i].MaSV.Equals(kw))
- listSV[i].ToString();
- }
- }
- public void SortAscending() {
- SinhVien temp = new SinhVien("",0,true);
- for(int i=0; i<listSV.Length; i++) {
- for(int j=i; j<listSV.Length; j++) {
- if(listSV[j].TuoiSV < listSV[i].TuoiSV) {
- temp = listSV[j];
- listSV[j] = listSV[i];
- listSV[i] = temp;
- }
- }
- }
- }
- public static void Main()
- {
- Console.WriteLine("Nhap so sinh vien toi da");
- int max = Int32.Parse(Console.ReadLine());
- SinhVien[] listSV = new SinhVien[0];
- ListSV alSV = new ListSV(listSV, max);
- SinhVien objSV = new SinhVien("",0,false);
- SinhVien.Input(objSV);
- alSV.Add(objSV);
- SinhVien.Input(objSV);
- alSV.Edit(objSV, 0);
- alSV.Show("all");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement