c语言函数调用成绩单 c语言实现成绩查询

C语言制作成绩单

#include stdio.hstruct stud

创新互联坚信:善待客户,将会成为终身客户。我们能坚持多年,是因为我们一直可值得信赖。我们从不忽悠初访客户,我们用心做好本职工作,不忘初心,方得始终。10多年网站建设经验创新互联是成都老牌网站营销服务商,为您提供成都网站制作、做网站、外贸营销网站建设、网站设计、H5高端网站建设、网站制作、品牌网站设计重庆小程序开发服务,给众多知名企业提供过好品质的建站服务。

{

int num;

char name[20];

float score1, score2, score3, aver;

}; int main(void)

{

int high;

int i, j;

struct stud myClass[10], *pStu = myClass;

struct stud temp; printf("Please input students info:Num Name score1 score2 score3\n");

for (i = 0; i 10; i++)

{

printf("%d:", i + 1);

scanf("%d %s %f %f %f", myClass[i].num, myClass[i].name, myClass[i].score1,

myClass[i].score2, myClass[i].score3);

myClass[i].aver = (myClass[i].score1 + myClass[i].score2 + myClass[i].score3) / 3;

} high = 0;

for (i = 0; i 10; i++)

{

if (myClass[i].aver myClass[high].aver)

{

high = i;

}

} printf("\nThe Highest is %s(%d)\nscore1=%.2f score2=%.2f score3=%.2f aver=%.2f\n",

myClass[high].name, myClass[high].num,

myClass[high].score1, myClass[high].score2, myClass[high].score3, myClass[high].aver); for (i = 0; i 9; i++)

{

for (j = i + 1; j 10; j++)

{

if ((pStu + j)-aver (pStu + i)-aver)

{

temp = *(pStu + j);

*(pStu + j) = *(pStu + i);

*(pStu + i) = temp;

}

}

} printf("\nResult of sort:\n");

printf("Num Name score1 score2 score3 average\n");

for (i=0; i10; i++)

{

printf("%-5d %-20s %-8.2f %-8.2f %-8.2f %-.2f\n", (pStu+i)-num, (pStu+i)-name,

(pStu+i)-score1, (pStu+i)-score2, (pStu+i)-score3, (pStu+i)-aver);

}

return 0;

}

C语言怎么输出一个成绩表

#include stdio.h

int main()

{

float score[2][2] = {0};

for (int i = 0; i  2; i++)

{

for (int j = 0; j  2; j++)

{

scanf("%f", score[i][j]);

}

}

printf("----------------------\n");

printf("序号语文  数学  总成绩\n");

printf("----------------------\n");

for (int i = 0; i  2; i++)

{

printf("%-4d%-6.1f%-6.1f%6.1f\n", i + 1, score[i][0], score[i][1], score[i][0] + score[i][1]);

}

return 0;

}

//测试输出:

//80.0

//90.5

//90.5

//70.5

//----------------------

//序号语文  数学  总成绩

//----------------------

//1   80.0  90.5   170.5

//2   90.5  70.5   161.0

怎么用C语言编一个学生成绩记录簿?

#includestdio.h

#includestdlib.h

#includestring.h

typedef struct

{

char id[15];

char name[10];

int score;

} StudentInfo;

typedef struct

{

StudentInfo arr[100];

int length;

} SeqList;

FILE *fp;

char *filePath = "C:/StudentInfo.txt";

void initSeqList(SeqList *L)

{

L-length = 0;

}

void insertSeqList(SeqList *L, int i, StudentInfo info)å

{

int j;

for(j = L-length; j i; j--)

L-arr[j] = L-arr[j-1];

L-arr[j] = info;

L-length++;

}

void printStudentInfo(StudentInfo info)

{

printf("%s\t%s\t%d\n", info.id, info.name, info.score);

}

void printSeqListWithSeqNo(SeqList L)

{

for(int i = 0; i L.length; i++)

{

printf("%d\t", i+1);

printStudentInfo(L.arr[i]);

}

}

void printSeqList(SeqList L)

{

for(int i = 0; i L.length; i++)

printStudentInfo(L.arr[i]);

}

int queryInfoById(SeqList L, char *id)

{

for(int i = 0; i L.length; i++)

if(strcmp(id, L.arr[i].id)==0)

return i;

return -1;

}

int queryInfoByName(SeqList L, char *name)

{

for(int i = 0; i L.length; i++)

if(strcmp(name, L.arr[i].name)==0)

return i;

return -1;

}

void save2File(SeqList L)

{

fp = fopen(filePath, "w");

for (int i = 0; i L.length; i++)

fprintf(fp, "%s\t%s\t%d\n", L.arr[i].id, L.arr[i].name, L.arr[i].score);

}

void showMenu(SeqList L);

void addInfo(SeqList L)

{

StudentInfo info;

int index;

do {

printf("请输入学号:");

scanf("%s", info.id);

index = queryInfoById(L, info.id);

if (index != -1)

{

printf("输入的学号已存在。\n");

printStudentInfo(L.arr[index]);

}

} while(index != -1);

do {

printf("请输入姓名:");

scanf("%s", info.name);

index = queryInfoByName(L, info.name);

if(index != -1)

{

printf("输入的姓名已存在。\n");

printStudentInfo(L.arr[index]);

}

} while(index != -1);

printf("请输入成绩:");

scanf("%d", info.score);

L.arr[L.length] = info;

L.length++;

save2File(L);

}

void editInfo(SeqList L)

{

StudentInfo info;

char choice;

printf("1. 按学号修改\n2. 按姓名修改\n3. 返回上一层\n");

while((choice=getchar())=='\n');

int index;

if(choice == '1' || choice == '2')

{

if(choice == '1')

{

printf("请输入学号:");

scanf("%s", info.id);

index = queryInfoById(L, info.id);

} else {

printf("请输入姓名:");

scanf("%s", info.name);

index = queryInfoByName(L, info.name);

}

if(index != -1)

printStudentInfo(L.arr[index]);

else {

printf("%s 为 %s 的学生不存在\n", choice==1?"学号":"姓名", choice==1?info.id:info.name);

editInfo(L);

return;

}

printf("成绩改为:");

scanf("%d", L.arr[index].score);

save2File(L);

}else if(choice == '3')

showMenu(L);

else {

printf("选择有误,请重新选择\n");

editInfo(L);

return;

}

}

void insertSort(SeqList *L)

{

for(int j = 1; j L-length; j++)

{

StudentInfo key = L-arr[j];

int i = j - 1;

while(i = 0 L-arr[i].score key.score)

{

L-arr[i+1] = L-arr[i];

i--;

}

L-arr[i+1] = key;

}

}

void statisticInfo(SeqList L)

{

// 显示 60 分以下、60~79、80~89、90 分以上各分数段的学生信息

SeqList sectionListArr[4];

for (int i = 0; i 4; i++)

initSeqList(sectionListArr[i]);

float sum = 0, average, passedRate;

for (int i = 0; i L.length; i++)

{

int score = L.arr[i].score;

sum += score;

if(score 60)

insertSeqList(sectionListArr[0], sectionListArr[0].length, L.arr[i]);

else if(score = 60 score 80)

insertSeqList(sectionListArr[1], sectionListArr[1].length, L.arr[i]);

else if(score = 80 score 90)

insertSeqList(sectionListArr[2], sectionListArr[2].length, L.arr[i]);

else insertSeqList(sectionListArr[3], sectionListArr[3].length, L.arr[i]);

}

average = sum/L.length;

passedRate = (L.length-sectionListArr[0].length)*100.0/L.length;

insertSort(L);

printf("60 分以下的学生:\n");

printSeqList(sectionListArr[0]);

printf("\n60 ~ 79 分的学生:\n");

printSeqList(sectionListArr[1]);

printf("\n80 ~ 89 分的学生:\n");

printSeqList(sectionListArr[2]);

printf("\n90 分以上的学生:\n");

printSeqList(sectionListArr[3]);

printf("\n及格率:%.1f %%\n平均分:%.1f\n", passedRate, average);

printf("按顺序从高到低排序:\n");

insertSort(L);

printSeqListWithSeqNo(L);

printf("\n最高分:\n");

printStudentInfo(L.arr[0]);

printf("\n最低分:\n");

printStudentInfo(L.arr[L.length-1]);

}

void queryInfo(SeqList L)

{

char choice;

printf("1. 按学号查询\n2. 按姓名查询\n3. 返回上层\n");

while((choice=getchar())=='\n');

int index;

if (choice == '1')

{

char id[15];

printf("请输入学号:");

scanf("%s", id);

index = queryInfoById(L, id);

} else if(choice == '2') {

char name[10];

printf("请输入姓名:");

scanf("%s", name);

index = queryInfoByName(L,name);

} else if(choice == '3') {

showMenu(L);

return;

} else {

printf("选择有误,请重新选择\n");

queryInfo(L);

return;

}

if(index == -1)

printf("没有查询到结果\n");

else

printStudentInfo(L.arr[index]);

}

void showMenu(SeqList L)

{

char choice;

printf("\n1. 查询\n2. 添加成绩\n3. 修改成绩\n4. 统计分析\n5. 退出\n");

while((choice = getchar()) == '\n');

switch(choice)

{

case '1': queryInfo(L); break;

case '2': addInfo(L); break;

case '3': editInfo(L); break;

case '4': statisticInfo(L); break;

case '5': exit(0);

}

}

int main(void)

{

StudentInfo temp;

SeqList *L = (SeqList*)malloc(sizeof(SeqList));

do {

initSeqList(L);

fp = fopen(filePath, "r");

int i = 0;

while(fscanf(fp, "%s%s%d", temp.id, temp.name, temp.score) != EOF)

insertSeqList(L, i++, temp);

showMenu(*L);

fclose(fp);

}while(1);

return 0;

}

在c语言中用调用函数求三个同学三科的总成绩,怎么编程

#include stdio.h 

#define N 100

/*定义学生结构体*/    

struct Student    

{    

int  ID;   

char Name[20];   

float Mark1;    

float Mark2;  

float Mark3; 

float Sum;    

};   

/*声明学生数组及学生数量*/    

struct Student students[N];    

//int num=0;  

/*求总分*/    

float Sums(struct Student stu)   

{    

return stu.Mark1+stu.Mark2+stu.Mark3;  

}    

/*输入学生信息*/    

int Student_Input(){  

int num=0;

while(1){    

//printf("请输入学号:");   

students[num].ID=num+1; //可以自行将学号改为手工输入

printf("请输入姓名:"); 

scanf("%s",students[num].Name);  

getchar();  

printf("请输入成绩1:"); 

scanf("%f",students[num].Mark1); 

getchar();  

printf("请输入成绩2:"); 

scanf("%f",students[num].Mark2); 

printf("请输入成绩3:"); 

scanf("%f",students[num].Mark3); 

getchar();  

students[num].Sum=Sums(students[num]);   

num++;  

printf("是否继续?(y/n)"); //继续输入数据?

if (getchar()=='n'){  

break;  

}    

}  

return num;  

}  

/*输出学生信息*/   

void Student_Display(int n)   

{   

int i;    

printf("%10s%10s%8s%8s%8s%8s\n","学号","姓名","成绩","成绩","成绩","总成线");  

printf("---------------------------------------------------------\n");  

for (i=0;in;i++)  

{  

printf("%10d%10s%8.2f%8.2f%8.2f%8.2f\n",students[i].ID,students[i].Name,  

students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Sum);  

}  

/*主程序*/    

int  main(){ 

int n=0;

n=Student_Input();

Student_Display(n); 

return 0;  

}


分享名称:c语言函数调用成绩单 c语言实现成绩查询
浏览路径:http://hbruida.cn/article/ddgejcd.html