我还不是很会自己写代码,自己写了一点,又借鉴了一些别人的代码,有一些地方不是很理解,所以代码运行不出来也是正常的,但是我就是想弄明白到底是什么问题,要怎么修改,请大家指点一下我~
#include<stdio.h>
#define N 5000
struct student
{
char Stu_Name[32];
long int Stu_ID;
int English_Score;
int Math_score;
int C_Score;
int Total;
}STU[N];
int n;
extern void menu();
extern int InporData(struct student stu[]);
extern void saveData(char *FileName,struct student stu[],int n);
extern int ReadData(char *FileName,struct student stu[]);
extern void Browe(struct student stu[],int n);
extern int Select(struct student STU[],int ID,struct student *Result,int n);
extern int Insert(struct student STU[],int *n);
extern int Delete(struct student STU[],int ID,int *n);
extern int Modify(struct student STU[],int ID,int n);
extern void sortTotal(struct student stu[],int n);
{
public struct Student
{
public string Name;//定义名字
public string Xuehao;//定义学号
public string Class;//班级
public int English_Score;//英语成绩
public Math_score;//数学成绩
public C_Score;//c语言成绩
public double Total;//总成绩
}
class Program
{
static Student[] stu = new Student[5000];
static int count;
//初始化数组
public static void moren()//默认的五位同学信息
{
stu[0].Xuehao = "0001";
stu[0].Name = "明明";
stu[0].Class = "1903";
stu[0].English_Score = 78;
stu[0].Math_score = 88;
stu[0].C_score = 84;
stu[0].Total= 250;
stu[1].Xuehao = "0002";
stu[1].Name = "欧欧";
stu[1].Class = "1903";
stu[1].English_Score = 86;
stu[1].Math_score= 82;
stu[1].C_score = 88;
stu[1].Total= 256;
stu[2].Xuehao = "0003";
stu[2].Name = "莎莎";
stu[2].Class = "1903";
stu[2].English_Score = 88;
stu[2].Math_score = 92;
stu[0].C_score = 89;
stu[2].Total= 269;
stu[3].Xuehao = "0004";
stu[3].Name = "琳琳";
stu[3].Class = "1903";
stu[3].English_Score = 90;
stu[3].Math_score= 87;
stu[0].C_score = 78;
stu[3].Total = 255;
stu[4].Xuehao = "0005";
stu[4].Name = "月月";
stu[4].Class = "1903";
stu[4].English_Score = 83;
stu[4].Math_score= 88;
stu[0].C_score = 90;
stu[4].Total = 261;
count = 5;
}
public static void Man()//主菜单
{
Console.WriteLine("1.查询学生信息");
Console.WriteLine("2.录入学生信息");
Console.WriteLine("3.修改学生信息");
Console.WriteLine("4.删除学生信息");
Console.WriteLine("5.退出");
}
public static void AddStudent()
{
string flag;
do
{
Console.WriteLine("请输入学号:");
stu[count].Xuehao = Console.ReadLine();
Console.WriteLine("请输入姓名:");
stu[count].Name = Console.ReadLine();
Console.WriteLine("请输入班级:");
stu[count].Class = Console.ReadLine();
Console.WriteLine("请输入英语成绩:");
stu[count].English_Score = int.Parse(Console.ReadLine());
Console.WriteLine("请输入数学成绩:");
stu[count].Math_score= Console.ReadLine();
Console.WriteLine("请输入c语言成绩:");
stu[count].C_Score= Console.ReadLine();
Console.WriteLine("请输入总成绩:");
stu[count].Total = double.Parse(Console.ReadLine());
count++;
Console.WriteLine("添加成功!是否继续添加(y/n)?");
flag = Console.ReadLine();
} while (flag == "Y" || flag == "y");
} //录入信息功能
public static void FindStudent()
{
string choose;
do
{
Console.WriteLine("1.查询全部");
Console.WriteLine("2.按班级查询");
Console.WriteLine("3.按学号查询");
Console.WriteLine("4.按姓名查询");
Console.WriteLine("5.按总分数查询排名");
Console.WriteLine("0.返回上一级菜单");
Console.WriteLine("请选择:");
choose = Console.ReadLine();
switch (choose)
{
case "1":
FindAll();//查询全部
break;
case "2":
FindClass();//查询班级
break;
case "3":
FindXueHao();//查询学号
break;
case "4":
FindName();//按名字查询
break;
case "5":
FindSTotal();//按总成绩查询
break;
case "0":
Console.WriteLine("欢迎再次查询");
break;
}
} while (choose != "0");//等于0则循环,不等于则结束
} //查询界面
//全部查询界面
public static void FindAll()
{
Console.WriteLine("学号\t姓名\t班级\t英语成绩\t数学成绩\tc语言成绩\t总成绩\t");
for (int i = 0; i < count; i++)
{
Console.Write(stu[i].Xuehao + "\t");
Console.Write(stu[i].Name + "\t");
Console.Write(stu[i].Class + "\t");
Console.Write(stu[i].English_Score + "\t");
Console.Write(stu[i].Math_score + "\t");
Console.Write(stu[i].C_Score + "\t");
Console.Write(stu[i].Total + "\t");
Console.WriteLine("");
}
}//查询全部
//按班级查询
public static void FindClass()
{
string BanJi, chooes;
do
{
Console.WriteLine("请输入班级:");
BanJi = Console.ReadLine();
Console.WriteLine("学号\t姓名\t班级\t英语成绩\t数学成绩\tc语言成绩\t总成绩\t");
for (int i = 0; i < count; i++)
{
if (BanJi == stu[i].Class)
{
Console.Write(stu[i].Xuehao + "\t");
Console.Write(stu[i].Name + "\t");
Console.Write(stu[i].Class + "\t");
Console.Write(stu[i].English_Score + "\t");
Console.Write(stu[i].Math_score + "\t");
Console.Write(stu[i].C_Score + "\t");
Console.Write(stu[i].Total + "\t");
Console.WriteLine("");
}
else
{
continue;
}
}
Console.WriteLine("是否继续按班级查询?(y/n)");
chooes = Console.ReadLine();
} while (chooes == "Y" || chooes == "y");
}//查询班级
//按学号查询
public static void FindXueHao()
{
string Xuehao, chooes;
do
{
Console.WriteLine("请输入学号:");
Xuehao = Console.ReadLine();
Console.WriteLine("学号\t姓名\t班级\t英语成绩\t数学成绩\tc语言成绩\t总成绩\t");
for (int i = 0; i < count; i++)
{
if (Xuehao == stu[i].Xuehao)
{
Console.Write(stu[i].Xuehao + "\t");
Console.Write(stu[i].Name + "\t");
Console.Write(stu[i].Class + "\t");
Console.Write(stu[i].English_Score + "\t");
Console.Write(stu[i].Math_score + "\t");
Console.Write(stu[i].C_Score + "\t");
Console.Write(stu[i].Total + "\t");
Console.WriteLine("");
}
else
{
continue;
}
}
Console.WriteLine("是否继续按学号查询?(y/n)");
chooes = Console.ReadLine();
} while (chooes == "Y" || chooes == "y");
}//查询学号
//按姓名查询
public static void FindName()
{
string Name, chooes;
do
{
Console.WriteLine("请输入姓名:");
Name = Console.ReadLine();
Console.WriteLine("学号\t姓名\t班级\t英语成绩\t数学成绩\tc语言成绩\t总成绩\t");
for (int i = 0; i < count; i++)
{
if (Name == stu[i].Name)
{
Console.Write(stu[i].Xuehao + "\t");
Console.Write(stu[i].Name + "\t");
Console.Write(stu[i].Class + "\t");
Console.Write(stu[i].English_Score + "\t");
Console.Write(stu[i].Math_score + "\t");
Console.Write(stu[i].C_Score + "\t");
Console.Write(stu[i].Total + "\t");
Console.WriteLine("");
}
else
{
continue;
}
}
Console.WriteLine("是否继续按姓名查询?(y/n)");
chooes = Console.ReadLine();
} while (chooes == "Y" || chooes == "y");
}//名字查询
//按分数查询排名
static void Bubble()//冒号排序法
{
Student temp = new Student();
for (int i = count; i > 0; i--)
{
for (int j = 0; j < i - 1; j++)
{
if (stu[j].Total < stu[j + 1].Total)
{
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
}
}
}
public static void FindTotal()
{
Bubble();
Console.WriteLine("学号\t姓名\t班级\t英语成绩\t数学成绩\tc语言成绩\t总成绩\t");
for (int i = 0; i < count; i++)
{
Console.Write(stu[i].Xuehao + "\t");
Console.Write(stu[i].Name + "\t");
Console.Write(stu[i].Class + "\t");
Console.Write(stu[i].English_Score + "\t");
Console.Write(stu[i].Math_score + "\t");
Console.Write(stu[i].C_Score + "\t");
Console.Write(stu[i].Total + "\t");
Console.WriteLine("");
}
}//成绩排名查询
public static void ShanChuXueHao() //输入学号删除信息
{
Console.WriteLine("请输入学号:");
string stuno = Console.ReadLine();
int index = XHo(stuno);
if (index == -1)
{
Console.WriteLine("输入错误,请重新输入!");
}
else if (index == count - 1)
{
count--;
Console.WriteLine("删除成功!");
}
else
{
for (int i = index; i < count; i++)
{
stu[i] = stu[i + 1];
}
count--;
Console.WriteLine("删除成功!");
}
}
//要修改的学生信息
public static void XinXi(string coun)
{
Console.WriteLine("要修改的学生信息:");
for (int i = 0; i < count; i++)
{
if (coun == stu[i].Xuehao)
{
Console.WriteLine("姓名:" + stu[i].Name);
Console.WriteLine("班级:" + stu[i].Class);
Console.WriteLine("英语成绩:" + stu[i].English_Score);
Console.WriteLine("数学成绩:" + stu[i].Math_score);
Console.WriteLine("c语言成绩:" + stu[i].C_Score);
Console.WriteLine("总成绩:" + stu[i].Total);
}
else
{
continue;
}
}
}
//修改学生信息
public static void XGXX()
{
Console.WriteLine("请输入学号!");
string coun = Console.ReadLine();
XinXi(coun);
Console.WriteLine("请选择要修改的内容:");
Console.WriteLine("1.姓名");
Console.WriteLine("2.班级");
Console.WriteLine("3.英语成绩");
Console.WriteLine("4.数学成绩");
Console.WriteLine("5.c语言成绩");
Console.WriteLine("6.总成绩");
Console.WriteLine("请选择:");
string a = Console.ReadLine();
for (int i = 0; i < count; i++)
{
if (coun == stu[i].Xuehao)
{
if (a == "1")
{
Console.WriteLine("请输入新的姓名");
stu[i].Name = Console.ReadLine();
}
else if (a == "2")
{
Console.WriteLine("请输入新的班级");
stu[i].Class = Console.ReadLine();
}
else if (a == "3")
{
Console.WriteLine("请输入新的英语成绩");
stu[i].English_Score = Console.ReadLine();
}
else if (a == "4")
{
Console.WriteLine("请输入新的数学");
stu[i].Math_score = int.Parse(Console.ReadLine());
}
else if (a == "5")
{
Console.WriteLine("请输入新的c语言成绩");
stu[i].C_Score = float.Parse(Console.ReadLine());
}
else if (a == "6")
{
Console.WriteLine("请输入新的总成绩");
stu[i].Total = float.Parse(Console.ReadLine());
}
Console.WriteLine("修改成功");
}
else
{
continue;
}
}
}
static void Main(string[] args)
{
moren();
int chooes;
do
{
Man();
Console.WriteLine("请选择序号!");
chooes = int.Parse(Console.ReadLine());
switch (chooes)
{
case 1:
FindStudent();
break;
case 2:
AddStudent();
break;
case 3:
XGXX();
break;
case 4:
ShanChuXueHao();
break;
case 5:
Console.WriteLine("已退出");
break;
default:
Console.WriteLine("输入错误!,请重新输入!");
break;
}
} while (chooes != 5);
}
}
}