急求c语言大神输入成绩学号姓名查询成绩
发布网友
发布时间:2023-09-05 00:17
我来回答
共2个回答
热心网友
时间:2023-10-06 03:20
#include <stdio.h>
#include <string.h>
typedef struct{
int qq;
char string[1024];
}C语言;
int main(){
C语言 c = {563337217, "计算机C语言课程设计有偿助攻,看清楚了有偿助攻再加好友!\n总有穷*和傻*想不花钱让爹给你白写,你*以为你是谁啊。\n想让爹给你白写的滚一边去,省的挨骂!"};
printf("QQ:%d\n%s\n", c.qq, c.string);
return 0;
}
热心网友
时间:2023-10-06 03:21
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student
{
char name[12];
char student_id[12];
unsigned short Chinese;
unsigned short English;
unsigned short Math;
unsigned short average;
}student_t;
unsigned short num;
unsigned short pass_rate;
void enter_message(student_t *p);
void sort(student_t *p);
void print_message(student_t *p);
void swit_student(student_t *p,student_t *q);
void search_student(student_t *p);
int main(int argc, char const *argv[])
{
printf("Enter the number of students:");
scanf("%hu",&num);
student_t *p = NULL;
p = malloc(num * sizeof(student_t));
printf("Enter students message,example: name student_id Chinese English Math\n");
enter_message(p);
sort(p);
print_message(p);
printf("The pass_rate is %f\n",(pass_rate*1.0)/(num*1.0));
search_student(p);
free(p);
return 0;
}
void enter_message(student_t *p)
{
unsigned short i = 0;
student_t *temp = p;
while(i < num)
{
printf("Enter the %hu message:\n", i + 1);
scanf("%s %s %hu %hu %hu",temp->name,temp->student_id,&temp->Chinese,&temp->English,&temp->Math);
temp->average = (temp->Chinese + temp->English + temp->Math)/3;
if(temp->average > 60)
pass_rate++;
temp += 1;
i++;
}
}
void sort(student_t *p)
{
student_t *temp;
for (int i = 0; i < num; ++i)
for (int j = i+1; j < num; ++j)
if(p[i].average < p[j].average)
swit_student(&p[i],&p[j]);
temp = p;
printf("The bast student is:name:%s student_id:%s Chinese:%hu English:%hu Math:%hu average:%hu\n"
,temp->name,temp->student_id,temp->Chinese,temp->English,temp->Math,temp->average);
temp += num -1;
printf("The worst student is:name:%s student_id:%s Chinese:%hu English:%hu Math:%hu average:%hu\n"
,temp->name,temp->student_id,temp->Chinese,temp->English,temp->Math,temp->average);
}
void print_message(student_t *p)
{
unsigned short i = 0;
student_t *temp = p;
while(i < num)
{
printf("name:%s student_id:%s Chinese:%hu English:%hu Math:%hu average:%hu\n"
,temp->name,temp->student_id,temp->Chinese,temp->English,temp->Math,temp->average);
temp += 1;
i++;
}
}
void swit_student(student_t *p,student_t *q)
{
student_t temp;
strcpy(temp.name,p->name);
strcpy(p->name,q->name);
strcpy(q->name,temp.name);
strcpy(temp.student_id,p->student_id);
strcpy(p->student_id,q->student_id);
strcpy(q->student_id,temp.student_id);
temp.Chinese = p->Chinese;
p->Chinese = q->Chinese;
q->Chinese = temp.Chinese;
temp.English = p->English;
p->English = q->English;
q->English = temp.English;
temp.Math = p->Math;
p->Math = q->Math;
q->Math = temp.Math;
temp.average = p->average;
p->average = q->average;
q->average = temp.average;
}
void search_student(student_t *p)
{
char student_id[12] = {0};
printf("Pls enter the student_id\n");
scanf("%s",student_id);
for (int i = 0; i < num; ++i)
{
if(!strcmp(p[i].student_id,student_id))
printf("The student is:name:%s student_id:%s Chinese:%hu English:%hu Math:%hu average:%hu\n"
,p[i].name,p[i].student_id,p[i].Chinese,p[i].English,p[i].Math,p[i].average);
}
}
写的有点乱,时间有限,见谅。功能都给你实现了