Operational requirements
Student Achievement Management (1)class Student { int id; string name; int score; Student next; } (2) Using linked list or system List class. Array implementation is also possible (up to 100 records)? (3) Increase: Check no duplication of student numbers (4) Delete: If an integer is input, the record to be deleted is located according to the student number. If you enter a string, locate the record to be deleted by name (abbreviated) Tip: Read the temporary variable into the string first, check whether it contains a number, and you will know whether it is a school number or a name. (5) Change: If an integer is input, the record to be modified is located according to the student number. If you enter a string, locate the record to be modified by name (abbreviated) (4), (5) If more than one record is caused by the abbreviation of the name, the execution is refused and an error is reported. When modifying, do the following actions one by one: (a) Display field names and current values (b) Enter a new value for the field. If you just hit Enter without entering a new value, the field will not be modified and the current value will remain unchanged. Tip: First read in the temporary variable according to the string, check whether its length is 0, then you know you need not overwrite the original value. (6) Check: Input format is: field name relational operator query value For example, score > 80, query score greater than 80. Equivalent to an SQL query operation: select * from Student where score > 80 If you query by string type field (name), the query value can be abbreviated. (7) Deposit: Inventory (8) Take: Reduce
Main Class Program
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace classManger { class Program { static void Main(string[] args) { ClassList a = new ClassList(); String i = ""; Boolean t = true; Console.WriteLine("-----------------------Welcome to Student Achievement Management System 1.0.0 edition-------------------->"); Console.WriteLine(); Console.WriteLine(" || || |||||||||| || || || ||"); Console.WriteLine(" || || || || || || ||"); Console.WriteLine(" |||||||||| ||||||||| || || || ||"); Console.WriteLine(" || || || || || || ||"); Console.WriteLine(" || || |||||||||| ||||||||||| ||||||||||| || ||"); Console.WriteLine(); Console.WriteLine("-------------------------------------------------------------------------->"); Console.WriteLine(); while (t) { Console.WriteLine("----------Operator----------->"); Console.WriteLine("\t1-------->Adding students"); Console.WriteLine("\t2-------->Delete students"); Console.WriteLine("\t3-------->Editing Student Information"); Console.WriteLine("\t4-------->Inquire about Student Information"); Console.WriteLine("\t5-------->Print Student Information"); Console.WriteLine("\t6-------->Save"); Console.WriteLine("\t7-------->open"); Console.WriteLine("\t8-------->Sign out"); Console.WriteLine("--------------------------->"); i = Console.ReadLine(); while (!isNumber(i)){ Console.WriteLine("Please enter the correct command!"); i =Console.ReadLine(); } switch (int.Parse(i)) { case 1: a.add(); break; case 2: a.delete(); break; case 3: a.edit(); break; case 4: a.find(); break; case 5: a.print(); break; case 6: a.Write(); break; case 7: a.Read(); break; case 8: t = false; break; } } } protected static bool isNumber(string message) {/* * Determine whether the incoming string is a number? * If true is returned or false is returned */ try { int.Parse(message); return true; } catch { return false; } } } }
Student category
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace classManger { class Student { /** * * Student category * Student id * Name name * Achievement score */ private int id; private String name; int score; //Student next; public Student (){ } public Student(int i,String n,int s) { id = i; name = n; score = s; } public int Id { get { return id; } set { id = value; } } public String Name { get { return name; } set { name = value; } } public int Score { get { return score; } set { score = value; } } //internal student next //{ // get { return next; } // set { next = value; } //} public override string ToString() {/* * Rewrite ToString * */ return "ID: " + id + " Full name: " + name+" achievement"+score; } } }
Link list operation
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using System.IO; namespace classManger { class ClassList {/* * Linked list operation class * */ List<Student> s = new List<Student>(); int count = 0; public ClassList() { //s.Add(new Student(201502, "obama", 80)); //s.Add(new Student(201503, "bush", 90)); } public void add() {/* * Adding students * Check if the number is in conflict */ String i = ""; String n = ""; String c = ""; Console.WriteLine("Please enter your student number:"); i = Console.ReadLine(); while (!isNumberic(i)) { Console.WriteLine("Please enter the correct number (pure number):"); i = Console.ReadLine(); } Console.WriteLine("Please enter your name:"); n = Console.ReadLine(); Console.WriteLine("Please enter the results:"); c = Console.ReadLine(); while (!isNumberic(c)) { Console.WriteLine("Please enter the correct score (pure number):"); c = Console.ReadLine(); } while (true) { if (count == 0) //inspect { s.Add(new Student(int.Parse(i), n, int.Parse(c))); count++; Console.WriteLine("------Add success!"); break; } else if (tooId(int.Parse(i)) == -1) //Check if the id is duplicated and if it is the last student information? { Console.WriteLine("------Repeat the number! Please re-enter your student number:"); i = Console.ReadLine(); } else { s.Add(new Student(int.Parse(i), n, int.Parse(c))); count++; Console.WriteLine("------Add success!"); break; } } } public void delete() {/* * Delete Student Classes * Check that if stu contains numbers, delete them by school number or by name */ int index = 0; String stu = ""; Console.WriteLine("Please enter the student information to be deleted"); stu = Console.ReadLine(); if (isNumberic(stu)) {/* * Judge stu if it is a number, then locate it according to the student number * First of all, judge whether the student number exists or not. */ index = fID(stu); if (index == -1) { Console.WriteLine("Error: No student number found"); } else { Console.WriteLine(s[index].ToString()); s.Remove(s[index]); count--; Console.WriteLine("Successful deletion"); } } else { index = fName(stu); if (index == -1) { Console.WriteLine("Error: Name not found"); }else if(index == -2) { Console.WriteLine("Error: Match multiple records!"); } else { Console.WriteLine(s[index].ToString()); s.Remove(s[index]); count--; Console.WriteLine("Successful deletion"); } } } public void edit() {/* * Modifying Student Data * If an integer is input, the record to be modified is located according to the student number. * If you enter a string, locate the record to be modified by name (abbreviated) */ String stu = ""; int index = 0; Console.WriteLine("Please enter the student information to be modified"); stu = Console.ReadLine(); String id = "0"; String name = "0"; String score = "0"; if (isNumberic(stu)) { index = fID(stu); if (index == -1) { Console.WriteLine("Error: No student number found"); } else { Console.WriteLine("The data you want to modify" + s[index].ToString()); Console.WriteLine("Please enter your student number:"); id = Console.ReadLine(); if (id == "") id = Convert.ToString(s[index].Id); Console.WriteLine("Please enter your name:"); name = Console.ReadLine(); if (name == "") name = s[index].Name; Console.WriteLine("Please enter the results:"); score = Console.ReadLine(); if (score == "") score = Convert.ToString(s[index].Score); //Console.WriteLine(id+" "+name+" "+score); while (true) { if (tooId(int.Parse(id)) == -1 && id != Convert.ToString(s[index].Id)) { Console.WriteLine("The student number is repeated. Please re-enter the student number:"); id = Console.ReadLine(); if (id == "") id = Convert.ToString(s[index].Id); } else { s[index].Id = int.Parse(id); s[index].Name = name; s[index].Score = int.Parse(score); Console.WriteLine("Successful revision"); break; } } } } else { index = fName(stu); if (index == -1) { Console.WriteLine("Error: Name not found"); } else if (index == -2) { Console.WriteLine("Error: Match multiple records!"); } else { Console.WriteLine("The data you want to modify" + s[index].ToString()); Console.WriteLine("Please enter your student number:"); id = Console.ReadLine(); if (id == "") id = Convert.ToString(s[index].Id); Console.WriteLine("Please enter your name:"); name = Console.ReadLine(); if (name == "") name = s[index].Name; Console.WriteLine("Please enter the results:"); score = Console.ReadLine(); if (score == "") score = Convert.ToString(s[index].Score); while (true) { if (tooId(int.Parse(id)) == -1 && id != Convert.ToString(s[index].Id)) { Console.WriteLine("The student number is repeated. Please re-enter the student number:"); id = Console.ReadLine(); if (id == "") id = Convert.ToString(s[index].Id); } else { s[index].Id = int.Parse(id); s[index].Name = name; s[index].Score = int.Parse(score); Console.WriteLine("Successful revision"); break; } } } } } public void find() {/* * Query class * Check: Input format is: field name relational operator query value * For example, score > 80, query score greater than 80. Equivalent to an SQL query operation: select * from Student where score > 80 * If you query by string type field (name), the query value can be abbreviated. */ String sql = ""; Console.WriteLine("Please enter a query statement---->for example score > 80,Those with query scores greater than 80"); sql = Console.ReadLine(); if (sql == "") { sql = " 1 "; } String where = getWhereSql(sql); String ro = getROSql(sql); String value = getValueSql(sql); switch (ro){ case ">": sqla(where,value); break; case "<": sqlb(where, value); break; case"=": sqlc(where, value); break; case">=": sqle(where, value); break; case"<=": sqld(where, value); break; default: Console.WriteLine("The query statement is incorrect! For example, score > 80,Those with query scores greater than 80"); break; } } public void print() {/* * Print out all the students */ if (count == 0) Console.WriteLine("No data!"); else for (int i = 0; i < count;i++ ) Console.WriteLine(s[i].ToString()); } public void print(int i) {/* *Print Student Information No. 1 */ if (i<count) Console.WriteLine(s[i-1].ToString()); else Console.WriteLine("No data!"); } protected bool isNumberic(string message) {/* * Determine whether the incoming string is a number? * If true is returned or false is returned */ try { int.Parse(message); return true; } catch { return false; } } public int tooId(int id) {/* * Check if the number is repeated * */ for (int i = 0; i <count; i++) { if (s[i].Id == id) return -1; } return id; } public int fID(String id) {/* * Check if the student number exists * */ int rid = -1; Boolean a = false; for (int i = 0; i < count; i++) { if (Convert.ToString(s[i].Id) == id) { a = true; rid = i; } } if (a) return rid; else return -1; } public int fName(String name) {/* * Name Abbreviation Matching */ int number = 0; int rindex = -1; for (int j = 0;j<count;j++) { for (int m=0,n=0; m < s[j].Name.Length; m++) { if (s[j].Name[m] == name[n]) n++; if (n == name.Length) { rindex = j; number++; break; } } } if (number == 1) return rindex; else if (number > 1) return -2; else return -1; } public String getWhereSql(String sql) {/* * Return the condition in sql */ String[] rsql = sql.Split(' '); ; return rsql[0]; } public String getROSql(String sql) {/* * Returns the relational operator in sql */ String[] rsql = sql.Split(' '); ; return rsql[1]; } public string getValueSql(string sql) {/* * Returns the query value in sql */ String[] rsql = sql.Split(' '); ; return rsql[2]; } /* * * Query method * */ public void sqla(String In,String value) {/* * > */ switch(In){ case "id": Console.WriteLine("Error: id Please use an equal sign.(=)"); break; case "name": Console.WriteLine("Error: Names should be equal to symbols(=)"); break; case "score": Console.WriteLine("Query results-->"); for (int i = 0; i < count; i++) { if (s[i].Score > int.Parse(value)) Console.WriteLine(s[i].ToString()); } break; default: Console.WriteLine("The query statement is incorrect! For example, score > 80,Those with query scores greater than 80"); break; } } public void sqlb(String In, String value) {/* * < */ switch (In) { case "id": Console.WriteLine("Error: id Please use an equal sign.(=)"); break; case "name": Console.WriteLine("Error: Names should be equal to symbols(=)"); break; case "score": Console.WriteLine("Query results-->"); for (int i = 0; i < count; i++) { if (s[i].Score < int.Parse(value)) Console.WriteLine(s[i].ToString()); } break; default: Console.WriteLine("The query statement is incorrect! For example, score > 80,Those with query scores greater than 80"); break; } } public void sqlc(String In, String value) {/* * = */ switch (In) { case "id": Console.WriteLine("Query results-->"); for (int i = 0; i < count; i++) { if (s[i].Id == int.Parse(value)) Console.WriteLine(s[i].ToString()); } break; case "name": Console.WriteLine("Query results-->"); for (int i = 0; i < count; i++) { if (s[i].Name == value) Console.WriteLine(s[i].ToString()); } break; case "score": Console.WriteLine("Query results-->"); for (int i = 0; i < count; i++) { if (s[i].Score == int.Parse(value)) Console.WriteLine(s[i].ToString()); } break; default: Console.WriteLine("The query statement is incorrect! For example, score > 80,Those with query scores greater than 80"); break; } } public void sqld(String In, String value) {/* * <= */ switch (In) { case "id": Console.WriteLine("Error: id Please use an equal sign.(=)"); break; case "name": Console.WriteLine("Error: Names should be equal to symbols(=)"); break; case "score": Console.WriteLine("Query results-->"); for (int i = 0; i < count; i++) { if (s[i].Score <= int.Parse(value)) Console.WriteLine(s[i].ToString()); } break; default: Console.WriteLine("The query statement is incorrect! For example, score > 80,Those with query scores greater than 80"); break; } } public void sqle(String In, String value) {/* * <= */ switch (In) { case "id": Console.WriteLine("Error: id Please use an equal sign.(=)"); break; case "name": Console.WriteLine("Error: Names should be equal to symbols(=)"); break; case "score": Console.WriteLine("Query results-->"); for (int i = 0; i < count; i++) { if (s[i].Score >= int.Parse(value)) Console.WriteLine(s[i].ToString()); } break; default: Console.WriteLine("The query statement is incorrect! For example, score > 80,Those with query scores greater than 80"); break; } } /* * * Query method * */ public void Write() {/* * File Save * */ Console.WriteLine("Please enter the file storage path-->"); Console.WriteLine(@"for example:Default path D:\\classScore.txt"); string fPath = ""; string output = ""; FileStream file = null; StreamWriter sw = null; fPath = Console.ReadLine(); if (fPath == "") { fPath = "D:\\classScore.txt"; } file = new FileStream(fPath, FileMode.Create); sw = new StreamWriter(file); for (int i = 0; i < count; i++) { output = s[i].Id +" "+s[i].Name +" "+s[i].Score + "\r\n"; sw.Write(output); sw.Flush(); } Console.WriteLine("Save finished! common" + s.Count + "Article Information"); sw.Close(); file.Close(); } public void Read() {/* * File Reading * */ Console.WriteLine("Please enter the file read path-->"); Console.WriteLine(@"for example:Default path D:\\classScore.txt"); string fPath = ""; string input = null; StreamReader sr = null; fPath = Console.ReadLine(); if (fPath == "") { fPath = "D:\\classScore.txt"; } sr = new StreamReader(fPath, Encoding.UTF8); while ((input = sr.ReadLine()) != null) { string[] arr = input.Split(' ');//String separation s.Add(new Student(Int32.Parse(arr[0]), arr[1], Int32.Parse(arr[2]))); count++; } Console.WriteLine("Read completed! common" + s.Count + "Article Information"); sr.Close(); } } }