Home > Back-end >  About the structure of the c questions want to ask how to do
About the structure of the c questions want to ask how to do

Time:09-16

(2) write a program to define a structure type, can be stored at ordinary times, a student internship, test, the final achievement and overall performance, and then asked for structure array to complete the following tasks:
A. programming complete input 4 students at ordinary times, practice, test and final grades, as a function of encapsulation,
B. calculate the four student's overall performance, as a function of encapsulation, which normally, internship, test and final respectively 10%, 20%, 20%, 50%,
C. to find students the highest overall performance, as a function of encapsulation,
D. output overall achievement of the highest student achievement information (normally, practice, test, final grades and overall grades),
(3) write a program: (2) the changes of process, makes the program can support input n student performance, n can be determined by the user input, such as to prompt the user for the number of students, and then enter the scores,
Tip: you need to define a structure pointer, and then use malloc dynamically allocated space, free recycling space,
(4) write a program to define a structure type, you can store the name of a course on teacher's name, course number of students and learning scores, programming complete input 4 course information, calculate and output the most credits the gate (not only a) course information, asked for array and structure reference tasks (2) the packaging function,

CodePudding user response:

Ask yourself with reference to the 4 write
 
#include
#include

Typedef struct student
{
Char name [20].//name
Float ps;//grades
Float sx.//internship performance
Float cy;//test score
Float qm;//final grade
Float zp;//overall achievement
} stu.

//input result
Void Input (stu * ArrStu, int n)
{
int i;
for (i=0; I{
Printf (" input the names of the first % d a student internship at ordinary times test final grade: \ n ", I + 1);
The scanf (" % s % f % f % f % f ", ArrStu [I]. Name, & amp; ArrStu [I]. Ps, & amp; ArrStu [I]. Sx, & amp; ArrStu [I]. Cy,
& ArrStu [I]. Qm);
ArrStu [I]. Zp=(ArrStu [I] ps * 0.1 + ArrStu [I] sx * 0.2 + ArrStu [I] cy * 0.2 +
ArrStu [I]. Qm * 0.5);
}
}

Void MaxZP (stu * StuArr, int n)
{
If (StuArr==NULL)
{
Printf (" Error!" );
exit(1);
}
Int I, index;
Float Max=StuArr [0]. Zp;
for (i=0; i{
If (Max & lt; StuArr [I]. Zp)
{
Max=StuArr [I]. Zp;
index=i;
}
}
Printf (" % d \ n ", the index);
Name: printf (" % s \ n grades: %, 2 f \ n practice achievement: %, 2 f \ n test scores: %, 2 f \ n final grade: %, 2 f \ n overall grade: %, 2 f \ n ",
StuArr [index]. Name, StuArr [index]. Ps, StuArr [index] sx, StuArr [index]. Cy, StuArr [index]. Qm,
StuArr [index]. Zp);
}

Int main ()
{
Stu * StuArr=NULL;
Int n=0, the index=1;

Printf (" input the number of students: \ n ");
The scanf (" % d ", & amp; N);

StuArr=(stu *) malloc (sizeof (stu) * n);

Input (StuArr, n);
MaxZP (StuArr, n);



Free (StuArr);
StuArr=NULL;

return 0;
}
  • Related