c语言 设计一个二维数组储存学生的四门课成绩,要求从键盘输入学生学号,输出该生的所有课成绩。

c语言 设计一个二维数组储存学生的四门课成绩,要求从键盘输入学生学号,输出该生的所有课成绩。 求源程序》》》

第1个回答  2010-12-21
#include<iostream>
#include<cstring>
using namespace std;
struct date
{
int year;
int moonth;
int day;
};

struct score
{
float chinese;
float macth;
float english;
float history;
};

struct student
{int shu;
char name[20];
char sex[20];
struct date brithday;
struct score fen;
}stu[100];

void start();
int find(int n);
void edit();
void chu();

int main()
{
pf:
cout<<"*********************************************"<<endl;
cout<<"* 选择服务 * "<<endl;
cout<<"* 1-输入学生信息 * "<<endl;
cout<<"* 2-查找学生信息 * "<<endl;
cout<<"* 3-修改学生信息 * "<<endl;
cout<<"* 4-删除学生信息 * "<<endl;
cout<<"* 5-退出 * "<<endl;
cout<<"*********************************************"<<endl;
int menu,num,choice;
cout<<"请输入要选择的项目"<<endl;
cin>>menu;
system("cls");
switch(menu)
{
case 1:
{
start();
system("cls");
goto pf;
break;
}
case 2:
{
cout<<"请输入一个学号"<<endl;
cin>>num;
choice=find(num);
if(choice!=-1)
{
cout<<" 学号:"<<stu[choice].shu<<endl;
cout<<" 姓名:"<<stu[choice].name<<endl;
cout<<" 性别:"<<stu[choice].sex<<endl;
cout<<stu[choice].brithday.year;
cout<<"年";
cout<<stu[choice].brithday.moonth;
cout<<"月";
cout<<stu[choice].brithday.day;
cout<<"日"<<endl;
cout<<"语文:"<<stu[choice].fen.chinese<<endl;
cout<<"数学:"<<stu[choice].fen.macth<<endl;
cout<<"英语:"<<stu[choice].fen.english<<endl;
cout<<"历史:"<<stu[choice].fen.history<<endl;
}
else
cout<<"输入有误,请从新输入"<<endl;
system("pause");
goto pf;
break;
}
case 3:
{
edit();
system("cls");
goto pf;
break;
}
case 4:
{
chu();
system("cls");
goto pf;
break;
}
case 5:
{
cout<<" 谢谢使用"<<endl;
break;
}
default:
{
cout<<"输入有误,请从新输入"<<endl;
goto pf;
break;
}
}
return 0;
}

void start()
{
int i;
char m;
for(i=0;i<=100;i++)
{
cout<<"请输入学号:";
cin>>stu[i].shu;
cout<<endl;
cout<<"姓名:";
cin>>stu[i].name;
cout<<endl;
cout<<"性别:";
cin>>stu[i].sex;
cout<<endl;
cout<<"年";
cin>>stu[i].brithday.moonth;
cout<<endl;
cout<<"月";
cin>>stu[i].brithday.moonth;
cout<<"日";
cin>>stu[i].brithday.day;
cout<<endl;
cout<<"语文:";
cin>>stu[i].fen.chinese;
cout<<endl;
cout<<"数学:";
cin>>stu[i].fen.macth;
cout<<endl;
cout<<"英语:";
cin>>stu[i].fen.english;
cout<<endl;
cout<<"历史:";
cin>>stu[i].fen.history;
cout<<endl;
cout<<"是否继续(y/n)?"<<endl;
cin>>m;
if(m=='n')
break;
}
}

int find(int n)
{
int i;
for(i=0;i<=100;i++)
{
if(stu[i].shu==n)
return i;
else
return -1;
break;
}
}

void edit()
{
int a,b,temp;
int s1;
float y1,y2,y3;
float a1,a2,a3,a4;
char s2[20];
char s3[20];
cout<<"请输入一个学号"<<endl;
cin>>a;
temp=find(a);
if(a!=-1)
{

b:
cout<<"*******************************"<<endl;
cout<<" 1-修改学号 "<<endl;
cout<<" 2-修改名字 "<<endl;
cout<<" 3-修改性别 "<<endl;
cout<<" 4-修改出生年月 "<<endl;
cout<<" 5-修改成绩 "<<endl;
cout<<" 6-退出 "<<endl;
cout<<"*******************************"<<endl;
cin>>b;
switch(b)
{
case 1:
{
cout<<"请输入要修改的学号:"<<endl;
cin>>s1;
stu[temp].shu=s1;
system("pause");
goto b;
break;
}
case 2:
{
cout<<"请输入要修改的名字:"<<endl;
cin>>s2;
strcpy(stu[temp].name,s2);
system("pause");
goto b;
break;
}
case 3:
{
cout<<"请输入要修改的性别:"<<endl;
cin>>s3;
strcpy(stu[temp].sex,s3);
system("pause");
goto b;
break;
}
case 4:
{
cout<<"年 ";
cin>>y1;
stu[temp].brithday.year=y1;
cout<<endl;
cout<<"月 ";
cin>>y2;
stu[temp].brithday.moonth=y2;
cout<<endl;
cout<<"日 ";
cin>>y3;
stu[temp].brithday.day;
cout<<endl;
system("pause");
goto b;
break;
}
case 5:
{
cout<<"语文:";
cin>>a1;
stu[temp].fen.chinese=a1;
cout<<endl;
cout<<"数学:";
cin>>a2;
stu[temp].fen.macth=a2;
cout<<"英语:";
cin>>a3;
stu[temp].fen.english=a3;
cout<<endl;
cout<<"历史:";
cin>>a4;
stu[temp].fen.history;
cout<<endl;
system("pause");
goto b;
break;
}
default:
{
cout<<"谢谢使用"<<endl;
break;
}
}
}
else
cout<<"输入有误,请从新输入"<<endl;
}

void chu()
{
int a,b;
cout<<"请输入一个学号"<<endl;
cin>>a;
b=find(a);
if(a!=-1)
{
stu[b].shu=0;
stu[b].name[0]='0';
stu[b].sex[0]='0';
stu[b].brithday.year=0;
stu[b].brithday.moonth=0;
stu[b].brithday.day=0;
stu[b].fen.chinese=0;
stu[b].fen.macth=0;
stu[b].fen.english=0;
stu[b].fen.history=0;

}
else
cout<<"输入有误,请从新输入"<<endl;
}

这个程序是我自己写的,其中还可以删除和更改学生的程序,如果只要输入和查询,把删除和更改函数删掉就可以了
第2个回答  推荐于2016-03-10
#include<stdio.h>
void main()
{
int s[4][5];
int i,j,n;
printf("please input numbers and scores:\n");
for(i=0;i<4;i++)
{for(j=0;j<5;j++)
scanf("%d",&s[i][j]);}
printf("please input number:\n");
scanf("%d",&n);
for(i=0;i<4;i++)
{if(n==s[i][0])
{printf("his scores are:\n");
printf("%d %d %d %d\n",s[i][1],s[i][2],s[i][3],s[i][4]);}
}
}
结果:
please input numbers and scores:
1001 87 86 79 80
1002 81 82 83 84
1003 85 90 91 79
1004 86 78 88 90
please input number:
1003
his scores are:
85 90 91 79本回答被提问者和网友采纳
相似回答