当前位置: 代码迷 >> C语言 >> [求助]看一看
  详细解决方案

[求助]看一看

热度:250   发布时间:2007-02-08 19:13:33.0
[求助]看一看
有4名学生每个学生考4门课程,要求在用户输入学生学号以后能输出该生的全部成绩..
怎么搞啊,,需要用什么知识点???
最好能把代码写出来..
谢谢大家!!!!
搜索更多相关的解决方案: 知识点  课程  用户  最好  

----------------解决方案--------------------------------------------------------
应该用二维数组就可以了吧.a[4][i] i是课程数.
----------------解决方案--------------------------------------------------------
#include <stdio.h>
main()
{
char choice;
printf("请输入学生号(A,B,C,D):");
choice=getchar();
switch(choice)
{
case 'A':
case 'a':
printf("英语=90,数学=80,化学=74,物理=92\n");
break;
case 'B':
case 'b':
printf("英语=80,数学=85,化学=84,物理=99\n");
break;
case 'C':
case 'c':
printf("英语=40,数学=35,化学=24,物理=19\n");
break;
case 'D':
case 'd':
printf("英语=60,数学=25,化学=83,物理=49\n");
break;
}
printf("程序运行结束\n");
getch();
}
----------------解决方案--------------------------------------------------------
以下是引用pc新手在2007-2-8 20:26:37的发言:
#include <stdio.h>
main()
{
char choice;
printf("请输入学生号(A,B,C,D):");
choice=getchar();
switch(choice)
{
case 'A':
case 'a':
printf("英语=90,数学=80,化学=74,物理=92\n");
break;
case 'B':
case 'b':
printf("英语=80,数学=85,化学=84,物理=99\n");
break;
case 'C':
case 'c':
printf("英语=40,数学=35,化学=24,物理=19\n");
break;
case 'D':
case 'd':
printf("英语=60,数学=25,化学=83,物理=49\n");
break;
}
printf("程序运行结束\n");
getch();
}

不会这么简单吧
----------------解决方案--------------------------------------------------------

用链表,成绩按链表格式在于文件里,输入学号时搜索链表然后输出。


----------------解决方案--------------------------------------------------------

我的不对吗


----------------解决方案--------------------------------------------------------
以下是引用pc新手在2007-2-8 20:41:33的发言:

我的不对吗

不是不对

是应该没这么简单


----------------解决方案--------------------------------------------------------

简单不好吗


----------------解决方案--------------------------------------------------------

我着里有个程序的样本 你自己按照要求可以加上名字拉,成绩拉什么的
/*注意如果你的程序不支持中文就运行不了这个程序,*/
#include"stdio.h"
#include<alloc.h>
struct fun{
int data;
struct fun *next;
}*h,*r,*s,*v;
void chazhao();
void charu();
void shanchu();
void jiaohuan(int);
void print();
main()
{
int num,x;
printf("程序样本,只能输入数字(输入-1结束输入);\n");
h=(struct fun*)malloc(sizeof(struct fun));
r=h;
scanf("%d",&x);
while(x!=-1)
{
s=(struct fun*)malloc(sizeof(struct fun));
s->data=x;
r->next=s;
r=s;
scanf("%d",&x);
}
r->next=NULL;
print();
printf("1.查找\n2.插入\n3.删除\n4.显示\n");
scanf("%d",&num);
printf("\n运行结果\n");
switch(num)
{
case 1: chazhao();break;
case 2: charu(); break;
case 3:shanchu();break;
case 4:print();break;

}
}
void chazhao()
{
struct fun *p;
int i=0,k=0;
p=h;
printf("要查找的数:");
scanf("%d",&i);
for(;p!=NULL&&p->data!=i;k++)
p=p->next;
if(p!=NULL)
printf("值为%d的元素已经找到,在链表位置%d\n",i,k);
else
printf("没有找到\n");
print();
}
void charu()
{
struct fun *p;
int num,sum,i;
p=h;
printf("插入的位置:数");
scanf("%d:%d",&num,&sum);
for(i=0;i<num-1&&p!=NULL;i++)
p=p->next;
if(p==NULL)
printf("错误\n");
else{
s=(struct fun*)malloc(sizeof(struct fun));
s->data=sum;
s->next=p->next;
p->next=s;
}
print();
}
void shanchu()
{
struct fun *p,*u;
int i,sum;
p=h;
printf("要删除的位置");
scanf("%d",&sum);
for(i=0;i<sum-1&&p!=NULL;i++)
p=p->next;
if(p==NULL)
printf("错误\n");
else
{
u=p->next;
p->next=u->next;
free(u);
}
print();
}
void print()
{
struct fun *p;
p=h;
for(;p->next!=NULL;)
{
p=p->next;
printf("%d\n",p->data);
}
}

[此贴子已经被作者于2007-2-8 21:54:15编辑过]


----------------解决方案--------------------------------------------------------
对拉 如果你还不会链表 我可以帮你在写一个
----------------解决方案--------------------------------------------------------
  相关解决方案