Data Structure-sports meeting score statistics

Source: Internet
Author: User

// Exercise score statistics ////////
// Time: 2005-7-4
// Program: Zhang jianbo

# Include <iostream. h>
# Include <string. h>
# Include "menu. H"
# Include "key. H"

Typedef struct xm_table {
Int item; // Project No.
Char name [20];
Int count; // Number of Persons scoring in this project
} Xm_table;

Struct student {
Char name [20]; // name
Int score; // score
Int range; // ranking
Int item; // score item
Int sex; // gender
};

Typedef struct schoolstruct // participating schools
{
Int count; // calculate the actual number of athletes
Int serial; // school ID
Char name [20];
Int menscore; // total score of men's groups
Int womenscore; // total score of the female group
Int totalscore; // group total score
Int jifeng; // School points
Struct student students [10]; // contestant
Struct schoolstruct * Next; // participating schools
} Schoolstruct;

Void creat_shool_link (schoolstruct * & head); // create a linked list
Void add_student_link (schoolstruct * & head); // Add an award winner
Void tj_fx (schoolstruct * & head); // score statistics
Void find_xm_id (schoolstruct * & head, int xm_id); // query the top three or top five schools by project number.
Void find_school_xm (schoolstruct * & head, int school_id, int xm_id); // query a school project by school number
Void output_link (schoolstruct * head); // output data to the screen

Void _ setargs (); // parameter settings
Void _ setxminfor (); // project information
Void addstudent (schoolstruct * & schooltable); // Add student data

Int schoolcount = 0; // Total Number of Schools
Int boycount = 0; // total number of boys' Projects
Int girlcount = 0; // total number of girls' projects
Int xm_count = 0; // total number of projects
Xm_table xm_t [41]; // project table

Int _ f1_main () {// function entry

Menu M [9];
M [1]. Name = "parameter settings ";
M [2]. Name = "add student ";
M [3]. Name = "Statistics ";
M [4]. Name = "school query ";
M [5]. Name = "project query ";
M [6]. Name = "return ";

Schoolstruct * H, * head, * schooltable; // = new schoolstruct;

Int id = 1;
While (1)
{
Showmenu ("Data Structure-sports meeting score Statistics", M, 6); // display menu
Id = selectmenuid (); // obtain the selected menu ID
Switch (ID ){
Case 1 :{
_ Setargs ();
_ Setxminfor ();
Creat_shool_link (schooltable );
H = head = schooltable;
Initkey ();
Break;
}
Case 2: {addstudent (schooltable); initkey (); break ;}
Case 3: {tj_fx (h); output_link (h); initkey (); break ;}
Case 4 :{
Int m_school_id;
Int m_xm_id;
For cout <"/N, enter the school ID (1 --" <schoolcount <") school ID = ";
Cin> m_school_id;
For cout <"/N, enter the project number (1 --" <xm_count <") XM id = ";
Cin> m_xm_id;
Find_school_xm (H, m_school_id, m_xm_id );
Initkey ();
Break;
}
Case 5 :{

Int m_xm_ I;
Cout <"/n enter the project id = ";
Cin> m_xm_ I;
Find_xm_id (H, 1 );
Initkey ();
}
Case 6: Return 0;
}
}
Return 0;
}

Void creat_shool_link (schoolstruct * & head) {// create a linked list
// Create a linked list
Schoolstruct * P;
P = new schoolstruct;
Head = P;
For (INT I = 1; I <= schoolcount; I ++)
{
P = p-> next = new schoolstruct;
Cout <"enter the school name/N ";
Cout <"school ID =" <I <Endl;
Cout <"school name = ";
P-> serial = I;
P-> jifeng = 0; // set the credit to 0.
P-> totalscore = 0;
P-> womenscore = 0;
P-> menscore = 0;

Cin> P-> name;
P-> COUNT = 0; // set the number of athletes to 0;
}
P-> next = NULL;
Head = head-> next;
}

Void add_student_link (schoolstruct * & head) {// Add an award winner
Schoolstruct * H, * P;

Int school_id; // The school ID.
Char student_name [20]; // Student name
Int sex; // gender
Int xm_id;
Int score;
Int range; // ranking

Cout <"Enter the student's school ID (1 <--->" <schoolcount <") id = ";
Cin> school_id;
Cout <"Enter the Student name = ";
Cin> student_name;
Cout <"select student gender [0 = FEMALE 1 = male] Sex = ";
Cin> sex;
If (sex = 0)
For cout <"/N, enter the Project ID (1 <--->" <girlcount <") id = ";
If (sex = 1)
For cout <"/N, enter the Project ID (1 <--->" <boycount <") id = ";
Cin> xm_id;
Cout <"/n enter the score for this project = ";
Cin> score;
Cout <"/N, enter the ranking range = ";
Cin> range;

// Find the school ID
H = head;
While (h)
{
If (H-> serial = school_id)
{

P = h;
P-> COUNT = p-> count + 1; // number of athletes + 1
Strcpy (p-> students [p-> count]. Name, student_name); // Student name
P-> students [p-> count]. Item = xm_id; // score item
Xm_t [xm_id]. Count = xm_t [xm_id]. Count + 1; // The number of people who scored in this project + 1
P-> students [p-> count]. range = range; // rank
P-> students [p-> count]. Score = score; // score
P-> students [p-> count]. Sex = sex; // gender
Break;
}
Else h = H-> next;
}
}

Void tj_fx (schoolstruct * & head) {// score statistics

Schoolstruct * H, * P;
P = H = head; // Save the head pointer of the linked list
Int menscore = 0; // total score of men's groups
Int womenscore = 0; // total score of the female group
Int totalscore = 0; // group total score
Int I;
Int item_ I = 0;
Int JF = 0; // points
While (p ){
For (I = 1; I <= p-> count; I ++)
{
// Calculate the score
Totalscore = totalscore + P-> students [I]. Score; // calculate the total score
If (p-> students [I]. Sex = 0) womenscore = womenscore + P-> students [I]. Score; // The total score of the female group
Else menscore = menscore + P-> students [I]. Score; // total score of men's groups
// Calculate points

Item_ I = p-> students [I]. item;
If (xm_t [item_ I]. Count> = 5 ){
// Obtain the first five
If (p-> students [I]. range = 1) JF = JF + 7;
Else if (p-> students [I]. range = 2) JF = JF + 5;
Else if (p-> students [I]. range = 3) JF = JF + 3;
Else if (p-> students [I]. range = 4) JF = JF + 2;
Else if (p-> students [I]. range = 5) JF = JF + 1;

}
If (xm_t [item_ I]. Count <5 ){
// Obtain the first three
If (p-> students [I]. range = 1) JF = JF + 5;
Else if (p-> students [I]. range = 2) JF = JF + 3;
Else if (p-> students [I]. range = 3) JF = JF + 2;
}
// Cout <"/ndebug: JF =" <JF <Endl;
// Cout <"/ndebug p-> students [I]. Range:" <p-> students [I]. range <Endl;
}

P-> jifeng = JF; // calculate points
P-> womenscore = womenscore; // Save the total score of women
P-> menscore = menscore; // stores the total score of men.
P-> totalscore = totalscore; // Save the total score.

Jf = 0;
Menscore = 0; // total score of the men's group
Womenscore = 0; // total score of the female group
Totalscore = 0; // total score

P = p-> next; // move the pointer backward.

}

}

Void find_xm_id (schoolstruct * & head, int xm_id) {// query the top three or the top five schools by project number.
Schoolstruct * H, * P;
P = H = head; // Save the head pointer of the linked list
Int I;
Cout <"/n query by project number to obtain the first three or the first five schools/N ";
Cout <"query result:/N ";
While (h ){
//

For (I = 1; I <= H-> count; I ++)
{
If (H-> students [I]. Item = xm_id)
{
Cout <"School:" }
}

H = H-> next;
}

}

Void find_school_xm (schoolstruct * & head, int school_id, int xm_id) {// query a school project by school number
Schoolstruct * H, * P;
P = H = head; // Save the head pointer of the linked list
While (h ){
If (H-> serial = school_id) {P = H; break ;}
H = H-> next;
}

Cout <"/n query a school project by school number/N ";
Int xm_ I = 0;
For (INT I = 1; I <= p-> count; I ++ ){
If (p-> students [I]. Item = xm_id ){
Cout <"the query result is as follows:" <Endl;
Cout <"name:" <p-> students [I]. Name <"";
Xm_ I = p-> students [I]. item;
If (p-> students [I]. Sex = 0 ){
Cout <"Gender: Female/N ";
Xm_ I = xm_ I + 20;
}
Else {
Cout <"Gender: male/N ";
}

Cout <"Project No.:" <p-> students [I]. Item <"Project name:" <xm_t [xm_ I]. Name;
Cout <"score of this project:" <p-> students [I]. score <"ranking:" <p-> students [I]. range <Endl;
}
}


}

Void output_link (schoolstruct * head) {// output data to the screen
Schoolstruct * h;
H = head;
Int I;
Int xm_item;
While (h) {// traverse the school
Cout <"school ID:/N" Cout <"school name:" Cout <"sports meeting points:" Cout <"total score of men's groups:" Cout <"total score of women's groups:" Cout <"total score:"

Cout <"athletes:" Cout <"/n -----------------------------------------/N ";
For (I = 1; I <= H-> count; I ++) {// output the students and athletes in the school
Cout <"athlete name" Cout <"gender" Xm_item = H-> students [I]. item;
If (H-> students [I]. Sex = 0) xm_item = xm_item + 20; // if it is a girl, the project table is moved 20
Cout <"score item" <xm_t [xm_item]. Name <"";
Cout <"score" Cout <"ranking" }
Cout <"/n --------------------------------------/N ";
H = H-> next; // the pointer moves backward.
}

Cout <"/n -- Project List of this sports meeting --/N ";
Int xm_count_ I;
For (xm_count_ I = 1; xm_count_ I <= boycount; xm_count_ I ++)
{
Cout <"no." <xm_t [xm_count_ I]. item <"name" <xm_t [xm_count_ I]. name <"Participants" <xm_t [xm_count_ I]. count <Endl;
}

For (xm_count_ I = 1; xm_count_ I <= girlcount; xm_count_ I ++)
{
Cout <"no." <xm_t [xm_count_ I + 20]. item <"name" <xm_t [xm_count_ I + 20]. name <"Participants" <xm_t [xm_count_ I + 20]. count <Endl;
}

Cout <"/n -----------------------/N ";

}

Void _ setargs () {// parameter settings
/// Set the participating schools
Loop_1:
Cout <"Enter the participating schools (n> = 2)/nn = ";
Cin> schoolcount;
If (schoolcount <2) {cout <"/n data input error"; goto loop_1 ;}
////////////////////////////

Loop_2:
Cout <"/n please enter the total number of boys' projects 0 <n <= 20/Nm = ";
Cin> boycount;
If (boycount <0 | boycount> 20) {cout <"/n data input error"; goto loop_2 ;}
/////////////////////////////

Loop_3:
Cout <"/n please enter the total number of girls' projects 0 <n <= 20/nw = ";
Cin> girlcount;
If (girlcount <0 | girlcount> 20) {cout <"/n data input error"; goto loop_3 ;}
/////////////////////////////
Xm_count = boycount + girlcount; // total number of projects
}

Void _ setxminfor () {// project information
Int I;
Cout <"/n enter boys' project information" <Endl;
For (I = 1; I <= boycount; I ++ ){
Cout <"project" <I <"name = ";
Xm_t [I]. Item = I; // Project No.
Xm_t [I]. Count = 0; // Number of participants in the project
Cin> xm_t [I]. Name; // project name
}
Cout <"/n enter Girl Project information" <Endl;
For (I = 1; I <= girlcount; I ++ ){
Cout <"project" <I <"name = ";
Xm_t [20 + I]. Item = I; // Project No.
Cin> xm_t [20 + I]. Name; // project name
}
}

Void addstudent (schoolstruct * & schooltable) {// Add student data
Int ANW;
Loop_4:
Add_student_link (schooltable); // Add student data
Cout <"/N: continue to add student data? [0 = No 1 = Yes]/n ";
Cin> ANW;
If (ANW = 1) goto loop_4;
}

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.