苞苞不是包包 2022-03-12 10:34 采纳率: 100%
浏览 49
已结题

试着用C语言简单的做了一个学生成绩管理系统,但是一直有错误,改来改去还是不行,求解答~

我还不是很会自己写代码,自己写了一点,又借鉴了一些别人的代码,有一些地方不是很理解,所以代码运行不出来也是正常的,但是我就是想弄明白到底是什么问题,要怎么修改,请大家指点一下我~

#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);
        }
    }
}



  • 写回答

1条回答 默认 最新

  • yun6853992 2022-03-12 11:29
    关注

    大哥,你这是c吗? 我怎么赶紧语法更像java或者其他了。。。。

    c语言的基本语法了解一下,然后我根据你的意图,简单使用了一下相关基本语法,你看看: 类怎么定义,类成员函数怎么定义,c里面的main函数等

    img

    
    //链表
    #include<stdio.h>
    #include<stdlib.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    struct Student
    {
        string Name;//定义名字
        string Xuehao;//定义学号
        string Class;//班级
        int English_Score;//英语成绩
        int Math_score;//数学成绩
        float C_Score;//c语言成绩
        double Total;//总成绩
    };
    
    struct Student st[4];
    class Program
    {
    public:
        Program() {}
        ~Program(){}
    public:
        void man() { printf("this is man \n"); }
        void test() {
            for (int i = 0; i < 4; i++)
            {
                st[i].Name = "myname"+ std::to_string(i);
                st[i].Math_score = 5+ i;
            }
        }
        void testprint()
        {
            for (int i = 0; i < 4; i++)
            {
                printf("%d  %s %d \n", i, st[i].Name.c_str(), st[i].Math_score);
            }
        }
    
    };
    int main()
    {
        class Program mytest;
        mytest.man();
        mytest.test();
        mytest.testprint();
        return 0;
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月20日
  • 已采纳回答 3月12日
  • 创建了问题 3月12日

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理