日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言之学生成绩表

發布時間:2023/12/15 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言之学生成绩表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

練習:班主任需要在計算機中錄入n個同學的成績信息,信息包含(學號、姓名、性別、總成績、語文成績、英語成績、數學成績)。

程序在編寫時有如下要求:

1.? n由班主任確定,且使用malloc申請內存;

2. 學號以201805xx形式,姓名為英文名,語文成績、英語成績、數學成績由班主任輸入,總成績需要由程序計算;

?

程序在運行時打印提示功能信息,程序需要有如下功能:

1. 按學號升序;

2. 按總成績降序;

3. 輸入學生姓名,查詢學生信息,且程序具有檢查不合法姓名功能


環境:GCC,代碼如下:

#include <stdio.h>
#include <stdlib.h>


typedef struct Stu
{
int num;
char name[64];
char sex;
float total_score;
float chinsese_score;
float english_score;
float math_score;
}student;


int input_student_info(student *pstu, int n);
int print_student_info(student *pstu, int n);
int student_num_ascend(student *pstu, int n);
int score_total_descend(student *pstu, int n);
int query_studnet_info(char *stu_name, student *pstu, int n);


int main(int argc, const char *argv[])
{
int num, fun, quit;
student *pstu = NULL;
char query_name[64] = {0};


printf("Input the number of student!\n");
scanf("%d",&num);
pstu = (student *)malloc(sizeof(student) * num);
if(pstu == NULL)
{
printf("Malloc %d students mem fail!\n",num);
return 1;
}
input_student_info(pstu, num);
do
{
printf("\n");
printf("Which func do you want?\n");
printf("1:student num ascend print\n");
printf("2:stduent total score descend print\n");
printf("3:query single stduent infomation by name!\n");
printf("4:quit\n");
scanf("%d",&fun);


switch (fun)
{
case (1):
student_num_ascend(pstu, num);
print_student_info(pstu, num);
break;
case (2):
score_total_descend(pstu,num);
print_student_info(pstu, num);
break;
case (3):
printf("Input student name!\n");
scanf("%s",query_name);
query_studnet_info(query_name, pstu, num);
break;
case (4):
quit = 1;
break;
default:
printf("Input error!\n");
}


}while(quit == 0);


free(pstu);
pstu = NULL;


return 0;
}




int input_student_info(student *pstu, int n)
{
int i;


for(i = 0; i< n; i++)
{
printf("\n");
printf("Input %d student infomation as follow! \n",i+1);
printf("schoool_number name chinsese_score english_score math_score!\n");
scanf("%d %s %f %f %f",&(pstu+i)->num, (pstu+i)->name, &(pstu+i)->chinsese_score, &(pstu+i)->english_score, &(pstu+i)->math_score);
(pstu+i)->total_score = (pstu+i)->chinsese_score + (pstu+i)->english_score + (pstu+i)->math_score;
}


return 0;
}


int print_student_info(student *pstu, int n)
{
int i;


printf("\n");
printf("schoool_number name total_score chinsese_score english_score math_score!\n");
for(i = 0; i< n; i++)
{
printf("%d %s %f %f %f %f\n",(pstu+i)->num, (pstu+i)->name, (pstu+i)->total_score, (pstu+i)->chinsese_score, (pstu+i)->english_score, (pstu+i)->math_score);
}


return 0;
}
int student_num_ascend(student *pstu, int n)
{
int i, j;
student temp;
printf("\nstudent num ascend!\n");
for(i = n-1; i > 0; i--)
{
for(j = 0; j < i; j++)
{
if((pstu+j)->num > (pstu+j+1)->num)
{
temp = *(pstu+j);
*(pstu+j) = *(pstu+j+1);
*(pstu+j+1) = temp;
}
}
}


return 0;
}
int score_total_descend(student *pstu, int n)
{
int i, j;
student temp;


printf("\ntotal score descend!\n");
for(i = n-1; i > 0; i--)
{
for(j = 0; j < i; j++)
{
if((pstu+j)->total_score < (pstu+j+1)->total_score)
{
temp = *(pstu+j);
*(pstu+j) = *(pstu+j+1);
*(pstu+j+1) = temp;
}
}
}


return 0;
}
int query_studnet_info(char *stu_name, student *pstu, int n)
{
int i;


printf("\nquery single stduent infomation!\n");
for(i = 0; i< n; i++)
{
if(strcmp(stu_name,(pstu+i)->name) == 0)
{
printf("schoool_number name total_score chinsese_score english_score math_score!\n");
printf("%d %s %f %f %f %f\n",(pstu+i)->num, (pstu+i)->name, (pstu+i)->total_score, (pstu+i)->chinsese_score, (pstu+i)->english_score, (pstu+i)->math_score);
}
}


return 0;
}

總結

以上是生活随笔為你收集整理的C语言之学生成绩表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。