the variables defined by int can only be used for shaping data, and the variables defined by string can only put string data, which are built-in data types;struct{},class(classes) are user-defined data types that can be placed in any type of data. Defining a variable with a data type is like creating a variable with a template specification so that it cannot store data arbitrarily, such as a variable of type int cannot store data of type string; all data types (int,string, structs come out of the student) like a variety of templates, the struct-student is our own creation of the data type template. Class templates can write functions, so more advanced than struct templates, class-defined variables we call objects. Object-oriented is a kind of thought, a kind of thinking. In object-oriented programming, a class is the smallest unit and is the interaction between classes and classes. The type of data created by class as a template is called an object. The scope of the variable: Public(available everywhere in the project), private can only be used inside the class. You cannot create an array (struct) with an object created by class, and you can create a collection (array). Each time you create an object you need to open up space with new. Structs can automatically open up space. object is the base class for all data types: like creatures for all animals, plants, microorganisms and so on. Small knowledge Point: Scaling code:#regionEndregionBlue BLOCK: member variable purple block: When member method is programmed, right-click function name-go To Definition1. Example: storing and processing student information through a struct array, the information of 10 students is recorded from the console according to the following requirements (school number, name, C language score) Use the structure, print the total score and average of the class in the console, and print the highest score, the lowest score of students information, According to the high and low print the class score book and discharge position, require the use of structure, custom functions, arrays to complete the subject. Copy Code#region= = Student Course title = =structStudent { Public stringCode; Public stringname; Public decimaldegree; } Static voidMain (string[] args) {Console.Write ("Please enter the number of people:"); intn =int. Parse (Console.ReadLine (). ToString ()); decimalsumfen=0, avg=0, max=0, min=0; Student[] Sumstu=NewStudent[n]; //cyclic entry According to the number of people entered for(inti =0; I < n; i++) {Console.WriteLine ("Please enter section"+ (i+1)+"A student's information"); Console.WriteLine ("study number name C language score, separated by tab key"); strings =Console.ReadLine (); string[] Sarr = S.split (New Char[]{'\ t'});//use split to separate by delimiterSumstu[i].code= sarr[0]; Sumstu[i].name= sarr[1]; Sumstu[i].degree=decimal. Parse (sarr[2]); Sumfen+=Sumstu[i].degree; } Console.WriteLine ("****************************************"); Console.WriteLine ("Total Score:"+Sumfen. ToString ()); Avg= Sumfen/N; Console.WriteLine ("Average score:"+avg. ToString ()); //Bubble Sort for(inti =0; I < n1; i++) { for(intj = i+1; J < N; J + +) { if(Sumstu[i].degree <Sumstu[j].degree) {Student Zhong=NewStudent (); Zhong=Sumstu[i]; Sumstu[i]=Sumstu[j]; SUMSTU[J]=Zhong; }}} Console.WriteLine ("Highest score:"+sumstu[0].degree. ToString ()); Console.WriteLine ("Minimum Score:"+sumstu[n-1].degree. ToString ()); Console.WriteLine ("the results of this class are listed below:"); Console.WriteLine ("****************************************"); Console.WriteLine ("Rank Study number name result"); for(inti =1; I <= N; i++) {Console.WriteLine (i+"\ t"+sumstu[i-1].code+"\ t"+sumstu[i-1].name+"\ t"+sumstu[i-1].degree); } console.readline (); Copy the Code2. Using the array collection to process student information copy CodeclassProgram {//use an array to store 10 student information, (instead of putting the structure in an array, just practice the use of the array)//Define student information structure Body Public structStudent { Public stringSno; Public stringname; Public intdegree; } Static voidMain (string[] args) { //defines an array of student element types, storing 10 student informationArray Myarr = array.createinstance (typeof(Student),Ten); for(inti =0; i < myarr.length; i++) {Student AAA; Console.WriteLine ("Please enter section"+ (i +1) +"Student's school number, name, score"); Aaa.sno=Console.ReadLine (); Aaa.name=Console.ReadLine (); Aaa.degree=Convert.ToInt32 (Console.ReadLine ()); Myarr.setvalue (AAA, I); } //Split LineConsole.WriteLine ("********************************************************"); //To find the total score and the average intsum =0; for(inti =0; i < myarr.length; i++) { Objectaaa//defines an object to receive an element taken from an arrayAAA =Myarr.getvalue (i); Student b= (Student) AAA;//force the removed element to be convertedSum + =B.degree; } Console.WriteLine ("Total score is"+ Sum +"evenly divided into"+ Sum/myarr.length); Console.WriteLine ("********************************************************"); //highest score, lowest score by bubble sort int[] A =New int[Ten];//use an array to store the fraction of an element for(inti =1; I <= myarr.length; i++)//bubble sort, sorts the elements in an array by the size of fractions { for(intj =1; J <= Myarr.length-i; J + +) { ObjectAAA, BBB;//defines two objects to receive elements taken from an arrayAAA = Myarr.getvalue (J-1); BBB=Myarr.getvalue (j); Student AA= (Student) AAA;//force the removed element to be convertedStudent BB =(Student) BBB; A[j-1] = Aa.degree;//determines whether the position of an element is swapped by comparing the size of the fraction of the adjacent two elementsA[J] =Bb.degree; if(A[j] > A[j-1]) {Myarr.setvalue (AA, J); Myarr.setvalue (BB, J-1); } } } ObjectZG, ZD; ZG= Myarr.getvalue (0); Student mm=(Student) ZG; ZD= Myarr.getvalue (Myarr.length-1); Student N=(Student) ZD; Console.WriteLine ("maximum is divided into"+ Mm.degree +"name"+ Mm.name +"School Number"+ Mm.sno +"minimum is divided into"+ N.degree +"name"+ N.name +"School Number"+N.sno); //Split LineConsole.WriteLine ("********************************************************"); //Print a score sheet for(inti =0; i < myarr.length; i++) { ObjectAAA; AAA=Myarr.getvalue (i); Student b=(Student) AAA; Console.WriteLine ("name"+ B.name +"School Number"+ B.sno +"score of"+b.degree); }}} copy code BB
C # Object-oriented