首页 > 其他分享 >实验5

实验5

时间:2022-12-23 14:00:32浏览次数:36  
标签:level int ++ STU 实验 printf ptr

实验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-1; 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;
        }
}

实验2

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

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

int main() {
    Book x[N] = { {"《一九八四》", "乔治.奥威尔"},
                  {"《美丽新世界》", "赫胥黎"},
                  {"《昨日的世界》", "斯蒂芬.茨威格"}, 
                  {"《万历十五年》", "黄仁宇"},
                  {"《一只特立独行的猪》", "王小波"},
                  {"《百年孤独》", "马尔克斯"},
                  {"《情人》", "玛格丽特.杜拉斯"},
                  {"《只是孩子》", "帕蒂.史密斯"}, 
                  {"《刀锋》", "毛姆"},
                  {"《沉默的大多数》", "王小波"} };
    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;
}

实验3

 

#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, j = 0;
    double av = 0.0;
    for (i = 0; i < n; i++)
    {
        a[i].sum = 0.7 * a[i].s1 + 0.3 * a[i].s2;
    }
    for (i = 0; i < n; i++)
    {
        av = av + a[i].sum;
    }
    av = av / n;
    for (i = 0; i < n; i++)
        if (a[i].sum > av)
        {
            strcpy(a[i].level, "均分以上");
            h[j] = a[i];
            j++;
        }
    return j;
}

实验4

#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,max,min;
    STU *ptr;

    for(ptr = a;ptr<a+n;ptr++)
        ptr->sum = ptr->computer + ptr->english + ptr->maths;

    ptr = a;
    max = min = ptr->sum;
    for(ptr = a+1;ptr<a+n;ptr++)
    {
        if(ptr->sum>max)
            max = ptr->sum;
        if(ptr->sum<min)
            min = ptr->sum;
       }
    for(ptr = a;ptr<a+n;ptr++)
    {
        if(ptr->sum==max)
            strcpy(ptr->level,"优秀");
        else if(ptr->sum==min)
            strcpy(ptr->level,"不及格");
        else
            strcpy(ptr->level,"及格");
    }

}

实验5

#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("%ld%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("%-6ld%-8s%-4d\n",s[i].no,s[i].name,s[i].score);
}
int find_min_list(STU s[], STU t[], int n) {
    int i;
    int min = s[0].score;
    STU *ptr;

    for(ptr = s+1;ptr<s+n;++ptr)
        if(ptr->score < min)
            min = ptr->score;

    for(ptr = s,i = 0;ptr<s+n;++ptr)
        if(ptr->score==min)
        {
            t[i] = *ptr;
            i++;
        }

    return i;
}

 

标签:level,int,++,STU,实验,printf,ptr
From: https://www.cnblogs.com/yaj030820/p/16995560.html

相关文章

  • 实验5
    #include<stdio.h>#include<string.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时......
  • 实验二:简单的人机网络对话
    实验目的通过流式套接字编程,实现简单的人机网络对话程序。服务端预存对话模板,根据模板对客户端发来的会话进行应答。实验要求1.使用控制台界面编程。2.利用流式套接字......
  • 芯科BG22蓝牙芯片RAILtest测试实验
    一.如何创建RAILtest工程1.先打开SSV5,插入开发板,选择RAILtest程序:  2.创建工程   3.设置radio,正常情况下使用默认配置即可以跳过此步骤   4.设置......
  • R语言统计学DOE实验设计:用平衡不完全区组设计(BIBD)分析纸飞机飞行时间实验数据
    全文链接:http://tecdat.cn/?p=31010原文出处:拓端数据部落公众号平衡不完全区组设计(BIBD)是一个很好的研究实验设计,具有从统计的角度看各种所需的特征。最近我们被要求撰......
  • 实验八-Web部署
    实验八-Web部署最开始,我用自己的云服务器进行实验步骤如图:  经过下载和解压,进行里面内容的编辑,copy上去即可。  之后在访问ip/wp-config.php时......
  • 实验5
    1#include<stdio.h>2#include<string.h>3#defineN10045typedefstruct{6charnum[10];//学号7ints1;//期末......
  • 实验八-Web部署
    实验步骤在华为云openEuler安装后,没有配置yum源,我们通过重新配置。输入命令以切换到rpos目录下cd/etc/yum.repos.d输入命令更换yum源viopenEuler_x86_64.repo增......
  • 实验5 结构体应用编程
    1#define_CRT_SECURE_NO_WARNINGS2#include<stdio.h>3#include<string.h>4#defineN10056typedefstruct{7charnum[10];//学号8......
  • 实验八-Web部署
    配置openEuler在华为云openEuler安装后,没有配置yum源,我们通过重新配置。cd/etc/yum.repos.dviopenEuler_x86_64.repo增加下面内容:[OS]name=OSbaseurl=http:/......
  • 图像处理的云实验
    一直以来,我都在思考,如何将图像处理和手机等移动终端结合起来。结合起来的方法,大体应该说是两类,一类就是直接在android手机上写native的程序,但是由于工具链的搭建比较复杂,再......