结构体版的学生成绩管理系统,
java版本的在后面
主要功能有
按1 输入学生信息
按2 输出学生信息
按3 查询学生信息
按4 修改学生信息
按5 删除学生信息
按6 插入学生信息
按7 排序总成绩信息
学生信息主要有姓名,班级,学号,C语言成绩,高数成绩,大学英语成绩,控制台界面输出格式有点不美观,
#include<stdio.h>
#include<string.h>
struct student
{
char name[20];//名字
char sex[10];//性别
int number;//学号
char ban[20];//班级
int c;//C语言成绩
int gaoshu;//高数成绩
int yingyu;//大学英语成绩
int sum;//总成绩
}stu[60];
int n;//学生数量
void menu()//菜单
{
printf("\n");
printf("***********************************\n");
printf("*** 学生成绩管理系统 ***\n");
printf("*** 按1 输入学生信息 ***\n");
printf("*** 按2 输出学生信息 ***\n");
printf("*** 按3 查询学生信息 ***\n");
printf("*** 按4 修改学生信息 ***\n");
printf("*** 按5 删除学生信息 ***\n");
printf("*** 按6 插入学生信息 ***\n");
printf("*** 按7 排序成绩信息 ***\n");
printf("*** 按0 退出系统 ***\n");
printf("***********************************\n");
}
void input()//学生信息的录入
{
int i,j=1;
printf("\n 请输入总学生数量:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf(" 输入第%d个学生相关信息\n",j++);
printf("输入姓名\n");
scanf("%s",stu[i].name);
getchar();
printf("输入性别\n");
scanf("%s",stu[i].sex);
printf("输入学号\n");
scanf("%d",&stu[i].number);
printf("输入班级\n");
scanf("%s",stu[i].ban);
printf("输入c语言成绩\n");
scanf("%d",&stu[i].c);
printf("输入高数成绩\n");
scanf("%d",&stu[i].gaoshu);
printf("输入大学英语成绩\n");
scanf("%d",&stu[i].yingyu);
stu[i].sum=stu[i].c+stu[i].gaoshu+stu[i].yingyu;
printf("该学生的总成绩:%d\n",stu[i].sum);
}
}
void output()//学生信息输出
{
int i;
printf("----------学生信息的是----------\n");
if(n==0)printf(" ++++++这里没有信息++++++\n");
else for(i=1;i<=n;i++)
{
printf("名字:%2s",stu[i].name);
printf("性别:%2s",stu[i].sex);
printf("学号:%2d",stu[i].number);
printf("班级:%2s",stu[i].ban);
printf("c语言成绩:%2d\n",stu[i].c);
printf("高数成绩:%2d\n",stu[i].gaoshu);
printf("英语成绩:%2d\n",stu[i].yingyu);
stu[i].sum=stu[i].c+stu[i].gaoshu+stu[i].yingyu;
printf("该学生的总成绩:%d\n",stu[i].sum);
}
}
void search()//查询
{
int num,i,t;
char a[20],k;
if(n!=0)
{
printf("选择查找条件(1:学号 2:名字)\n");
scanf("%d",&t);
if(t==1)
{
printf("输入您要查找的学生的学号\n");
scanf("%d",&num);
for(i=1;i<=n;i++)
{
if(stu[i].number==num)
{
printf("名字:%s",stu[i].name);
printf("性别:%s",stu[i].sex);
printf("学号:%d",stu[i].number);
printf("班级:%s",stu[i].ban);
printf("c语言成绩:%d\n",stu[i].c);
printf("高数成绩:%d\n",stu[i].gaoshu);
printf("英语成绩:%d\n",stu[i].yingyu);
stu[i].sum=stu[i].c+stu[i].gaoshu+stu[i].yingyu;
printf("该学生的总成绩:%d\n",stu[i].sum);
break;
}
} if(i>n) printf("您查找的信息不存在或者学号输入错误\n");
}
if(t==2)
{
printf("输入您要查找的学生的名字\n");
scanf("%s",a);
for(i=1;i<=n;i++)
{
k=strcmp(stu[i].name,a);
if(k==0)
{
printf("名字:%s",stu[i].name);
printf("性别:%s",stu[i].sex);
printf("学号:%d",stu[i].number);
printf("班级:%s",stu[i].ban);
printf("c语言成绩:%d\n",stu[i].c);
printf("高数成绩:%d\n",stu[i].gaoshu);
printf("英语成绩:%d\n",stu[i].yingyu);
stu[i].sum=stu[i].c+stu[i].gaoshu+stu[i].yingyu;
printf("该学生的总成绩:%d\n",stu[i].sum);
break;
}
}if(i>n) printf("您查找的信息不存在或者学号输入错误\n");
}
}
else printf("对不起,这里没有学生信息\n");
}
void change()//修改
{
int num,i;
printf("输入您要修改的学生的学号\n");
scanf("%d",&num);
if(n==0) printf(" ++++++这里没有信息++++++\n");
else
{
for(i=1;i<=n;i++)
{
if(stu[i].number==num)
{
printf("您要修改的学生信息为\n");
printf("名字:%s",stu[i].name);
printf("性别:%s",stu[i].sex);
printf("学号:%d",stu[i].number);
printf("班级:%s",stu[i].ban);
printf("c语言成绩:%d\n",stu[i].c);
printf("高数成绩:%d\n",stu[i].gaoshu);
printf("英语成绩:%d\n",stu[i].yingyu);
stu[i].sum=stu[i].c+stu[i].gaoshu+stu[i].yingyu;
printf("该学生的总成绩:%d\n",stu[i].sum);
printf("\n");
break;
}
}
if(i>n) printf("您查找的信息不存在或者学号输入错误\n");
else
{
printf("输入姓名\n");
scanf("%s",stu[i].name);
getchar();
printf("输入性别\n");
scanf("%s",stu[i].sex);
printf("输入学号\n");
scanf("%d",&stu[i].number);
printf("输入班级\n");
scanf("%s",stu[i].ban);
printf("输入c语言成绩\n");
scanf("%d",&stu[i].c);
printf("输入高数成绩\n");
scanf("%d",&stu[i].gaoshu);
printf("输入大学英语成绩\n");
scanf("%d",&stu[i].yingyu);
}
}
}
void del()//删除
{
int i,j,e,num;
if(n!=0)
{
printf(" ****这是所有学生的信息****\n");
for(i=1;i<=n;i++)
{
printf("--------------------------*\n");
printf("名字:%s\n",stu[i].name);
printf(" *\n");
printf("性别:%s\n",stu[i].sex);
printf(" *\n");
printf("学号:%d\n",stu[i].number);
printf(" *\n");
printf("班级:%s\n",stu[i].ban);
printf(" *\n");
printf("c语言成绩:%d\n",stu[i].c);
printf("高数成绩:%d\n",stu[i].gaoshu);
printf("英语成绩:%d\n",stu[i].yingyu);
stu[i].sum=stu[i].c+stu[i].gaoshu+stu[i].yingyu;
printf("该学生的总成绩:%d\n",stu[i].sum);
printf("--------------------------*\n");
}
printf("请输入您要删除的学生的学号:");
scanf("%d",&num);
for(i=1;i<=n;i++)
if(stu[i].number==num)
{
j=i;
for(e=i-1;e<n;e++,j++)
{
strcpy(stu[j].name,stu[j+1].name);
strcpy(stu[j].sex,stu[j+1].sex);
stu[j].number=stu[j+1].number;
strcpy(stu[j].ban,stu[j+1].ban);
stu[j].c=stu[j+1].c;
stu[j].gaoshu=stu[j+1].gaoshu;
stu[j].yingyu=stu[j+1].yingyu;
n--;
}
}printf("**********该学生信息已删除**********\n");
}
else printf("对不起,这里没有学生信息\n");
}
void add()//插入
{
int i,j,t;
if(n!=0)
{
printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("^ 注: 下面已有信息,如有重复请不要插入 ^\n");
printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\n");
for(i=1;i<=n;i++)
{
printf("名字:%s",stu[i].name);
printf("性别:%s",stu[i].sex);
printf("学号:%d",stu[i].number);
printf("班级:%s",stu[i].ban);
printf("c语言成绩:%d\n",stu[i].c);
printf("高数成绩:%d\n",stu[i].gaoshu);
printf("英语成绩:%d\n",stu[i].yingyu);
stu[i].sum=stu[i].c+stu[i].gaoshu+stu[i].yingyu;
printf("该学生的总成绩:%d\n",stu[i].sum);
printf("\n");
}
printf("是否继续插入(是:y 否:n)\n");
printf("%c您的选择是:",t=getchar());
t=getchar();
if(t=='y')
{
j=n;
printf("**********请插入学生相关信息**********\n");
printf("输入姓名\n");
scanf("%s",stu[j+1].name);
getchar();
printf("输入性别\n");
scanf("%s",stu[j+1].sex);
printf("输入学号\n");
scanf("%d",&stu[j+1].number);
printf("输入班级\n");
scanf("%s",stu[j+1].ban);
printf("输入c语言成绩\n");
scanf("%d",&stu[j+1].c);
printf("输入高数成绩\n");
scanf("%d",&stu[j+1].gaoshu);
printf("输入英语成绩\n");
scanf("%d",&stu[j+1].yingyu);
strcpy(stu[j+2].name,stu[j+1].name);
strcpy(stu[j+2].sex,stu[j+1].sex);
stu[j+2].number=stu[j+1].number;
strcpy(stu[j+2].ban,stu[j+1].ban);
stu[j+2].c=stu[j+1].c;
stu[j+2].gaoshu=stu[j+1].gaoshu;
stu[j+2].yingyu=stu[j+1].yingyu;
printf(" 该学生信息已经插入\n");
n++;
}else printf("\n (▔▽▔)插入程序结束,请重新选择");printf("\n");
}
else{i=1;printf("请输入要插入学生的相关信息\n");
printf("输入姓名\n");
scanf("%s",stu[i].name);
getchar();
printf("输入性别\n");
scanf("%s",stu[i].sex);
printf("输入学号\n");
scanf("%d",&stu[i].number);
printf("输入班级\n");
scanf("%s",stu[i].ban);
printf("输入c语言成绩\n");
scanf("%d",&stu[i].c);
printf("输入高数成绩\n");
scanf("%d",&stu[i].gaoshu);
printf("输入英语成绩\n");
scanf("%d",&stu[i].yingyu);
n++;
}
}
void paixu()
{
int i,j,t;
if(n!=0)
{
printf("该排序是按照总分成绩从高到低进行排序\n");
for(i=1;i<=n;i++)
for(j=1;j<n;j++)
{
if(stu[j].sum<stu[j+1].sum)
{
t=stu[j].sum;
stu[j].sum=stu[j+1].sum;
stu[j+1].sum=t;
}
}
for(i=1;i<=n;i++)
{
printf("名字:%s\n",stu[i].name);
printf("性别:%s\n",stu[i].sex);
printf("学号:%d\n",stu[i].number);
printf("班级:%s\n",stu[i].ban);
printf("c语言成绩:%d\n",stu[i].c);
printf("高数成绩:%d\n",stu[i].gaoshu);
printf("总成绩:%d\n",stu[i].sum);
}
}
else printf(" ++++++这里没有信息++++++\n");
}
void main()
{
int a,b=1;
while(b)
{
menu();
printf("您选择的是: ");
scanf("%d",&a);
printf("\n");
switch(a)
{
case 1:input();break;//输入
case 2:output();break;//输出
case 3:search();break;//查找
case 4:change();break;//修改
case 5:del();break;//删除
case 6:add();break;//插入
case 7:paixu();break;//排序
case 0:b=0;break;//退出
}
}
printf(" 学生管理系统已退出( ^_^ )\n");
}
不吃香的java版本来了
package cn.com.lyb;
import java.util.Scanner;
class Student {
String name;
String sex;
int number;
String ban;
int c;
int gaoshu;
int yingyu;
int sum;
public Student() {
// 默认构造函数
}
public Student(String name, String sex, int number, String ban, int c, int gaoshu, int yingyu) {
this.name = name;
this.sex = sex;
this.number = number;
this.ban = ban;
this.c = c;
this.gaoshu = gaoshu;
this.yingyu = yingyu;
this.sum = c + gaoshu + yingyu;
}
}
public class StudentManagementSystem {
static Student[] stu;
static int n;
public static void menu() {
System.out.println("\n***********************************");
System.out.println("*** 学生成绩管理系统 ***");
System.out.println("*** 按1 输入学生信息 ***");
System.out.println("*** 按2 输出学生信息 ***");
System.out.println("*** 按3 查询学生信息 ***");
System.out.println("*** 按4 修改学生信息 ***");
System.out.println("*** 按5 删除学生信息 ***");
System.out.println("*** 按6 插入学生信息 ***");
System.out.println("*** 按7 排序成绩信息 ***");
System.out.println("*** 按0 退出系统 ***");
System.out.println("***********************************");
}
public static void input() {
Scanner scanner = new Scanner(System.in);
int j = 1;
System.out.print("\n请输入总学生数量: ");
n = scanner.nextInt();
stu = new Student[n + 1];
for (int i = 1; i <= n; i++) {
System.out.printf("输入第%d个学生相关信息\n", j++);
stu[i] = new Student();
System.out.print("输入姓名: ");
stu[i].name = scanner.next();
System.out.print("输入性别: ");
stu[i].sex = scanner.next();
System.out.print("输入学号: ");
stu[i].number = scanner.nextInt();
System.out.print("输入班级: ");
stu[i].ban = scanner.next();
System.out.print("输入c语言成绩: ");
stu[i].c = scanner.nextInt();
System.out.print("输入高数成绩: ");
stu[i].gaoshu = scanner.nextInt();
System.out.print("输入大学英语成绩: ");
stu[i].yingyu = scanner.nextInt();
stu[i].sum = stu[i].c + stu[i].gaoshu + stu[i].yingyu;
System.out.printf("该学生的总成绩: %d\n", stu[i].sum);
}
}
// ... (其他方法)
public static void main(String[] args) {
int a, b = 1;
while (b != 0) {
menu();
System.out.print("您选择的是: ");
Scanner scanner = new Scanner(System.in);
a = scanner.nextInt();
switch (a) {
case 1:
input();
break;
case 2:
output();
break;
case 3:
search();
break;
case 4:
change();
break;
case 5:
del();
break;
case 6:
add();
break;
case 7:
paixu();
break;
case 0:
b = 0;
break;
}
}
System.out.println("学生管理系统已退出( ^_^ )");
}
public static void output() {
int i;
System.out.println("----------学生信息的是----------");
if (n == 0) System.out.println(" ++++++这里没有信息++++++");
else {
for (i = 1; i <= n; i++) {
System.out.printf("名字:%s", stu[i].name);
System.out.printf("性别:%s", stu[i].sex);
System.out.printf("学号:%d", stu[i].number);
System.out.printf("班级:%s\n", stu[i].ban);
System.out.printf("c语言成绩:%d\n", stu[i].c);
System.out.printf("高数成绩:%d\n", stu[i].gaoshu);
System.out.printf("英语成绩:%d\n", stu[i].yingyu);
stu[i].sum = stu[i].c + stu[i].gaoshu + stu[i].yingyu;
System.out.printf("该学生的总成绩:%d\n", stu[i].sum);
}
}
}
public static void search() {
int num, i, t;
String a;
char k;
if (n != 0) {
Scanner scanner = new Scanner(System.in);
System.out.println("选择查找条件(1:学号 2:名字)");
t = scanner.nextInt();
if (t == 1) {
System.out.println("输入您要查找的学生的学号");
num = scanner.nextInt();
for (i = 1; i <= n; i++) {
if (stu[i].number == num) {
printStudentInfo(i);
break;
}
}
if (i > n) System.out.println("您查找的信息不存在或者学号输入错误");
} else if (t == 2) {
System.out.println("输入您要查找的学生的名字");
a = scanner.next();
for (i = 1; i <= n; i++) {
k = (char) a.compareTo(stu[i].name);
if (k == 0) {
printStudentInfo(i);
break;
}
}
if (i > n) System.out.println("您查找的信息不存在或者学号输入错误");
}
} else {
System.out.println("对不起,这里没有学生信息");
}
}
public static void change() {
int num, i;
Scanner scanner = new Scanner(System.in);
System.out.println("输入您要修改的学生的学号");
num = scanner.nextInt();
if (n == 0) System.out.println(" ++++++这里没有信息++++++");
else {
for (i = 1; i <= n; i++) {
if (stu[i].number == num) {
printStudentInfo(i);
break;
}
}
if (i > n) {
System.out.println("您查找的信息不存在或者学号输入错误");
} else {
System.out.println("请输入新的学生信息");
System.out.print("输入姓名: ");
stu[i].name = scanner.next();
System.out.print("输入性别: ");
stu[i].sex = scanner.next();
System.out.print("输入学号: ");
stu[i].number = scanner.nextInt();
System.out.print("输入班级: ");
stu[i].ban = scanner.next();
System.out.print("输入c语言成绩: ");
stu[i].c = scanner.nextInt();
System.out.print("输入高数成绩: ");
stu[i].gaoshu = scanner.nextInt();
System.out.print("输入大学英语成绩: ");
stu[i].yingyu = scanner.nextInt();
}
}
}
public static void del() {
int i, j, e, num;
Scanner scanner = new Scanner(System.in);
if (n != 0) {
System.out.println(" ****这是所有学生的信息****");
for (i = 1; i <= n; i++) {
printStudentInfo(i);
}
System.out.println("请输入您要删除的学生的学号:");
num = scanner.nextInt();
for (i = 1; i <= n; i++) {
if (stu[i].number == num) {
j = i;
for (e = i - 1; e < n; e++, j++) {
copyStudentInfo(j, j + 1);
}
n--;
System.out.println("**********该学生信息已删除**********");
}
}
} else {
System.out.println("对不起,这里没有学生信息");
}
}
public static void add() {
int i, t;
Scanner scanner = new Scanner(System.in);
if (n != 0) {
System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
System.out.println("^ 注: 下面已有信息,如有重复请不要插入 ^");
System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
System.out.println();
for (i = 1; i <= n; i++) {
printStudentInfo(i);
}
System.out.println("是否继续插入(是:y 否:n)");
System.out.print("您的选择是:");
t = scanner.next().charAt(0);
if (t == 'y') {
i = n;
System.out.println("**********请插入学生相关信息**********");
System.out.print("输入姓名: ");
stu[i + 1].name = scanner.next();
System.out.print("输入性别: ");
stu[i + 1].sex = scanner.next();
System.out.print("输入学号: ");
stu[i + 1].number = scanner.nextInt();
System.out.print("输入班级: ");
stu[i + 1].ban = scanner.next();
System.out.print("输入c语言成绩: ");
stu[i + 1].c = scanner.nextInt();
System.out.print("输入高数成绩: ");
stu[i + 1].gaoshu = scanner.nextInt();
System.out.print("输入英语成绩: ");
stu[i + 1].yingyu = scanner.nextInt();
copyStudentInfo(i + 2, i + 1);
System.out.println(" 该学生信息已经插入");
n++;
} else {
System.out.println("\n (▔▽▔)插入程序结束,请重新选择");
System.out.println();
}
} else {
i = 1;
System.out.println("请输入要插入学生的相关信息");
System.out.print("输入姓名: ");
stu[i].name = scanner.next();
System.out.print("输入性别: ");
stu[i].sex = scanner.next();
System.out.print("输入学号: ");
stu[i].number = scanner.nextInt();
System.out.print("输入班级: ");
stu[i].ban = scanner.next();
System.out.print("输入c语言成绩: ");
stu[i].c = scanner.nextInt();
System.out.print("输入高数成绩: ");
stu[i].gaoshu = scanner.nextInt();
System.out.print("输入英语成绩: ");
stu[i].yingyu = scanner.nextInt();
n++;
}
}
public static void paixu() {
int i, j, t;
if (n != 0) {
System.out.println("该排序是按照总分成绩从高到低进行排序");
for (i = 1; i <= n; i++) {
for (j = 1; j < n; j++) {
if (stu[j].sum < stu[j + 1].sum) {
t = stu[j].sum;
stu[j].sum = stu[j + 1].sum;
stu[j + 1].sum = t;
}
}
}
for (i = 1; i <= n; i++) {
printStudentInfo(i);
}
} else {
System.out.println(" ++++++这里没有信息++++++");
}
}
public static void printStudentInfo(int i) {
System.out.printf("名字:%s\n", stu[i].name);
System.out.printf("性别:%s\n", stu[i].sex);
System.out.printf("学号:%d\n", stu[i].number);
System.out.printf("班级:%s\n", stu[i].ban);
System.out.printf("c语言成绩:%d\n", stu[i].c);
System.out.printf("高数成绩:%d\n", stu[i].gaoshu);
System.out.printf("英语成绩:%d\n", stu[i].yingyu);
stu[i].sum = stu[i].c + stu[i].gaoshu + stu[i].yingyu;
System.out.printf("总成绩:%d\n", stu[i].sum);
System.out.println("--------------------------");
}
public static void copyStudentInfo(int destIndex, int sourceIndex) {
stu[destIndex].name = stu[sourceIndex].name;
stu[destIndex].sex = stu[sourceIndex].sex;
stu[destIndex].number = stu[sourceIndex].number;
stu[destIndex].ban = stu[sourceIndex].ban;
stu[destIndex].c = stu[sourceIndex].c;
stu[destIndex].gaoshu = stu[sourceIndex].gaoshu;
stu[destIndex].yingyu = stu[sourceIndex].yingyu;
stu[destIndex].sum = stu[sourceIndex].sum;
}
}