Initial idea of implementing a two-dimensional table

Source: Internet
Author: User

Tab: blog HTTP for Ar data 2014 Div log sp

Using struct, We can manually enter some student information for automatic sorting and printing;

First, define a struct named student outside the main function. Student struct is required for information storage by none of the following.

Struct student
{
Public int no;
Public string name;
Public int cshap;
Public int web;
Public int datebase;
Public int sum;

} // Define a student struct

The main function starts;

Static void main (string [] ARGs)

{
Int I; Int J; // declare the cyclic variable
Int NOx; string name_x; int cshap_x; int web_x; int datebase_x; // define element Variables

The above mainly defines two cyclic variables I and J. I is used for input loops and J is used for sorting loops. NOx is a variable that inputs the student ID, name_x is a variable that inputs the name, cshap_x is a variable that inputs the cshap score, and web_x is a variable that inputs the webpage score, datebase_x is a variable used to input database scores.

Student A = new student ();
Student B = new student ();
Student C = new student ();
Student d = new student (); // defines the structure used to store the scores of three students, and D for exchange.

Four student types are defined above. A, B, and C are the structures that store the scores of three students, and D is a structure used to exchange data during sorting.

 

The following figure shows the start of the input loop. A total of three students need to be input. Therefore, I <= 3. The student ID is auto + 1. Other information must be input actively, after entering a student, clear the screen.

For (I = 1; I <= 3; I ++)
{
// Prompt for input data and save it in the element variable
NOx = I;
Console. writeline ("enter the name of the {0} STUDENT:", I );
Name_x = console. Readline ();
Console. writeline ("Enter the cshap score of {0} students:", I );
Cshap_x = convert. toint32 (console. Readline ());
Console. writeline ("Enter the website score of {0} students:", I );
Web_x = convert. toint32 (console. Readline ());
Console. writeline ("Enter the database score of {0} students:", I );
Datebase_x = convert. toint32 (console. Readline ());

Console. Clear ();

// The following judges whether it is the first student. If yes, the basic data is stored in the structure of the first student, that is,.

If (I = 1)
{
A. No = NOx;
A. Name = name_x;
A. cshap = cshap_x;
A. Web = web_x;
A. datebase = datebase_x;
A. Sum = A. cshap + A. Web + A. datebase;

}

// Check whether the student is the second student. If yes, save the basic data to the structure of the second student, that is, B.

If (I = 2)
{

B. No = NOx;
B. Name = name_x;
B. cshap = cshap_x;
B. Web = web_x;
B. datebase = datebase_x;
B. Sum = B. cshap + B. Web + B. datebase;

}

// Check whether the student is a third student. If yes, save the basic data to the structure of the third student, that is, C.

If (I = 3)
{

C. No = NOx;
C. Name = name_x;
C. cshap = cshap_x;
C. Web = web_x;
C. datebase = datebase_x;
C. Sum = C. cshap + C. Web + C. datebase;

}

}

// After the data is stored, sort the data. Because the data stored in A, B, and C is used here, I did not expect to directly use two sets of loops to bubble the sorting method, you can use an array ZF [] to store the total score of each student, so that you can use two sets of loops for sorting.

For (j = 0; j <2; j ++)
{
If (A. Sum <B. Sum)
{
D =;
A = B;
B = D;
}
If (B. Sum <C. Sum)
{
D = B;
B = C;
C = D;

}
}

// The sorting is complete and printed. Because the previous statements have arranged the order, the data of the students with the highest total score is placed in a, the data of the lower scores is placed in B, and the data of the lower scores is placed in C, therefore, print data directly by A, B, and C.

Console. writeline ("student ID \ t name \ tcshap \ t webpage \ t database \ t total score \ t ");
Console. writeline ("{0} \ t {1} \ t {2} \ t {3} \ t {4} \ t {5} \ t"),. no,. name,. cshap,. web,. datebase,. sum );
Console. writeline ("{0} \ t {1} \ t {2} \ t {3} \ t {4} \ t {5} \ t"), B. no, B. name, B. cshap, B. web, B. datebase, B. sum );
Console. writeline ("{0} \ t {1} \ t {2} \ t {3} \ t {4} \ t {5} \ t"), C. no, C. name, C. cshap, C. web, C. datebase, C. sum );

}
}
}

It is basically an idea to implement the orders table. However, when there are a large number of students, the program is very complicated and you need to try again in other ways. It is best to solve the problem cyclically.

Let's take a look at the effect:

Input student information interface: input after printing the interface: Program network address: http://pan.baidu.com/s/1qWNmAUo

Initial idea of implementing a two-dimensional table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.