Home > Back-end >  For a great god
For a great god

Time:09-18

Student information including name, age, 3 classes (English), to achieve the following operations (100)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

1, data entry;

2, print the highest total score students;

3, print only branch high student subjects (input);

4, print only branch fail students and the number of subjects (input);

5, according to the average descending output;

6, according to the scale (average) information query and print the students

0, quit

CodePudding user response:

Use the structure array? Use the list?

CodePudding user response:

reference 1st floor CHXCHXKKK response:
use structure array? Use the list?

Structure

CodePudding user response:

Take time to set the code, for reference, have the ability to own and optimize the
 
# define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
# define N 100

Typedef struct student
{
Char name [20].
int age;
Int math;
Int physics;
Int chermistry;
int total;
Float business;
} STU.

//enter
Void inputSTU (STU * arr, int n)
{
int i=0;
For (I=0; i {
Printf (" enter the names of the students into the first % d age mathematical physical and chemical performance: \ n ", I + 1);
The scanf (" % s % d % d % d % d ", arr [I]. Name, & amp; Arr [I]. Age, & amp; Arr [I]. Math, & amp; Arr [I]. Physics, & amp; Arr [I] chermistry);
Arr [I]. Total=arr [I]. Math + arr [I]. Physics + arr [I] chermistry;
Arr [I] business=arr [I] total * 1.0/3;
getchar();
}
}


//the highest
Void maxSTU (STU * arr, int n, const char * STR)
{
Int I=0, j=0, Max=0;

If (STRCMP (STR, "total")==0)
{
for (i=0; i {
If (Max & lt; Arr [I]. Total)
{
Max=arr [I]. Total;
J=I;
}
}
Printf (" \ \ t \ n name age t \ \ t physics mathematics chemical \ t t scored an average total score \ t \ n ");
Printf (" % s \ \ t t % d % d % d % d \ \ t t \ \ t t % d % 2 f \ n ", arr [j]. Name, arr [j]. Journal of the age, arr [j]. Journal of math,
Arr [j]. Journal of physics, arr [j]. J chermistry, arr [j]. Journal of total, arr [j]. Journal of business);

}
Else if (STRCMP (STR, "mathematics")==0)
{
For (I=0; i {
If (Max & lt; Arr [I]. Math)
{
Max=arr [I]. Math;
J=I;
}
}
Printf (" \ \ t \ n name age t \ \ t physics mathematics chemical \ t t scored an average total score \ t \ n ");
Printf (" % s \ \ t t % d % d % d % d \ \ t t \ \ t t % d % 2 f \ n ", arr [j]. Name, arr [j]. Journal of the age, arr [j]. Journal of math,
Arr [j]. Journal of physics, arr [j]. J chermistry, arr [j]. Journal of total, arr [j]. Journal of business);
}
Else if (STRCMP (STR, "physical")==0)
{
For (I=0; i {
If (Max & lt; Arr [I]. Physics)
{
Max=arr [I]. Physics;
J=I;
}
}
Printf (" \ \ t \ n name age t \ \ t physics mathematics chemical \ t t scored an average total score \ t \ n ");
Printf (" % s \ \ t t % d % d % d % d \ \ t t \ \ t t % d % 2 f \ n ", arr [j]. Name, arr [j]. Journal of the age, arr [j]. Journal of math,
Arr [j]. Journal of physics, arr [j]. J chermistry, arr [j]. Journal of total, arr [j]. Journal of business);

}
Else if (STRCMP (STR, "chemical")==0)
{
For (I=0; i {
If (Max & lt; Arr [I] chermistry)
{
Max=arr [I] chermistry;
J=I;
}
}
Printf (" \ \ t \ n name age t \ \ t physics mathematics chemical \ t t scored an average total score \ t \ n ");
Printf (" % s \ \ t t % d % d % d % d \ \ t t \ \ t t % d % 2 f \ n ", arr [j]. Name, arr [j]. Journal of the age, arr [j]. Journal of math,
Arr [j]. Journal of physics, arr [j]. J chermistry, arr [j]. Journal of total, arr [j]. Journal of business);
}
}

//fail
Void failSTU (STU * arr, int n)
{
Int I=0, count=0;
Char course [10].
Printf (" \ n input failed to query subjects: \ n \ n ");
The scanf (" % s ", course);

If (STRCMP (course, "mathematics")==0)
{
Printf (" \ \ t \ n name age t \ \ t physics mathematics chemical \ t t scored an average total score \ t \ n ");
for (i=0; i {
If (arr [I]. Math & lt; 60)
{
Printf (" % s \ \ t t % d % d % d % d \ \ t t \ \ t t % d % 2 f \ n ", arr [I]. Name, arr [I] age, arr [I]. Math,
Arr [I]. Physics, arr [I] chermistry, arr [I] total, arr [I] business);
count++;
}
}
The number of failed the printf (" % s: % d ", actually, count);
}
Else if (STRCMP (actually, the "physical")==0)
{
Printf (" \ \ t \ n name age t \ \ t physics mathematics chemical \ t t scored an average total score \ t \ n ");
For (I=0; i {
If (arr [I]. Physics & lt; 60)
{
Printf (" % s \ \ t t % d % d % d % d \ \ t t \ \ t t % d % 2 f \ n ", arr [I]. Name, arr [I] age, arr [I]. Math,
Arr [I]. Physics, arr [I] chermistry, arr [I] total, arr [I] business);
count++;
}
}
The number of failed the printf (" % s: % d ", actually, count);
}
Else if (STRCMP (course, "mathematics")==0)
{
Printf (" \ \ t \ n name age t \ \ t physics mathematics chemical \ t t scored an average total score \ t \ n ");
For (I=0; i {
If (arr [I] chermistry & lt; 60)
{
Printf (" % s \ \ t t % d % d % d % d \ \ t t \ \ t t % d % 2 f \ n ", arr [I]. Name, arr [I] age, arr [I]. Math,
Arr [I]. Physics, arr [I] chermistry, arr [I] total, arr [I] business);
count++;
}
}
The number of failed the printf (" % s: % d ", actually, count);
}
}

//average descending
Void sortSTU (STU * arr, int n)
{
STU temp.
int i=0, j=0;
for (i=0; i {
For (j=0; J & lt; N - 1 - I; J++)
{
If (arr [j]. Journal of business & lt; Arr [j + 1] business)
{
temp=arr[j];
Arr=arr [j] [j + 1);
Arr=\ [j + 1];
}
}
}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related