c语言编程,题目如图,麻烦会的亲写一下过程,谢谢
2个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NAME_LEN 256
#define MALE 0
#define FEMALE 1
typedef struct stu_st{
char name[NAME_LEN];
char sex;
int ch;
int en;
int math;
float avg;
void (*print_func)(struct stu_st *self);
}student_t;
static int
chk_sex(char sex)
{
if(sex == MALE || sex == FEMALE)
return 0;
else
return -1;
}
void
show_info(student_t *self)
{
char *sextbl[2] = {
"Male",
"Female",
};
if(!self)return;
fprintf(stdout, "%s, %s, %d, %d, %d, %f\n", self->name, sextbl[(int)self->sex], self->ch, self->en, self->math, self->avg);
}
student_t*
student_init(char *name, char sex, int ch, int en, int math)
{
student_t *stu = NULL;
float avg;
if(!name)goto FIN;
if(chk_sex < 0)goto FIN;
stu = (student_t*)malloc(sizeof(student_t));
if(!stu)goto FIN;
(void)memset(stu, 0x00, sizeof(student_t));
(void)strncpy(stu->name, name, strlen(name));
stu->sex = sex;
stu->ch = ch;
stu->en = en;
stu->math = math;
avg = (ch + en + math) / 3;
stu->avg = avg;
stu->print_func = &show_info;
FIN:
return stu;
}
int
main(int ac, char **av)
{
int i;
student_t *s[1] ={NULL};
for(i = 0; i < 1; i++){
s[i] = student_init("j",MALE,80,90,100);
if(!s[i])break;
s[i]->print_func(s[i]);
}
for(i = 0; i < 1; i++){
if(s[i]){
free(s[i]);
}
}
return 0;
}
展开全部
#include<stdio.h>
struct student
{
long number;
char name[80];
char sex;
int math;
int English;
int Chinese;
};
void main()
{
struct student stu[10];
int average[10];
for(int i=0;i<10;i++)
{
scanf("%ld %s %c %d %d %d",&stu[i].number,&stu[i].name,&stu[i].sex,&stu[i].English,&stu[i].math,&stu[i].Chinese);
average[i]=stu[i].Chinese+stu[i].English+stu[i].math;
}
printf("姓名\t性别\t英语\t数学\t语文\t平均分\n");
for(int j=0;j<10;j++){
printf("%s\t%4c\t%d\t%d\t%d\t%d\n",stu[j].name,stu[j].sex,stu[j].English,stu[j].math,stu[j].Chinese,average[j]/3);
}
}
struct student
{
long number;
char name[80];
char sex;
int math;
int English;
int Chinese;
};
void main()
{
struct student stu[10];
int average[10];
for(int i=0;i<10;i++)
{
scanf("%ld %s %c %d %d %d",&stu[i].number,&stu[i].name,&stu[i].sex,&stu[i].English,&stu[i].math,&stu[i].Chinese);
average[i]=stu[i].Chinese+stu[i].English+stu[i].math;
}
printf("姓名\t性别\t英语\t数学\t语文\t平均分\n");
for(int j=0;j<10;j++){
printf("%s\t%4c\t%d\t%d\t%d\t%d\n",stu[j].name,stu[j].sex,stu[j].English,stu[j].math,stu[j].Chinese,average[j]/3);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询