public ActionResult Edit([Bind(Include = "Id,Member_id,Name,standard,room_cup,A_year")] student_data student_data) { if (ModelState.IsValid) { db.Entry(student_data).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student_data)); }
// populateStruct function - amended to include programme_title and programme_code parameters. // takes an uninitialized struct and populates each field based on parameters inputted static void populateStruct(out student_data student, string fname, string surname, int id_number, string programme_title, string programme_code) { // Sets the relevant data field in relation to parameter input student.forename = fname; student.surname = surname; student.id_number = id_number; student.averageGrade = 0.0F; student.programme_title = programme_title; student.programme_code = programme_code; }
// prints the student data static void printStudent(student_data student) { Console.WriteLine("Name: " + student.forename + " " + student.surname); Console.WriteLine("ID: " + student.id_number); Console.WriteLine("Av grade: " + student.averageGrade); Console.WriteLine("Grade: " + student.grade); // outputs the student's grade Console.WriteLine(); }
public ActionResult Create([Bind(Include = "Id,Member_id,Name,standard,room_cup,A_year")] student_data student_data) { if (ModelState.IsValid) { db.student_data.Add(student_data); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student_data)); }
// Populate struct function which initialises a given student_data object with data passed by the parameters static void populateStruct(out student_data student, string fname, string surname, int id_number, module_data[] mods, string grade) { student.forename = fname; // sets first name student.surname = surname; // sets surname student.id_number = id_number; // sets id number student.averageGrade = 0.0F; // sets average grade - 0.0 to begin with student.modules = mods; // sets the modules student.grade = grade; // sets the student's grade }
// calcuate average function that takes in a reference to a currently existing stuent_data object // assigns the average to the averagegrade field within the student_data object static void calculateAverage(ref student_data student) { float average = 0.0F; // average variable to store final calculation foreach (module_data m in student.modules) //for each loop that cycles through each module within the current student object { average += m.score; // adds up the scores per module } // Assign average to current student student.averageGrade = (average /= student.modules.Length); }
static void Main(string[] args) { student_data[] students = new student_data[4]; populateStruct(out students[0], "Mark", "Anderson", 1, 75.5f); populateStruct(out students[1], "John", "Smith", 2, 64.0f); populateStruct(out students[2], "Tom", "Jones", 3, 80.0f); populateStruct(out students[3], "Ewan", "Evans", 4, 62.0f); printAllStudents(students); Console.WriteLine("Press a key to continue"); Console.ReadKey(); }
// Program entry point static void Main(string[] args) { // Allocate a 4 element student_data array student_data[] students = new student_data[4]; // Populate each element with information on each student populateStruct(out students[0], "Mark", "Anderson", 1, "BSc (Hons) Computing", "G401"); populateStruct(out students[1], "Ardhendu", "Behera", 2, "BSc (Hons) Web Design and Development", "W4D7"); populateStruct(out students[2], "Tom", "Jones", 3, "BSc (Hons) Software Engineering", "II33"); populateStruct(out students[3], "Ewan", "Evans", 4, "BSc (Hons) Computing Games Programming", "I610"); // Print every student's data out to the console printAllStudent(ref students); }
// GET: student_data_detail/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } student_data student_data = db.student_data.Find(id); if (student_data == null) { return(HttpNotFound()); } return(View(student_data)); }
// Notice that a reference to the struct is being passed in along with a reference to the module list array static void populateStruct(out student_data student, string fname, string surname, int id_number, module_data[] modules_list) { student.forename = fname; student.surname = surname; student.id_number = id_number; student.averageGrade = 0.0f; student.modules = modules_list; // Calculate average grade int total = 0; foreach (module_data module in student.modules) { total += module.module_score; // Calculate sum of all grades } student.averageGrade = (float)total / 6.0f; }
static void Main(string[] args) { // Create student array student_data[] students = new student_data[2]; // Create module arrays module_data[] student1mods = new module_data[6]; module_data[] student2mods = new module_data[6]; // Allocate modules // Student 1 populateModule(out student1mods[0], "CIS2147", "Programming: Theroy to Practice", 96); populateModule(out student1mods[1], "CIS2150", "Game Engines", 70); populateModule(out student1mods[2], "CIS2162", "Employability", 84); populateModule(out student1mods[3], "CIS1111", "Programming Concepts", 95); populateModule(out student1mods[4], "CIS1110", "Web Design & Development", 73); populateModule(out student1mods[5], "CIS1109", "Computer Architecture & Networks", 77); // Student 2 populateModule(out student2mods[0], "CIS2147", "Programming: Theroy to Practice", 66); populateModule(out student2mods[1], "CIS2150", "Game Engines", 33); populateModule(out student2mods[2], "CIS2162", "Employability", 55); populateModule(out student2mods[3], "CIS1111", "Programming Concepts", 65); populateModule(out student2mods[4], "CIS1110", "Web Design & Development", 73); populateModule(out student2mods[5], "CIS1109", "Computer Architecture & Networks", 37); // Create student and allocate module populateStruct(out students[0], "Jordan", "McCann", 1, student1mods, null); // Left as null as grade is unknown populateStruct(out students[1], "Niall", "Davis", 2, student2mods, null); // Left as null as grade is unknown at this stage // Calculate student averages calculateAverage(ref students[0]); calculateAverage(ref students[1]); // Calculate student grades calculateGrade(ref students[0]); calculateGrade(ref students[1]); // Print student information to the console printStudent(students[0]); printStudent(students[1]); }
public string dataTableToStudentObjects(DataTable table) { int i = 0; int j = 0; Students students = new Students(); foreach (DataColumn column in table.Columns) { RenameQuestionAndCIDColumns(table, column, j); j++; } if (table.Rows[0].ItemArray.Length - 4 <= 0) { return(""); } else { foreach (DataRow row in table.Rows) { Array questionColumns = table.Columns.Cast <DataColumn>() .Select(x => x.ColumnName).Where(n => n.Contains("Question") && n.Contains("hash")).ToArray(); string CIDColumn = table.Columns.Cast <DataColumn>() .Select(x => x.ColumnName).First(n => n.Contains("CID")); student_data instance = new student_data(); students.StudentList.Add(instance); students.StudentList[i].Username = row["Username"].ToString(); students.StudentList[i].LastName = row["Last Name"].ToString(); students.StudentList[i].FirstName = row["First Name"].ToString(); students.StudentList[i].CID = row[row.Table.Columns[CIDColumn].Ordinal + 1].ToString(); SetStudentQuestionSubmissions(questionColumns, row, students, i); i += 1; } string serialisedData = JsonConvert.SerializeObject(students.StudentList); return(serialisedData); } }
static void Main(string[] args) { var rand = new Random(); student_data[] students = new student_data[6]; // Six students module_data[] modules; // = new module_data[6]; // Six modules per student // Arrays holding module codes and titles string[] codes = { "CIS2100", "CIS2117", "CIS2109", "CIS2118", "CIS2110", "BUS2005", "CIS2136", "CIS2116", "CIS2113", "CIS2135", "CIS2134" }; string[] titles = { "Intro to Databases", "Programming Languages", "OO Programming", "Prog Lang: Inspire Creativity", "Physical COmputing", "Graduate Enterprise", "Work Related Learning", "Team Project", "Games Engines", "Digital Design & Production", "Comp Graphics & Modelling" }; // Student names string[] fnames = { "Walter", "Bruce", "Clark", "Steve", "Jon", "Jeffrey" }; string[] snames = { "White", "Wayne", "Kent", "Rogers", "Osterman", "Sinclair" }; for (int t = 0; t < students.Length; t++) // Populate students { modules = new module_data[6]; // Set asside module space for this student and point modules at it for (int u = 0; u < modules.Length; u++) // Populate modules array { int mod = rand.Next(0, codes.Length); // Generate a random value to represent the module int score = rand.Next(0, 101); // maximum random value is exclusive so value should be in range 0 - 100 populateModules(out modules[u], codes[mod], titles[mod], score); // Populate module data } populateStruct(out students[t], fnames[t], snames[t], t + 1, modules); // Populate this student's data } printAllStudents(students); // Display all students' data to console Console.WriteLine("Press a key to continue"); Console.ReadKey(); }
void SendStudent() { student_data stu = new student_data(); stu.age = 20; stu.name = "阿斯顿"; stu.sex = false; stu.contry = "中国"; stu.grade = 1; try { //涉及格式转换,需要用到流,将二进制序列化到流中 using (MemoryStream ms = new MemoryStream()) { //使用ProtoBuf工具的序列化方法 ProtoBuf.Serializer.Serialize <student_data>(ms, stu); //定义二级制数组,保存序列化后的结果 byte[] result = new byte[ms.Length]; //将流的位置设为0,起始点 ms.Position = 0; //将流中的内容读取到二进制数组中 ms.Read(result, 0, result.Length); for (int i = 0; i < result.Length; i++) { Console.Write(result[i] + "\t"); } byte[] length = BitConverter.GetBytes(result.Length); Array.Reverse(length); byte[] temp = new byte[result.Length + 4]; for (int i = 0; i < temp.Length; i++) { if (i < 4) { temp[i] = length[i]; } else { temp[i] = result[i - 4]; } } socketClient.Send(temp); Console.ReadLine(); } } catch (Exception ex) { } //Student student = new Student("李磊", 20, false, "中国", 1); //byte[] buffer = Protobuffer(student); //socketClient.Send(buffer); //Console.ReadLine(); }