Summary and experience of the sixth experiment

This week we conducted the sixth test, the experiment is about the structure, union test body, this experiment do a little effort, using the wrong statement, took some time to correct, or to practice more, good to see content structure. Here is the Experiment:

Part1: structure type and application programming

1. Confirmatory Experiment: This section is to understand the structure of the program on the basis of the teacher.

2. Programming Exercise 1: Completion Program

Topic Description: Record numbers of students by school composition and performance. N student data has been placed in stu structural array in the main function. Write a function findMinlist, to achieve: the lowest score of student data on the array t, the function returns the number of the lowest student scores. (Note: the lowest student scores may be more than one)

#include <stdio.h>
const int N=5;
typedef struct student 
{
    long no;
    char name[20];
    int score;     
}STU;
void input(STU s[], int n);
int findMinlist(STU s[], STU t[], int n);
void output(STU s[], int n);
int main() 
{
    STU stu[N], minlist[N];
    int count;
    printf("录入%d个学生信息\n", N);
    the INPUT (STU, N);   
    printf ( " \ n lowest scores and student demographic information ... \ n " ); 
    COUNT = findMinlist (STU, minlist, N);     
    printf ( " \ n% d a total of lowest points, the following information: \ n " , COUNT); 
    Output (minlist, COUNT);      
    return  0 ; 
} 
void INPUT (the STU S [], int n-) 
{ 
    int I;
     for (I = 0 ; I <n-; I ++ ) 
    Scanf ( " % LD% S% D " , & S [I] .no, S [I] .name, & S [I] .score); 
} 
void Output (the STU S [], int n-)
{
    int i;
    for(i=0; i<n; i++)
    printf("%ld %s %d\n", s[i].no, s[i].name, s[i].score); 
}  
int findMinlist(STU s[], STU t[], int n) 
{
    int i,j,min=s[0].score;
    for(i=0;i<n;i++)
    {
        if(min>s[i].score)
        min=s[i].score;
    }
        i=0;
    for(j=0;j<n;j++)
    {
        if(s[j].score==min)
        t[i++]=s[j];
    }
    return i;
}

After the completion of this part of the program beginning has been wrong not to write leak is wrong, ask the students to understand the behind.

3. Programming Exercise 2:

Topic Description: The final score province computer grade examination is composed of two parts: the objective questions and operating questions the composition. Student information includes ticket number, student's name, title and objective scores, operating questions scores, total score and grade. Objective questions which accounted for 40%, 60% operating questions. Write a function to achieve the following functions: calculate the total score based on students' scores of objective questions and operational issues, and the total score of the students to sort, then level 10% of the total score before former students identified as "excellent", the top 10 between 50 percent (10% but does not include the students comprise 50 percent) identified as "qualified", the students rated as "unqualified."

#include <stdio.h>
#include <string.h>
const int N = 10; 
typedef struct student 
{
    long int id;
    char name[20];
    float objective;   
    float subjective;   
    float sum;
    char level[10];    
}STU; 
void input(STU s[], int n);
void output(STU s[], int n);
void process(STU s[], intn-);
 int main () 
{ 
    the STU STU [N]; 
    the printf ( " input candidate information of% d: ticket number, name, title objective score (<= 40), operating questions score (<= 60) \ n- " , N); 
    INPUT (STU, N);     
    the printf ( " \ n-processed information on the candidates: score calculation, to determine the level \ n- " ); 
    process (STU, N);     
    the printf ( " \ n-print complete information candidates: ticket number, name, title and objective scores, operation title, TOT, rating \ n- " ); 
    Output (STU, N);      
    return  0 ; 
} 
void INPUT (the STU S [], int n-) 
{ 
    int I;
     for (I = 0 ; I <n-; I ++  )
    Scanf (" % LD% S% F% F " , & S [I] .id, S [I] .name, & S [I] .objective, & S [I] .subjective); 
} 
void Output (the STU S [], int n-) 
{ 
    int I; 
    the printf ( " ticket number name score objective test question score out operation level \ n- " );
     for (I = 0 ; I <n-; I ++ ) 
    the printf ( "   % -9ld% -10S% -7.2f%%% -10.2f -13.2f -8S \ n- " , 
    S [I] .id, S [I] .name, S [I] .objective, S [I] .subjective, S [I] .sum, S [I] .level); 
} 
void Process (the STU S [], int n-) 
{ 
    int I, J, K;
     int a1,a2;                  
    a1=(int)(N*0.1),a2=(int)(N*0.5);
    STU temp;
    for(i=0;i<n;i++)
    s[i].sum=s[i].objective+s[i].subjective;
    for(j=0;j<n-1;j++)
    for(k=0;k<n-j-1;k++)
    if(s[k].sum<s[k+1].sum)
    {
        temp=s[k];
        s[k]=s[k+1];
        s[k+1]=temp;
    }
    for(i=0;i<a1;i++)
    strcpy(s[i].level,"优秀");
    for(i=a1;i<a2;i++)
    strcpy(s[i].level,"合格");
    for(i=a2;i<n;i++)
    strcpy(s[i].level,"不合格");
}

This section also took a very long time, the resulting output is wrong, carefully looked at some of the wrong statements.

Part2: Community exemplary programming Types

Community and structure type of difference?

A: Community (Union) several different variables are stored in the same memory cell, i.e. the use of overlay technique, each covering several variables, variables such several different structures together occupying a region of memory.

Structure (Structure) is a type of configuration, which is made up of several "members" thereof. Each member can be a basic data type is a structure or type, but each member may be the same type of data may not be identical.

Community and the difference is the structure of the memory occupied by the Community (Union) is equal to the maximum amount of memory is the memory components, the structure (Structure) memory is occupied by the sum of the memory component.

Part3: enumerated types and programming examples

Enumeration type is used to describe what kind of data?

A: The enumeration is a list of named integer constant, and enumerated types to describe discrete, limited data.

Note the use of enumeration process:
whether the direct input and output?

A: No direct input, an output, each enumeration corresponds to an integer value, the input must be entered enumeration value corresponding to an integer value, it is necessary to use type conversion. When the output value of the enumeration, also need to be cast.

You can put an int value assigned to a variable of type enum? Conversely it?

A: I can not assign a value to a variable of type int an enumerated type.

Summary and Experience:

In this experiment a bit difficult, written procedures a little effort, easy to leak to write some wrong statements, also learn the structure is not enough, we must continue efforts to do more programming.



 

Guess you like

Origin www.cnblogs.com/super123-/p/10991021.html