首页 > 其他分享 >实验6

实验6

时间:2023-12-11 17:35:15浏览次数:27  
标签:head int void char 实验 printf Film


#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,N); 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,cnt = 0; for(i = 0;i<n;i++) if(s[i].total<60) t[cnt++] = s[i]; return cnt; } 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[i].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 {
    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_1

#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;
    }
}

task3_2

#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;    
    Film *p;       

    p = (Film *)malloc(sizeof(Film));
    p->next = NULL;
    head = p;       

    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->next;
        head->next = p;
    }

    return head;
}

void output(Film *head) {
    Film *p;

    p = head->next;
    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>
#define N 10

typedef struct {
    char isbn[20];          // isbn号
    char name[80];          // 书名
    char author[80];        // 作者
    double sales_price;     // 售价
    int  sales_count;       // 销售册数
} Book;

void output(Book x[], int n);
void sort(Book x[], int n);
double sales_amount(Book x[], int n);

int main() {
    Book x[N] = {{"978-7-229-14156-1", "源泉", "安.兰德", 84, 59},
                 {"978-7-5133-5261-1", "李白来到旧金山", "谭夏阳", 48, 16},
                 {"978-7-5617-4347-8", "陌生人日记", "周怡芳", 72.6, 27},
                 {"978-7-5722-5475-8", "芯片简史", "汪波", 74.9, 49},
                 {"978-7-5046-9568-0", "数据化决策", "道格拉斯·W·哈伯德", 49, 42},
                 {"978-7-5133-4388-6", "美好时代的背后", "凯瑟琳.布", 34.5, 39},
                 {"978-7-1155-0509-5", "无穷的开始:世界进步的本源", "戴维·多伊奇", 37.5, 55},
                 {"978-7-5321-5691-7", "何为良好生活", "陈嘉映", 29.5 , 31},
                 {"978-7-5133-5109-6", "你好外星人", "英国未来出版集团", 118, 42},
                 {"978-7-2011-4617-1", "世界尽头的咖啡馆", "约翰·史崔勒基", 22.5, 44}};
    
    printf("图书销量排名: \n");
    sort(x, N);
    output(x, N);

    printf("\n图书销售总额: %.2f\n", sales_amount(x, N));
    
    return 0;
}


void output(Book x[],int n){
    Book *p;
    printf("ISBN号               书名                           作者                   售价                 销售册数\n"); 
    for(p = x;p<x+n;p++){
        printf("%-20s %-30s %-20s %-20f %-20d\n",p->isbn,p->name,p->author,p->sales_price,p->sales_count);
    }
}



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


double sales_amount(Book x[],int n){
    double s = 0;
    Book *p;
    for(p = x;p<x+n;p++){
        s = s + p->sales_count*p->sales_price;
    }
    return s;
}

 

task 5

 

标签:head,int,void,char,实验,printf,Film
From: https://www.cnblogs.com/u3291193/p/17894958.html

相关文章

  • 实验六
    #include<stdio.h>#include<string.h>#defineN10typedefstruct{charisbn[20];//isbn号charname[80];//书名charauthor[80];//作者doublesales_price;//售价intsales_count;//销售册数......
  • 实验六 周天意 202383290417
    实验六实验内容1.实验任务1验证性实验。输入代码,结合运行结果,观察、理解以下用法:结构体类型的定义结构体数组的输入、输出、元素访问结构体数组作为函数参数结构体类型作为函数返回值类型问题场景描述:学生成绩包括:学号、姓名、课程名称、平时成绩、期中成绩、期末成绩、总评成......
  • 实验6_c语言结构体、枚举应用编程
    task4#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#defineN10typedefstruct{charisbn[20];charname[80];charauthor[80];doublesales_price;intsales_count;}Book;voidoutput(Bookx[],intn);voidsort(Bookx[],......
  • 实验六
    实验4#include<stdio.h>#defineN10typedefstruct{charisbn[20];//isbn号charname[80];//书名charauthor[80];//作者doublesales_price;//售价intsales_count;//销售册数}Book;voidou......
  • 实验六
    task41#include<stdio.h>2#defineN1034typedefstruct{5charisbn[20];//isbn号6charname[80];//书名7charauthor[80];//作者8doublesales_price;//售价9intsales_count;......
  • 实验6 C语言结构体、枚举应用编程
    实验任务4代码task4.c1#include<stdio.h>2#defineN1034typedefstruct{5charisbn[20];//isbn号6charname[80];//书名7charauthor[80];//作者8doublesales_price;//售价9intsale......
  • 实验六
    任务1//P286例8.17//对教材上的程序作了微调整,把输出学生信息单独编写成一个函数模块//打印不及格学生信息和所有学生信息程分别调用#include<stdio.h>#include<string.h>#defineN10//运行程序输入测试时,可以把这个数组改小一些输入测试typedefstructstudent{......
  • 实验6
    四、实验结论4.实验任务4此部分书写内容:正确补足后完整的task4.c源码,及,运行结果截图1#include<stdio.h>2#defineN1034typedefstruct{5charisbn[20];//isbn号6charname[80];//书名7charauthor[80];/......
  • 实验6
    task41#include<stdio.h>2#include<string.h>3#defineN104typedefstruct{5charisbn[20];6charname[80];7charauthor[80];8doublesales_price;9intsales_count;10}Book;11voidoutput(Book......
  • 实验三-电子公文传输系统1-个人贡献
    实验三-电子公文传输系统1-个人贡献1简述你完成的工作身为组长,组织组员相互配合,合理高效完成任务。参与组内文档的撰写工作。参与后端设计的代码编写以及前端设计的代码编写2你们小组总共的代码行数,你贡献的代码行数?相关代码链接?总共代码行数为55352行,其中大部分是gite......