设计题目:用C语言实现成绩统计程序的设计 〔问题描述〕给出n个学生的

设计题目:用C语言实现成绩统计程序的设计 〔问题描述〕给出n个学生的,第1张

以前做过一个差不多的程序(不过是用链表实现的) 跟你稍微改了下

用了3个文件(改成一个也很简单的^_^)

希望你用的上吧^_^

文件listh

#ifndef _LIST_H

#define _LIST_H

struct Student

{

char szName[20]; // 姓名

int nScore1; // 科目1

int nScore; // 科目2

int nNumber; //平均分

////

Student pNext; // 指针

};

// 声明链表头指针

extern Student g_pHead;

Student CreateNode();

void AddToTail(Student pNew);

void AddToHead(Student pNew);

void InsertNode(Student pNew);

void DeleteNode(int nNumber);

Student FindNode(int nNumber);

void ShowList();

void FreeList();

void Save();

void Load();

void Init();

文件listcpp

#include <stdioh>

#include "Listh"

// 定义链表头指针

Student g_pHead = NULL;

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

Student CreateNode()

{

printf("请输入姓名,科目1,科目2:");

Student pNew = new Student;

scanf("%s",pNew->szName);

scanf("%d",&pNew->nScore1);

scanf("%d",&pNew->nScore);

pNew->nNumber = (pNew->nScore1 + pNew->nScore)/2;

pNew->pNext = NULL;

return pNew;

}

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

void AddToTail(Student pNew)

{

if (g_pHead == NULL) // 空链表

{

g_pHead = pNew;

}

else // 非空链表

{

Student pTail = g_pHead;

while (pTail->pNext != NULL)

{

pTail = pTail->pNext;

}

pTail->pNext = pNew;

}

}

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

void AddToHead(Student pNew)

{

if (g_pHead == NULL) // 空链表

{

g_pHead = pNew;

}

else // 非空链表

{

pNew->pNext = g_pHead;

g_pHead = pNew;

}

}

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

void InsertNode(Student pNew)

{

if (g_pHead == NULL) // 空链表

{

g_pHead = pNew;

}

else if (pNew->nNumber > g_pHead->nNumber) // 比头节点小

{

pNew->pNext = g_pHead;

g_pHead = pNew;

}

else // 其他非空普通情况

{

Student pCur = g_pHead;

while (pCur->pNext != NULL)

{

if (pCur->nNumber >= pNew->nNumber &&

pCur->pNext->nNumber < pNew->nNumber)

{

// 找到了,在此处插入

pNew->pNext = pCur->pNext;

pCur->pNext = pNew;

break;

}

else

{

pCur = pCur->pNext;

}

} // end of while

// 处理比尾节点还大的情况

if ((pCur->pNext == NULL) // 必须的!!!

&&(pNew->nNumber < pCur->nNumber))

{

pCur->pNext = pNew;

}

} // end of if-else

}

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

void DeleteNode(int nNumber)

{

Student pCur = g_pHead;

Student pPre = g_pHead;

while (pCur != NULL)

{

if (pCur->nNumber == nNumber)

{

// 找到了,删除他

pPre->pNext = pCur->pNext;

if (pCur == g_pHead)

{

g_pHead = pPre->pNext;

delete pCur;

}

else

{

delete pCur;

}

break; // !!!

}

else

{

pPre = pCur; // !!!

pCur = pCur->pNext;

}

}

}

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

Student FindNode(int nNumber)

{

Student pCur = g_pHead;

while (pCur != NULL)

{

if (pCur->nNumber == nNumber)

break;

pCur = pCur->pNext;

}

return pCur;

}

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

void ShowList()

{

Student pTail = g_pHead;

while(pTail != NULL)

{

printf("姓名:%s,科目1:%d,科目2:%d,平均分:%d\n",

pTail->szName,

pTail->nScore1,

pTail->nScore,

pTail->nNumber);

pTail = pTail->pNext;

}

}

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

void FreeList()

{

Student pTail = g_pHead;

while (pTail != NULL)

{

Student pTemp = pTail->pNext;

delete pTail;

pTail = pTemp;

}

g_pHead = NULL;

}

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

void Save()

{

FILE pf = fopen("studenttxt", "w");

Student pTail = g_pHead;

while(pTail != NULL)

{

fprintf(pf, "%s %d %d %d\n",

pTail->szName,

pTail->nScore1,

pTail->nScore,

pTail->nNumber);

pTail = pTail->pNext;

}

fclose(pf);

}

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

void Load()

{

FILE pf = fopen("studenttxt", "r");

while(NULL != pf)

{

Student pNew = new Student;

pNew->pNext = NULL;

fscanf(pf, "%s",pNew->szName);

fscanf(pf, "%d",&pNew->nScore1);

fscanf(pf, "%d",&pNew->nScore);

int nRes = fscanf(pf, "%d",&pNew->nNumber);

if(nRes == EOF)break;

InsertNode(pNew);

}

fclose(pf);

}

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

void Init()

{

printf("\t\t学员管理系统\n\n");

printf("\t1新增学员\n");

printf("\t2删除学员\n");

printf("\t3查找学员\n");

printf("\t4显示全部学员\n");

printf("\t5保存到文件\n");

printf("\t6从文件中读取\n\n");

}

文件maincpp

#include <stdioh>

#include "listh"

void main(void)

{

int nN = 0; //菜单选择

int nNumber = 0;

Student FTemp, pNew;

Init();

while(1)

{

printf("请选择 *** 作: \b\b\b");

scanf("%d", &nN);

switch(nN)

{

case 1:

pNew = CreateNode();

InsertNode(pNew);

printf("\n");

break;

case 2:

printf("请输入欲删除的学生的平均分:");

scanf("%d", &nNumber);

DeleteNode(nNumber);

printf("删除完毕\n\n");

break;

case 3:

printf("请输入欲查找的学生的平均分:");

scanf("%d", &nNumber);

FTemp = FindNode(nNumber);

if( FTemp != NULL )

{

printf("姓名:%s 科目1:%d 科目2:%d 平均分\n:%d",

FTemp->szName,

FTemp->nScore1,

FTemp->nScore,

FTemp->nNumber);

printf("\n");

}

break;

case 4:

ShowList();

printf("\n");

break;

case 5:

Save();

printf("保存完毕\n\n");

break;

case 6:

Load();

printf("读取完毕\n\n");

break;

}

}

}

#include<stdioh>

main()

{

int a[30],max,min,average,h=0,s1=0,s2=0,s3=0,s4=0,s5=0,i;

for(i=0;i<30;i++)

{

scanf("%d",a[i]);

if(a[i]<=59&&a[i]>=0) s1++;

if(a[i]<=69&&a[i]>=60 s2++;

if(a[i]<=79&&a[i]>=70) s3++;

if(a[i]<=89&&a[i]>=80) s4++;

if(a[i]<=100&&a[i]>=90) s5++;

}

max=min=a[0];averae=0;

for(i=0;i<30;i++)

{

if(min>a[i]) min=a[i];

if(max<a[i]) max=a[i];

h=h+a[i];

}

average=h/30;

printf("0~59的人数:%d\n60~69的人数:%d\n70~79的人数:%d\n80~89的人数%d/n90~100的人数:%d\n",s1,s2,s3,s4,s5);

printf("最高分:%d\n最低分:%d\n平均分:%d\n",max,min,average);

}

改好了,问题不大,我都写在注释里了:

#include<stdioh>

#include<mathh>

#define N 35

#define COURSE 4

struct student

{

char num[10];/如果把num当作字符串的话,不能用int,而是char数组。不然就用int num;/

float score[4];

float sum;

float aver;

}

stu[N];

void main()

{

void Input(struct student stu[]);

void count(struct student stu[]);

void sort(struct student stu[]);

void find(struct student stu[]);

sqrt(10);/不知你用什么编译器,如果TC的话,有个BUG。就是结构体里有float型的话,要加这句,不然会报错/

Input(stu);

count(stu);

find(stu);

/为什么你的程序里没有执行着几个函数咧/

}

void Input(struct student stu[])

{

int i,j;

printf("Enter Noand score as :score1 score2 score3 score4\n");

for (i=0;i<N;i++)

{

scanf("%s",stu[i]num);/用%s输入字符串/

for (j=0;j<COURSE;j++)

{

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

}

}

}

void count(struct student stu[])

{

float sum,aver;

int i,j;

for(i=0;i<N;i++)

{

sum=0;

for(j=0;j<5;j++)

sum+=stu[i]score[j];

aver=sum/4;

stu[i]sum=sum;

stu[i]aver=aver;

}

}

void sort(struct student stu[])

{

int i,j,k;

struct student temp;

for(i=0;i<N;i++)

{

k=i;

for(j=i+1;j<N;j++)

if(stu[k]sum<stu[j]sum)k=j;

if(k!=i)

{

temp=stu[i];

stu[i]=stu[k];

stu[k]=temp;

}

}

printf("number score1 score2 score3 score4 sum average \n");

for(i=0;i<N;i++)

printf("%-8s%-82f%-82f%-82f%-82f%-82f%-82f\n",stu[i]num,stu[i]score[0],stu[i]score[1],stu[i]score[2],stu[i]score[3],stu[i]sum,stu[i]aver);

/输出学号也用%s/

}

void find(struct student stu[])

{

int flag=0;

int i,j;

sort(stu) /;//stu[];)/

printf("the student of one score>=90 and 前五名:\n");

/这两句调换一下位置,不然输出不太好/

for(i=0;i<5;i++)

{

int sum=0;

for(j=0;j<4;j++)

if(stu[i]score[j]>=90 )sum++;

if(sum)

{

flag=1;

printf("%-8s%-82f%-82f%-82f%-82f%-82f%-82f\n",stu[i]num,stu[i]score[0],stu[i]score[1],stu[i]score[2],stu[i]score[3],stu[i]sum,stu[i]aver);

}

}

if(flag==0)

printf(" not exist!\n");

/这个判断放在循环体之外,不然会输出好多" not exist!"/

}

另外,注意:

1个班的学生成绩最多35人。你的咋是固定35人捏?

2第四点要求:根据用户要求输入课程号显示该门课程成绩在90以上且总分在前五的学生的 学号和各科成绩,平均分和总分

你似乎没有看清题意吧?是要用户输入课程号耶。

这些你自己应该知道怎么做吧?

#include <malloch>

#include <stdioh>

#include <stdlibh>

#include <stringh>

#define NULL 0

#define MaxSize 30

typedef struct athletestruct /运动员/

{

char name[20];

int score; /分数/

int range; //

int item; /项目/

}ATH;

typedef struct schoolstruct /学校/

{

int count; /编号/

int serial; //

int menscore; /男选手分数/

int womenscore; /女选手分数/

int totalscore; /总分/

ATH athlete[MaxSize]; //

struct schoolstruct next;

}SCH;

int nsc,msp,wsp;

int ntsp;

int i,j;

int overgame;

int serial,range;

int n;

SCH head,pfirst,psecond;

int phead=NULL,pafirst=NULL,pasecond=NULL;

input ()

{

char answer;

head = (SCH )malloc(sizeof(SCH)); //

head->next = NULL;

pfirst = head;

answer = 'y';

while ( answer == 'y' )

{

Is_Game_DoMain:

printf("\nGET Top 5 when odd\nGET Top 3 when even");

printf("\n输入运动项目序号 (x<=%d):",ntsp);

scanf("%d",pafirst);

overgame = pafirst;

if ( pafirst != phead )

{

for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )

{

if ( overgame == pasecond )

{

printf("\n这个项目已经存在请选择其他的数字\n");

goto Is_Game_DoMain;

}

}

}

pafirst = pafirst + 1;

if ( overgame > ntsp )

{

printf("\n项目不存在");

printf("\n请重新输入");

goto Is_Game_DoMain;

}

switch ( overgame%2 )

{

case 0: n = 3;break;

case 1: n = 5;break;

}

for ( i = 1 ; i <= n ; i++ )

{

Is_Serial_DoMain:

printf("\n输入序号 of the NO%d (0<x<=%d): ",i,nsc);

scanf("%d",&serial);

if ( serial > nsc )

{

printf("\n超过学校数目,请重新输入");

goto Is_Serial_DoMain;

}

if ( head->next == NULL )

{

create();

}

psecond = head->next ;

while ( psecond != NULL )

{

if ( psecond->serial == serial )

{

pfirst = psecond;

pfirst->count = pfirst->count + 1;

goto Store_Data;

}

else

{

psecond = psecond->next;

}

}

create();

Store_Data:

pfirst->athlete[pfirst->count]item = overgame;

pfirst->athlete[pfirst->count]range = i;

pfirst->serial = serial; ("Input name:) : ");

scanf("%s",pfirst->athlete[pfirst->count]name);

}

printf("\n继续输入运动项目(y&n)?");

answer = getch();

printf("\n");

}

}

calculate() //

{

pfirst = head->next;

while ( pfirst->next != NULL )

{

for (i=1;i<=pfirst->count;i++)

{

if ( pfirst->athlete[i]item % 2 == 0 )

{

switch (pfirst->athlete[i]range)

{

case 1:pfirst->athlete[i]score = 5;break;

case 2:pfirst->athlete[i]score = 3;break;

case 3:pfirst->athlete[i]score = 2;break;

}

}

else

{

switch (pfirst->athlete[i]range)

{

case 1:pfirst->athlete[i]score = 7;break;

case 2:pfirst->athlete[i]score = 5;break;

case 3:pfirst->athlete[i]score = 3;break;

case 4:pfirst->athlete[i]score = 2;break;

case 5:pfirst->athlete[i]score = 1;break;

}

}

if ( pfirst->athlete[i]item <=msp )

{

pfirst->menscore = pfirst->menscore + pfirst->athlete[i]score;

}

else

{

pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i]score;

}

}

pfirst->totalscore = pfirst->menscore + pfirst->womenscore;

pfirst = pfirst->next;

}

}

output()

{

pfirst = head->next;

psecond = head->next;

while ( pfirst->next != NULL )

{

clrscr();

printf("\n第%d号学校的结果成绩:",pfirst->serial);

printf("\n\n项目的数目\t学校的名字\t分数");

for (i=1;i<=ntsp;i++)

{

for (j=1;j<=pfirst->count;j++)

{

if ( pfirst->athlete[j]item == i )

{

printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j]name,pfirst->athlete[j]score);break;

}

}

}

printf("\n\n\n\t\t\t\t\t\t按任意建 进入下一页");

getch();

pfirst = pfirst->next;

}

clrscr();

printf("\n运动会结果:\n\n学校编号\t男运动员成绩\t女运动员成绩\t总分");

pfirst = head->next;

while ( pfirst->next != NULL )

{

printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);

pfirst = pfirst->next;

}

printf("\n\n\n\t\t\t\t\t\t\t按任意建结束");

getch();

}

create()

{

pfirst = (struct schoolstruct )malloc(sizeof(struct schoolstruct));

pfirst->next = head->next ;

head->next = pfirst ;

pfirst->count = 1;

pfirst->menscore = 0;

pfirst->womenscore = 0;

pfirst->totalscore = 0;

}

void Save()

{FILE fp;

if((fp = fopen("schooldat","wb"))==NULL)

{printf("can't open schooldat\n");

fclose(fp);

return;

}

fwrite(pfirst,sizeof(SCH),10,fp);

fclose(fp);

printf("文件已经成功保存\n");

}

main()

{

system("cls");

printf("\n\t\t\t 运动会分数统计\n");

printf("输入学校数目 (x>= 5):");

scanf("%d",&nsc);

printf("输入男选手的项目(x<=20):");

scanf("%d",&msp);

printf("输入女选手项目(<=20):");

scanf("%d",&wsp);

ntsp = msp + wsp;

phead = calloc(ntsp,sizeof(int));

pafirst = phead;

pasecond = phead;

input();

calculate();

output();

Save();

}

#include "stdioh"

void main()

{

int i,Max=-1,Min=999,Score,x,y;

double Sum=0,a[10],Max2=-1,Min2=999,z;

printf("练习30题_6:歌星比赛评分:\n");

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

{

printf("第%d位评委打分:\n",i);

scanf("%d",&Score);

a[i]=Score;

Sum+=Score;

if(Score>Max)Max=Score;

if(Score<Min)Min=Score;

}

printf("%s%d\n%s%d\n%s%f\n","去掉一个最高分",Max,"去掉一个最低分",Min,"得出的分数为:",(Sum-Min-Max)/8);

z=(Sum-Min-Max)/8;

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

{

if(a[i]-z>0)//等于0就是差距最小的了所以不用在max上

if(a[i]-z>Max2)

{

Max2=a[i]-z;

x=i;

}

else if (z-a[i]>0)

if(z-a[i]>Max2)

{

Max2=z-a[i];

x=i;

}

if(a[i]-z>=0)

if(a[i]-z<Min2)

{

Min2=a[i]-z;

y=i;

}

else if (z-a[i]>=0)

if(z-a[i]<Min2)

{

Min2=z-a[i];

y=i;

}

}

printf("思维延伸:最公平的裁判是:第%d位。\n最不公平的裁判是:第%d位。\n",y,x);//以上代码没写并列情况

}

#include<stdioh>

void main()

printf("input a score:\n");

scanf("%f",&score);

if(score>=0&&score<60)

count[0]++;

if(score>=60&&score<70)

count[1]++;

if(score>=70&&score<80)

count[2]++;

if(score>=80&&score<90)

count[3]++;

if(score>=90&&score<=100)

count[4]++;

}

printf("0~60:%d\n60~70:%d\n70~80:%d\n80~90:%d\n90~100:%d\n",count[0],count[1],count[2],count[3],count[4]);

}

机器语言

在计算机系统中,一条机器指令规定了计算机系统的一个特定动作。一个系列的计算机在硬件设计制造时就用了若干指令规定了该系列计算机能够进行的基本 *** 作,这些指令一起构成了该系列计算机的指令系统。

在计算机应用的初期,程序员使用机器的指令系统来编写计算机应用程序,这种程序称为机器语言程序。使用机器语言编写的程序,由于每条指令都对应计算机一个特定的基本动作,所以程序占用内存少、执行效率高。

以上就是关于设计题目:用C语言实现成绩统计程序的设计 〔问题描述〕给出n个学生的全部的内容,包括:设计题目:用C语言实现成绩统计程序的设计 〔问题描述〕给出n个学生的、用C语言求 输入30个成绩数据,统计各分数段(0~59,60~69,70~79,80~89,90~100)的人数,最高分,最低分和平均分.、用c语言设计一个程序统计一个班的学生成绩等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10630366.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存