首页 > 其他分享 >实验六

实验六

时间:2023-05-28 15:33:18浏览次数:32  
标签:head int char STU 实验 printf include

task_1

#include<stdio.h> 
#include<string.h>
#define N 3 

typedef struct student{
    int id;
    char name[20];
    char subject[20];
    double perf;
    double mid;
    double final;
    double total;
    char level[10];
}STU;

void input(STU [],int);
void output(STU [],int);
void calc(STU [],int);
int fail(STU [],STU [],int);
void sort(STU [],int);

int main(){
    STU st[N],fst[N];
    int k;
    
    printf("录入学生成绩信息:\n");
    input(st,N);
    
    printf("\n成绩处理...\n");
    calc(st,N);
    
    k=fail(st,fst,N);
    sort(st,N);
    printf("\n学生成绩排名情况:\n");
    output(st,N);
    
    printf("\n不及格学生信息:\n");
    output(fst,k);
    
    return 0;
}

void input(STU s[],int n){
    int i;
    for(i=0;i<n;i++){
        scanf("%d %s %s %lf %lf %lf",&s[i].id,&s[i].name,&s[i].subject,&s[i].perf,&s[i].mid,&s[i].final);
    }
}

void output(STU s[],int n){
    int i;
    printf("----------------------\n");
    printf("学号    姓名    科目    平时    期中    期末    总评    等级\n");
    for(i=0;i<n;i++)
    printf("%d    %-6s    %-4s    %-4.0f    %-4.0f    %-4.0f    %-4.1f    %s\n",s[i].id,s[i].name,s[i].subject,s[i].perf,s[i].mid,s[i].final,s[i].total,s[i].level);
}

void calc(STU s[],int n) {
    int i;
    
    for(i=0;i<n;i++){
        s[i].total=s[i].perf*0.2+s[i].mid*0.2+s[i].final*0.6;
        
        if(s[i].total>=90)
        strcpy(s[i].level,"优");
        else if(s[i].total>=80&&s[i].total<90) 
        strcpy(s[i].level,"良");
        else if(s[i].total>=70&&s[i].total<80) 
        strcpy(s[i].level,"中");
        else if(s[i].total>=60&&s[i].total<70) 
        strcpy(s[i].level,"及格");
        else 
        strcpy(s[i].level,"不及格");
    }
}

int fail(STU s[],STU t[],int n){
    int i,k=0;
    
    for(i=0;i<n;i++)
    if(s[i].total<60)
    t[k++]=s[i];
    
    return k;
    
} 

void sort(STU s[],int n){
    int i,j;
    STU t;
    
    for(i=0;i<n;i++)
    for(j=0;j<n-1-i;j++)
    if(s[j].total<s[j+1].total){
        t=s[j];
        s[j]=s[j+1];
        s[j+1]=t;
    }
}

 

 task_2

#include<stdio.h> 
#include<string.h>
#define N 10
#define M 80

typedef struct student{
    char name[M];
    char author[M];
}Book;

int main(){
    Book x[N]={{"《一九八四》","乔治.奥威尔"},
               {"《美丽新世界》","赫胥黎"},
               {"《昨日的世界》","斯蒂芬.茨威格" },
               {"《万历十五年》","黄仁宇"},
               {"《一只特立独行的猪》","王小波"},
               {"《百年孤独》","马尔克斯"},
               {"《查令十字街84号》","海莲.海芙"},
               {"《只是孩子》","帕蒂.史密斯"},
               {"《刀锋》","毛姆"},
               {"《沉默的大多数》","王小波"}};
    Book *ptr;
    int i;
    char author[M];
    
    printf("所有图书信息:\n");
    for(ptr=x;ptr<x+N;++ptr)
        printf("%-30s%-30s\n",ptr->name,ptr->author);
        
    printf("\n输入作者名:");
    gets(author);
    for(ptr=x;ptr<x+N;++ptr)    
    if(strcmp(ptr->author,author)==0){
        printf("%-30s%-30s\n",ptr->name,ptr->author);
    }
    return 0;
}

 

 

 task_3

#include<stdio.h>
#include<stdlib.h>
#define N 80

typedef struct Filminfo{
    char name[N];
    char director[N];
    char region[N];
    int year;
    struct Filminfo *next;
}Film;

void output(Film *head);
Film *insert(Film *head, int n);


int main(){
    int n;
    Film *head;
    
    head=NULL;
    printf("输入影片数目:");
    scanf("%d",&n);
    
    head=insert(head,n);
    
    printf("\n所有影片信息如下:\n");
    output(head);
    
    return 0;
}

Film *insert(Film *head, int n){
    int i;
    Film *p;
    
    for(i=1;i<=n;++i){
        p=(Film*)malloc(sizeof(Film));
        printf("请输入第%d部影片信息:",i);
        scanf("%s %s %s %d",p->name,p->director,p->region,&p->year);
        
        p->next=head;
        head=p;
    }
    
    return head;
}
    
void output (Film *head){

    Film *p;
    
    p=head;
    while(p!=NULL){
        printf("%-20s %-20s %-20s %d\n",p->name,p->director,p->region,p->year);
        p=p->next;
    }
}

 

task_4

 

#include<stdio.h>
#include<string.h>
#define N 100

typedef struct{
    char num[10];
    int s1;
    int s2;
    double sum;
    char level[10];
}STU;

int fun(STU a[],int n,STU h[]);

int main(){
    STU s[N]={{"GA05",85,76},
              {"GA03",76,90},
              {"GA02",69,90},
              {"GA04",85,56},
              {"GA01",91,95},
              {"GA07",72,80},
              {"GA08",64,45},
              {"GA06",87,98},
              {"GA015",85,86},
              {"GA013",91,97}};
    STU h[N];
    int i,k,n=10;
    
    k=fun(s,n,h);
    
    printf("There are:\n");
    for(i=0;i<k;i++)
    printf("%s %d %d %.2f %s\n",h[i].num,h[i].s1,h[i].s2,h[i].sum,h[i].level);
    
    return 0;
}

int fun(STU a[],int n,STU h[]){
    int i,k=0;
    double sum=0.0,aver=0.0;
    for(i=0;i<n;i++)
    {
        a[i].sum=a[i].s1*0.7+a[i].s2*0.3;
        sum=sum+a[i].sum;
    }
        aver=sum/n;    
        
    for(i=0;i<n;i++){
        if(a[i].sum>aver){
        
           strcpy(a[i].level,"均分以上");
            h[k]=a[i];
            k++;
        }
    }
    return k;
}

 

task_5

 

#include<stdio.h>
#include<string.h>
#define N 5

typedef struct student{
    char name[10];
    int num;
    int maths;
    int computer;
    int english;
    int sum;
    char level[10];
}STU;

void fun(STU a[],int n);

int main(){
    STU s[6*N]={{"A001",1,34,67,80},
                {"B003",3,78,87,90},
                {"A002",2,90,98,99},
                {"B002",4,56,78,98},
                {"A005",5,35,67,79}};
    int i;
    
    fun(s,N);
    for(i=0;i<N;i++)
       printf("%s %d %d %d %d %d %s\n",s[i].name,s[i].num,s[i].maths,s[i].computer,s[i].english,s[i].sum,s[i].level);
    return 0;
}

void fun(STU a[],int n){
    int i,j,k;
    STU b[n],l;

    for(j=0;j<n;j++){
      a[j].sum=a[j].maths+a[j].computer+a[j].english;
      b[j]=a[j];
    }

      
 for (i=0;i<n-1;i++)
     for (j=0;j<n-1-i;j++)
     
      if(b[j].sum>b[j+1].sum)    {
          l=b[j];
          b[j]=b[j+1];
          b[j+1]=l;
    }
      
for(k=0;k<n;k++){
    if(a[k].sum==b[0].sum)
    strcpy(a[k].level,"不及格");
    else if(a[k].sum==b[4].sum) 
    strcpy(a[k].level,"优秀");
    else
    strcpy(a[k].level,"合格"); 
}
}

 

task_6

 

#include<stdio.h>

#define N 5

typedef struct student{
    long no;
    char name[20];
    int score;
}STU;

void input(STU s[],int n);
int find_min_list(STU s[],STU t[],int n);
void output(STU s[],int n);

int main(){
    STU stu[N],min_list[N];
    int count;
    
    printf("录入%d个学生信息\n",N);
    input(stu,N);
    
    printf("\n统计最低分人数和学生信息...\n");
    count=find_min_list(stu,min_list,N);
    
    printf("\n一共有%d个最低分,信息如下:\n",count);
    output(min_list,count);
    
    return 0;
}

void input(STU s[],int n){
    int i;
    for(i=0;i<n;i++){
        scanf("%d %s %d",&s[i].no,&s[i].name,&s[i].score);
    }
}

void output(STU s[],int n){
    int i;
    for(i=0;i<n;i++){
        printf("%d %s %d\n",s[i].no,s[i].name,s[i].score);
    }
}

int find_min_list(STU s[],STU t[],int n){
int i,j,k=0;
STU l;
for (i=0;i<n-1;i++)
    for (j=0;j<n-1-i;j++)
     
      if(s[j].score>s[j+1].score)    {
          l=s[j];
          s[j]=s[j+1];
          s[j+1]=l;
    }
for(i=0;i<n;i++){
    if(s[i].score==s[0].score){
        t[k]=s[i];
        k++;
    }
    }
    return k;
}
      

 

 

标签:head,int,char,STU,实验,printf,include
From: https://www.cnblogs.com/zyyjl/p/17432037.html

相关文章

  • 实验6
     task1.c1//P286例8.172//对教材上的程序作了微调整,把输出学生信息单独编写成一个函数模块3//打印不及格学生信息和所有学生信息程分别调用45#include<stdio.h>6#include<string.h>7#defineN3//运行程序输入测试时,可以把这个数......
  • 实验 六
    实验1、2、3已完成验证,充分学习理解了结构体相关知识点。实验4:#include<stdio.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时成绩doublesum;//总评charlevel[10];//等级}......
  • 实验6 结构体应用编程
    task1//打印不及格学生信息和所有学生信息程分别调用#include<stdio.h>#include<string.h>#defineN3typedefstructstudent{intid;charname[20];charsubject[20];doubleperf;//平时成绩doublemid;//期中成绩doublefinal;......
  • 实验六
    task4#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时成绩doublesum;//总评charlevel[10];//等级}STU;intfun(STUa[],intn,S......
  • 实验6
    实验任务4实验源代码#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时成绩doublesum;//总评charlevel[10];//......
  • 实验6 结构体应用编程
    实验四#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[100];ints1;ints2;doublesum;charlevel[10];}STU;intfun(STUa[],intn,STUh[]);intmain(){STUs[N]={{"GA......
  • 实验6 结构体应用编程
    1.task41//finish!2#include<stdio.h>3#include<string.h>4#include<stdlib.h>5#defineN10067typedefstruct{8charnum[10];//学号9ints1;//期末成绩10ints2;//平时成绩1......
  • 实验6
    task1源代码//P286例8.17//对教材上的程序作了微调整,把输出学生信息单独编写成一个函数模块//打印不及格学生信息和所有学生信息程分别调用#include<stdio.h>#include<string.h>#defineN3//运行程序输入测试时,可以把这个数组改小一些输入测试type......
  • 华为—DHCP中继实验配置-通过两种配置方法实现功能
     实验说明本实验将通过两种中继配置方法实现DHCP中继功能  第一种:在接口下直接指定DHCP服务器IP地址  第二种:通过在接口下调用DHCP服务器组实验拓扑图实验要求1、将路由器R1作为DHCP服务器,创建全局地址池分配地址;2、通过DHCP中继实现为PC1和PC2分配不同网段地址 ......
  • 实验六
    task4.c#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时成绩doublesum;//总评charlevel[10];//等级}STU;......