برنامه ای بنویسید که شامل موارد زیر باشد:
1)کلاس student با فیلدهای نام ،نام خانودگی،شماره دانشجویی،ترم ورودی
2)متدهای لازم جهت تنظیم و دریافت مقادیر فیلدهای کلاس student
3)ایجاد للیستی از دانشجویان
4)پیاده سازی findstudentکه با دریافت شماره دانشجویی اطلاعات دانشجوی مورد نظر را در صورت وجود برگرداند.
- List studentlist = new List();
- public Student FindStudent(string stuCode)
- {
- Student result = null;
- foreach(Student stu in studentlist)
- {
- if (stu.GetStudentCode() == stuCode)
- {
- result = stu;
- break;
- }
- return result;
- }
- private void btnAddStudent_Click(object sender, EventArgs e)
- {
- if (FindStudent(tbxstucode.Text) != null)
- {
- MessageBox.Show(
- "stu already exist!"
- , "eror"
- , MessageBoxButtons.OKCancel,
- MessageBoxIcon.Error
- );
- return;
- }
- Student stu = new Student(
- tbxfname.Text
- , tbxlname.Text
- , tbxstucode.Text,
- Int32.Parse(tbxentryterm.Text)
- );
- studentlist.Add(stu);
- lblcount.Text = $"#stu={studentlist.Count}";
----------------------------------------------------------------------------------------
- public class Student
- {
- string _firstName;
- string _lastName;
- string _studentCode;
- int _entryTerm;
- public Student()
- {}
- _firstName = string.Empty;
- _lastName = string.Empty;
- _studentCode = string.Empty;
- _entryTerm = 0;
- public Student(
- string fname,
- string lname,
- string stuCode,
- int entryTerm
- )
- {
- _firstName = fname;
- _lastName = lname;
- _studentCode = stuCode;
- _entryTerm = entryTerm;
- }
- public string GetFirstName() => _firstName;
- public string GetLastName() => _lastName;
- public string GetStudentCode() => _studentCode;
- public int GetEntryTerm() => _entryTerm;
برچسب:
نویسنده: بهنام شجاعی
تاريخ: چهارشنبه
11 فروردين
1400 ساعت: 18:05