|
一、問題提出: 1.創(chuàng)建相應的成員變量保存學生基本信息。 2.創(chuàng)建相應屬性和索引以實現(xiàn)對成員變量訪問的封裝。 3.創(chuàng)建相應的方法以實現(xiàn)對學生基本信息的管理。 4.創(chuàng)建相應的方法以實現(xiàn)對學生成績的管理。 5.派生出小學生,中學生,大學生等子類。 二、問題分析: 1、添加基類Student,定義私有成員變量姓名,性別,號,民族,住址,英語,數(shù)學,語文等學生的基本信息并創(chuàng)建相應的屬性實現(xiàn)對成員變量訪問的封裝。 2、分別定義派生類Pupil,CollegeStudenr,Middleschoolstudent,并使用base關鍵字調(diào)用基類構造函數(shù)。 3、添加Option類實現(xiàn)對學生信息進行的一系列操作。 4、添加Manager類實現(xiàn)管理用戶登陸。 三、程序代碼: Student.cs: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StudentInformation public class Student private string studentType; public string StudentType getreturn studentType; setstudentType=value; private string studentName; public string StudentName get return studentName; set studentName = value; private string studentSex; public string StudentSex get return studentSex; set studentSex = value; private string studentNumber; public string StudentNumber get return studentNumber; set studentNumber = value; private string studentNation; public string StudentNation get return studentNation; set studentNation = value; private string studentAddress; public string StudentAddress get return studentAddress; set studentAddress = value; private string englishScore; public string EnglishScore get return englishScore; set englishScore = value; private string mathScore; public string MathScore get return mathScore; set mathScore = value; private string chineseScore; public string ChineseScore get return chineseScore; set chineseScore = value; public Student(string type,string name,string sex,string number,string nation,string address,string english,string math,string chinese) this.studentType=type; this.studentName=name; this.studentSex=sex; this.studentNumber=number; this.studentNation=nation; this.studentAddress=address; this.englishScore=english; this.mathScore=math; this.chineseScore=chinese; public void showstudent() Console.WriteLine("該同學的基本信息為:"); Console.WriteLine("學生類型:" studentType); Console.WriteLine("姓名:" studentName); Console.WriteLine("性別:" studentSex); Console.WriteLine("學號:" studentNumber); Console.WriteLine("住址:" studentAddress); Console.WriteLine("英語:" englishScore); Console.WriteLine("數(shù)學:" mathScore); Console.WriteLine("語文:" chineseScore); Option.cs: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StudentInformation public class Option : Student int flag; public Option(string Type, string Name, string Sex, string Number, string Nation, string Address, string English, string Math, string Chinese) : base(Type, Name, Sex, Number, Nation, Address, English, Math, Chinese) Console.WriteLine("對學生信息進行相關的操作"); public void input() Console.WriteLine("請輸入一系列的相關信息"); StudentName = Console.ReadLine(); StudentSex = Console.ReadLine(); StudentNumber = Console.ReadLine(); StudentNation = Console.ReadLine(); StudentAddress = Console.ReadLine(); EnglishScore = Console.ReadLine(); MathScore = Console.ReadLine(); ChineseScore = Console.ReadLine(); public void search_number(string numm) flag = 0; if (StudentNumber == numm) Console.WriteLine(StudentNumber "被找到"); flag = 1; public void search_name(string nname) flag = 0; if (StudentName == nname) Console.WriteLine(StudentName "被找到"); flag = 1; public void input_englishScore() Console.WriteLine("請重新輸入英語成績"); string englishScore = Console.ReadLine(); this.EnglishScore = englishScore; public void input_chineseScore() Console.WriteLine("請重新輸入語文成績"); string chineseScore = Console.ReadLine(); this.ChineseScore = chineseScore; public void input_mathScore() Console.WriteLine("請重新輸入數(shù)學成績"); string mathScore = Console.ReadLine(); this.MathScore = mathScore; public int getflag() return flag; Middleschoolstudent.cs: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StudentInformation public class Middleschoolstudent:Option public Middleschoolstudent(string Type, string Name, string Sex, string Number, string Nation, string Address, string English, string Math, string Chinese) : base(Type, Name, Sex, Number, Nation, Address, English, Math, Chinese) StudentType = "中學生"; Program.cs: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StudentInformation class Program int number, judge = 0, flag, choose = 0; static void Main(string[] args) int i, j, n = 0, t = 0, k = 0; string find_name, find_number, delet_number, judgestring; Console.WriteLine("***********歡迎使用通用學生管理系統(tǒng) *************"); Console.WriteLine("請輸入用戶名:"); string username = Console.ReadLine(); manager ma = new manager(); ma.Next = username; if (ma.load()) Console.WriteLine(" ************************ "); Console.WriteLine(" 通用學生信息管理系統(tǒng) "); Console.WriteLine(" ************************ "); Console.WriteLine(" 1.錄入基本信息 "); Console.WriteLine(" 2.刪除信息 "); Console.WriteLine(" 3.修改基本信息 "); Console.WriteLine(" 4.查詢基本信息 "); Console.WriteLine(" 5.打印信息 "); Console.WriteLine(" ************************ "); Console.WriteLine(" 歡迎使用 "); Console.WriteLine(" ************************ "); Console.WriteLine(""); Console.WriteLine("請選擇學生類型:"); Console.WriteLine("1.大學生"); Console.WriteLine("2.中學生"); Console.WriteLine("3.小學生"); CollegeStudent[] g = new CollegeStudent[100]; Middleschoolstudent[] m = new Middleschoolstudent[100]; Pupil[] s = new Pupil[100]; int choose = int.Parse(Console.ReadLine()); switch (choose) case 1: do Console.WriteLine("請輸入你要選擇執(zhí)行的功能:"); int number1 = int.Parse(Console.ReadLine()); int judge = 0; switch (number1) case 1: i = 0; do g[i] = new CollegeStudent("0", "0", "0", "0", "0", "0", "0", "0", "0"); g[i].input(); i ; n ; Console.WriteLine(" 是否繼續(xù) 錄入檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); Console.WriteLine("共錄入" n "人"); break; //錄入 case 2: do t = 0; judge = 0; Console.WriteLine("請輸入您要 刪除的學號"); delet_number = Console.ReadLine(); for (i = 0; i g[i].search_number(delet_number); if (g[i].getflag() == 1) for (j = i; j g[j] = g[j 1]; n--; t ; Console.WriteLine("正 在刪除"); Console.WriteLine("刪 除成功"); if (t == 0) Console.WriteLine("您刪除 的學生的學生學號不存在"); Console.WriteLine("是否繼續(xù)刪 除是1否2"); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; //刪除 case 3: Console.WriteLine(" **************************************** "); Console.WriteLine(" 通用 學生信息管理系統(tǒng)修改 "); Console.WriteLine(" **************************************** "); Console.WriteLine(" 1.英語 "); Console.WriteLine(" 2.數(shù)學 "); Console.WriteLine(" 3.語文 "); do Console.WriteLine("請輸入你要選擇執(zhí)行的功能:"); int number2 = int.Parse(Console.ReadLine()); switch (number2) case 1: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的英語成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i g[i].search_number(find_number); if (g[i].getflag() == 1) g[i].input_englishScore(); t ; if (t == 0) Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)錄入檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 2: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的數(shù)學成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i g[i].search_number(find_number); if (g[i].getflag() == 1) g[i].input_mathScore(); t ; if (t == 0) Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 3: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的語文成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i g[i].search_number(find_number); if (g[i].getflag() == 1) g[i].input_chineseScore(); t ; if (t == 0) Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; //修改 case 4: Console.WriteLine(" **************************************** "); Console.WriteLine(" 通用學生信息管理查詢 "); Console.WriteLine(" **************************************** "); Console.WriteLine(" 1.學號 "); Console.WriteLine(" 2.姓名 "); do Console.WriteLine("請輸入你要選擇執(zhí)行的功能:"); int number2 = int.Parse(Console.ReadLine()); switch (number2) case 1: do t = 0; judge = 0; Console.WriteLine("請輸入你要查找的學生的學號:"); Console.ReadLine(); for (i = 0; i if (g[i].getflag() == 1) g[i].showstudent(); t ; if (t == 0) Console.WriteLine("您要找的學號不存在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 2: do t = 0; judge = 0; Console.WriteLine("請輸入你要查找的學生的姓名:"); find_name = Console.ReadLine(); for (i = 0; i if (g[i].getflag() == 1) g[i].showstudent(); if (t == 0) Console.WriteLine("您要找的姓名不存在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; Console.WriteLine(" 是否繼續(xù)其他查詢方案檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 5: for (i = 0; i g[i].showstudent(); break; Console.WriteLine(" 是否繼續(xù)其他查詢方案檔案?是1.否2."); judgestring = Console.ReadLine(); while (judgestring == "1"); break; case 2: do Console.WriteLine("請輸入你要選擇執(zhí)行的功能: "); int number1 = int.Parse(Console.ReadLine()); int judge = 0; switch (number1) case 1: i = 0; do m[i] = new Middleschoolstudent("0", "0", "0", "0", "0", "0", "0", "0", "0"); m[i].input(); i ; n ; Console.WriteLine(" 是否繼續(xù) 錄入檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); Console.WriteLine("共錄入" n "人"); break; //錄入 case 2: t = 0; judge = 0; Console.WriteLine("請輸入您要刪除的學號"); delet_number = Console.ReadLine(); for (i = 0; i m[i].search_number(delet_number); if (m[i].getflag() == 1) for (j = i; j m[j] = m[j 1]; n--; t ; Console.WriteLine("正在刪除"); Console.WriteLine("刪除成功"); if (t == 0) Console.WriteLine("您刪除的學生的學生學號不存在"); Console.WriteLine("是否繼續(xù)刪除是1否2"); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; //刪除 case 3: Console.WriteLine(" *************************************** "); Console.WriteLine(" 通用學生信息管理修改 "); Console.WriteLine(" **************************************** "); Console.WriteLine(" 1.英語 "); Console.WriteLine(" 2.數(shù)學 "); Console.WriteLine(" 3.語文 "); do Console.WriteLine("請輸入你要選擇執(zhí)行的功能:"); int number2 = int.Parse(Console.ReadLine()); switch (number2) case 1: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的英語成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i m[i].search_number(find_number); if (m[i].getflag() == 1) m[i].input_englishScore(); if (t == 0) Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)錄入檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 2: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的數(shù)學成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; im[i].search_number(find_number); if (m[i].getflag() == 1) m[i].input_mathScore(); if (t == 0) Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 3: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的語文成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; im[i].search_number(find_number); if (m[i].getflag() == 1) m[i].input_chineseScore(); if (t == 0) Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; //修改 case 4: Console.WriteLine(" **************************************** "); Console.WriteLine(" 通用學生信息管理查詢 "); Console.WriteLine(" **************************************** "); Console.WriteLine(" 1.學號 "); Console.WriteLine(" 2. 姓名 "); do Console.WriteLine("請輸入你要選擇執(zhí)行的功能:"); int number2 = int.Parse(Console.ReadLine()); switch (number2) case 1: do t = 0; judge = 0; Console.WriteLine("請輸入你要查找的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i if (m[i].getflag() == 1) m[i].showstudent(); t ; if (t == 0) Console.WriteLine("您要找的學號不存在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 2: do t = 0; judge = 0; Console.WriteLine("請輸入你要查找的學生的姓名:"); find_name = Console.ReadLine(); for (i = 0; i if (m[i].getflag() == 1) m[i].showstudent(); t ; if (t == 0) Console.WriteLine("您要找的姓名不存在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; Console.WriteLine(" 是否繼續(xù) 其他查詢方案檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 5: for (i = 0; i m[i].showstudent(); break; Console.WriteLine(" 是否繼續(xù)其他查詢方案檔 案?是1.否2."); judgestring = Console.ReadLine(); while (judgestring == "1"); break; case 3: do Console.WriteLine("請輸入你要選擇執(zhí)行的功能:"); int number1 = int.Parse(Console.ReadLine()); int judge = 0; switch (number1) case 1: i = 0; do s[i] = new Pupil("0", "0", "0", "0", "0", "0", "0", "0", "0"); s[i].input(); i ; n ; Console.WriteLine(" 是否繼續(xù) 錄入檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); Console.WriteLine("共錄入" n "人"); break; //錄入 case 2: do t = 0; judge = 0; Console.WriteLine("請輸入您要刪除的學號"); delet_number = Console.ReadLine(); for (i = 0; i s[i].search_number(delet_number); if (s[i].getflag() == 1) for (j = i; j s[j] = s[j 1]; n--; t ; Console.WriteLine("正在刪除"); Console.WriteLine("刪除成功"); if (t == 0) Console.WriteLine("您刪除的學生的學生學號不存在"); Console.WriteLine("是否繼續(xù)刪除是1否2"); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; //刪除 case 3: Console.WriteLine(" ***************************************** "); Console.WriteLine(" 通用學生信息管理修改 "); Console.WriteLine(" ***************************************** "); Console.WriteLine(" 1.英語 "); Console.WriteLine(" 2.數(shù)學 "); Console.WriteLine(" 3.語文 "); do Console.WriteLine("請輸入你要選擇執(zhí)行的功能:"); int number2 = int.Parse(Console.ReadLine()); switch (number2) case 1: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的英語成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i s[i].search_number(find_number); if (s[i].getflag() == 1) s[i].input_englishScore(); t ; Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)錄入檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 2: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的數(shù)學成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i s[i].search_number(find_number); if (s[i].getflag() == 1) s[i].input_mathScore(); t ; if (t == 0) Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); 1); break; case 3: do t = 0; judge = 0; Console.WriteLine("請輸入你要修改的語文成績的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i s[i].search_number(find_number); if (s[i].getflag() == 1) s[i].input_chineseScore(); t ; if (t == 0) Console.WriteLine("您查找的人不在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; Console.WriteLine(" 是否繼續(xù) 檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; //修改 case 4: Console.WriteLine(" **************************************** "); Console.WriteLine(" 通用學生信息管理查詢 "); Console.WriteLine(" ***************************************** "); Console.WriteLine(" 1.學號 "); Console.WriteLine(" 2.姓名 "); do Console.WriteLine("請輸入你要選擇執(zhí)行的功能:"); int number2 = int.Parse(Console.ReadLine()); switch (number2) case 1: do t = 0; judge = 0; Console.WriteLine("請輸入你要查找的學生的學號:"); find_number = Console.ReadLine(); for (i = 0; i if (s[i].getflag() == 1) s[i].showstudent(); t ; if (t == 0) Console.WriteLine("您要找的學號不存在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 2: do t = 0; judge = 0; Console.WriteLine("請輸入你要查找的學生的姓名:"); find_name = Console.ReadLine(); for (i = 0; i if (s[i].getflag() == 1) s[i].showstudent(); t ; if (t == 0) Console.WriteLine("您要找的姓名不存在"); Console.WriteLine(" 是否繼續(xù)檔案?是1.否2."); int.Parse(Console.ReadLine()); while (judge == 1); break; Console.WriteLine(" 是否繼續(xù)其他查詢方案檔案?是1.否2."); judge = int.Parse(Console.ReadLine()); while (judge == 1); break; case 5: for (i = 0; i s[i].showstudent(); break; Console.WriteLine(" 是否繼續(xù)其他查詢方案檔案?是1.否2."); judgestring = Console.ReadLine(); while (judgestring == "1"); break;
信息發(fā)布:廣州名易軟件有限公司 http://m.jetlc.com
|