关于幼儿园班级信息管理系统的一个系统,自己找代码改的,现在有一些问题解决不了,求解答

能运行且满足基本条件,但是显示不出身高、体重、家长姓名和备注,不知道代码的问题出在哪?

#include<iostream>

#include<cstring>

#include<string>

#include<fstream>

#include<algorithm>

#include<iomanip>

#include<cstdio>

#include<cstdlib>

#include<conio.h>

#include<windows.h>

using namespace std;

class student //学生类

{

private:

    long long num;

    char name[20];

     int age;

    char sex[6];

     int weight; //体重kg

      int height; //身高cm

    char name1[20]; //父母联系人姓名

    char phone[20];

    char add[20]; //地址

    char note{20}; //备注其它

public:

    static int NUM;

    student() {}

    ~student() {}

    void input();

    friend void readin();

    friend void show(); //显示

    friend void mood(); //修改

    friend void del(); //删除

    friend void soort(); //按身高体重排序

    friend void save(); //保存

    friend void findyou(); //按地址和家长姓名查找

    friend void clear1(); //销毁文件

}

zhuo_yue[1000];

int student::NUM=0;

void readin() //准备读入文件

{

    ifstream in("inf.txt",ios::binary);

    int i=1;

    while(!in.eof())

    {

        in.read((char*) &zhuo_yue[i],sizeof(zhuo_yue[i]));

        i++;

    }

    in.close();

    student::NUM=i-2;

}

void show() //显示信息

{

    if(student::NUM==0)

        cout<<endl<<endl<<setw(10)<<"暂无学生信息";

    else

    {

        cout<<"学生信息显示"<<endl<<endl;

        cout<<"学号"<<setw(20)<<"姓名"<<setw(20)<<"年龄"

         <<set(20)<<"性别"<<setw(20)<<"体重"<<setw(20)<<"身高"

         <<setw(20)<<"家长姓名"<<set(20)<<"联系电话"<<set(20)<<"地址"

         <<set(20)<<"备注"

            <<endl;

        for(int i=1; i<=student::NUM; i++)

        {

            cout<<zhuo_yue[i].num<<setw(20)<<zhuo_yue[i].name<<setw(20)

                <<zhuo_yue[i].age<<setw(20)<<zhuo_yue[i].sex<<setw(20)

                <<zhuo_yue[i].weight<<setw(20))<<zhuo_yue[i].height<<setw(20)

                <<zhuo_yue[i].name1<<setw(20)<<zhuo_yue[i].phone<<setw(20)

                <<zhuo_yue[i].add<<setw(20)<<zhuo_yue[i].note

                <<endl;

        }

    }

    cout<<endl<<setw(40)<<"按任意键退出";

    getch();

}

void mood() //修改信息

{

    long long L;

    cout<<"请输入欲修改的学号:";

    cin>>L;

    cout<<endl<<setw(40)<<"确认修改(y/n)";

    if(getch()=='y')

    {

        system("cls");

        for(int i=1; i<=student::NUM; i++)

            if(L==zhuo_yue[i].num)

            {

                cout<<"学生信息修改"<<endl<<endl;

                cout<<"学号:";

                cin>>zhuo_yue[i].num;

                cout<<endl<<endl;

                cout<<"姓名:";

                cin>>zhuo_yue[i].name;

                cout<<endl<<endl;

                cout<<"年龄:";

                cin>>zhuo_yue[i].age;

                cout<<endl<<endl;

                cout<<"性别:";

                cin>>zhuo_yue[i].sex;

                cout<<endl<<endl;

                cout<<"体重:";

                cin>>zhuo_yue[i].weight;

                cout<<endl<<endl;

                cout<<"身高:";

                cin>>zhuo_yue[i].height;

                cout<<endl<<endl;

                cout<<"家长姓名:";

                cin>>zhuo_yue[i].name1;

                cout<<endl<<endl;

                cout<<"联系电话:";

                cin>>zhuo_yue[i].phone;

                cout<<endl<<endl;

                cout<<"地址:";

                cin>>zhuo_yue[i].add;

                cout<<endl<<endl;

                cout<<"备注:";

                cin>>zhuo_yue[i].note;

                cout<<endl<<endl;

                break;

            }

        cout<<endl<<setw(40)<<"已修改,按任意键退出";

        getch();

    }

    else

        return;

}

void del()

{

    int sum=0;

    cout<<setw(50)<<"[1]按学号删除 [2]按姓名删除"<<endl;

    if(getch()=='1')

    {

        cout<<"请输入学号:";

        long long it;

        cin>>it;

        cout<<endl<<setw(30)<<"您确定删除此学生吗?(y/n)";

        if(getch()=='y')

        {

            system("cls");

            for(int i=1; i<=student::NUM; i++)

            {

                if(zhuo_yue[i].num==it)

                {

                    for(int j=i+1; j<=student::NUM; j++)

                        zhuo_yue[j-1]=zhuo_yue[j];

                    student::NUM--;

                    sum++;

                    break;

                }

            }

            cout<<"共删除"<<sum<<"人";

        }

        else

            return;

    }

    else if(getch()=='2')

    {

        char name1[20];

        cout<<"请输入姓名:";

        cin>>name1;

        cout<<endl<<setw(30)<<"您确定删除此学生吗?(y/n)";

        if(getch()=='y')

        {

            system("cls");

            for(int i=1; i<=student::NUM; i++)

            {

                if(strcmp(zhuo_yue[i].name,name1)==0)

                {

                    for(int j=i+1; j<=student::NUM; j++)

                        zhuo_yue[j-1]=zhuo_yue[j];

                    student::NUM--;

                    sum++;

                }

            }

            cout<<"共删除"<<sum<<"人";

        }

        else

            return;

    }

    cout<<endl<<endl<<setw(40)<<"按任意键结束";

    getch();

}

void soort()

{

    cout<<setw(50)<<"[1]按体重排序 [2]按身高排序"<<endl;

    if(getch()=='1')

    {

        for(int i=1; i<student::NUM; i++)

            for(int j=1; j<student::NUM-i+1; j++)

            {

                if(zhuo_yue[j].weight>zhuo_yue[j+1].weight)

                {

                    student it=zhuo_yue[j];

                    zhuo_yue[j]=zhuo_yue[j+1];

                    zhuo_yue[j+1]=it;

                }

            }

        cout<<endl<<setw(50)<<"已排序,按任意键退出";

        getch();

    }

    else if(getch()=='2')

    {

        for(int i=1; i<student::NUM; i++)

            for(int j=1; j<student::NUM-i+1; j++)

            {

                if(zhuo_yue[j].height>zhuo_yue[j+1].height)

                {

                    student it=zhuo_yue[j];

                    zhuo_yue[j]=zhuo_yue[j+1];

                    zhuo_yue[j+1]=it;

                }

            }

        cout<<endl<<setw(50)<<"已排序,按任意键退出";

        getch();

    }

}

void student::input() //录入学生信息

{

LI:

    NUM++;

    cout<<"学生信息输入"<<endl<<endl;

    cout<<"学号:";

    cin>>zhuo_yue[NUM].num;

    cout<<endl<<endl;

    cout<<"姓名:";

    cin>>zhuo_yue[NUM].name;

    cout<<endl<<endl;

    cout<<"年龄:";

    cin>>zhuo_yue[NUM].age;

    cout<<endl<<endl;

    cout<<"性别:";

    cin>>zhuo_yue[NUM].sex;

    cout<<endl<<endl;

    cout<<"体重:"; //显示出现问题

    cin>>zhuo_yue[NUM].weight;

    cout<<endl<<endl;

    cout<<"身高:"; //显示出现问题

    cin>>zhuo_yue[NUM].height;

    cout<<endl<<endl;

    cout<<"家长姓名:"; //显示出现问题

    cin>>zhuo_yue[NUM].name1;

    cout<<endl<<endl;

    cout<<"联系电话:";

    cin>>zhuo_yue[NUM].phone;

    cout<<endl<<endl;

    cout<<"地址:"; //显示出现问题

    cin>>zhuo_yue[NUM],add;

    cout<<endl<<endl;

    cout<<"备注:"; //显示出现问题

    cin>>zhuo_yue[NUM].note;

    cout<<endl<<endl;

    cout<<"已输入,是否继续 (y/n)";

    if(getch()=='y')

    {

        system("cls");

        goto LI;

    }

    else return;

}

void save()

{

    ofstream out("inf.txt",ios::binary);

    cout<<endl<<setw(40)<<"已保存,按任意键退出";

    for(int i=1; i<=student::NUM; i++)

    {

        out.write((char*)&zhuo_yue[i],sizeof(zhuo_yue[i]));

    }

    out.close();

    getch();

}

void findyou() //显示还存在问题

{

    int sum=0;

    cout<<setw(50)<<"[1]按地址查找 [2]按家长姓名查找"<<endl;

    if(getch()=='1')

    {

       char add[20];

        cout<<"请输入地址:";

        cin>>add;

        cout<<endl<<setw(30)<<"您确定查看此学生吗?(y/n)";

        if(getch()=='y')

        {

            system("cls");

            cout<<"查看学生信息"<<endl<<endl;

            for(int i=1; i<=student::NUM; i++)

            {

                if(zhuo_yue[i].add==add)

                {

                    cout<<setw(20)<<"学号:"<<zhuo_yue[i].num<<endl

                        <<setw(20)<<"姓名:"<<zhuo_yue[i].name<<endl

                        <<setw(20)<<"年龄:"<<zhuo_yue[i].age<<endl

                        <<setw(20)<<"性别:"<<zhuo_yue[i].sex<<endl

                        <<setw(20)<<"体重:"<<zhuo_yue[i].weight<<endl

                        <<setw(20)<<"身高:"<<zhuo_yue[i].height<<endl

                        <<setw(20)<<"家长姓名:"<<zhuo_yue[i].name1<<endl

                        <<setw(20)<<"联系电话:"<<zhuo_yue[i].phone<<endl

                        <<setw(20)<<"地址:"<<zhuo_yue[i].add<<endl

                        <<setw(20)<<"备注:"<<zhuo_yue[i].note<<endl;

                    cout<<"---------------------------------------"<<endl<<endl;

                    sum++;

                }

            }

            cout<<"共显示"<<sum<<"人";

        }

        else

            return;

    }

    else if(getch()=='2')

    {

        char name1[20];

        cout<<"请输入家长姓名:";

        cin>>name1;

        cout<<endl<<setw(30)<<"您确定查看该名学生吗?(y/n)";

        if(getch()=='y')

        {

            system("cls");

            cout<<"查看学生信息"<<endl<<endl;

            for(int i=1; i<=student::NUM; i++)

            {

                if(zhuo_yue[i].name1==name1)

                {

                   cout<<setw(20)<<"学号:"<<zhuo_yue[i].num<<endl

                        <<setw(20)<<"姓名:"<<zhuo_yue[i].name<<endl

                        <<setw(20)<<"年龄:"<<zhuo_yue[i].age<<endl

                        <<setw(20)<<"性别:"<<zhuo_yue[i].sex<<endl

                        <<setw(20)<<"体重:"<<zhuo_yue[i].weight<<endl

                        <<setw(20)<<"身高:"<<zhuo_yue[i].height<<endl

                        <<setw(20)<<"家长姓名:"<<zhuo_yue[i].name1<<endl

                        <<setw(20)<<"联系电话:"<<zhuo_yue[i].phone<<endl

                        <<setw(20)<<"地址:"<<zhuo_yue[i].add<<endl

                        <<setw(20)<<"备注:"<<zhuo_yue[i].note<<endl;

                    cout<<"---------------------------------------"<<endl<<endl;

                    sum++;

                }

            }

            cout<<"共显示"<<sum<<"人";

        }

        else

            return;

    }

    cout<<endl<<endl<<setw(40)<<"按任意键结束";

    getch();

}

char mainmenu() //主菜单(首页)

{

    cout<<"\n\n 欢迎进入学生信息管理系统 "<<endl<<endl;

    cout<<"\n\n [1]管理员 [2] 老 师 " <<endl<<endl;

   char ff=getch();

    return ff;

}

void adminmainmenu() //管理员管理界面

{

    cout<<"\n\n 欢迎进入学生信息管理系统(管理者) "<<endl<<endl

        <<endl

        <<endl

        <<" 1: 录入学生信息 "<<endl<<endl

        <<" 2: 显示学生信息 "<<endl<<endl

        <<" 3: 修改学生信息 "<<endl<<endl

        <<" 4: 删除学生信息 "<<endl<<endl

        <<" 5: 查找学生信息 "<<endl<<endl

        <<" 6: 保存学生信息 "<<endl<<endl

        <<" 7: 排序学生信息"<<endl<<endl

        <<" 8: 返回初始页面"<<endl<<endl

        <<" 0: 退出系统"<<endl;

}

void mainmenu1() //学生管理界面

{

    cout<<"\n\n 欢迎进入学生信息管理系统(老师) "<<endl<<endl

        <<endl

        <<endl

        <<" 1: 显示学生信息 "<<endl<<endl

        <<" 2: 查找学生信息 "<<endl<<endl

        <<" 3: 排序学生信息"<<endl<<endl

        <<" 4: 返回初始页面"<<endl<<endl

        <<" 0: 退出系统"<<endl;

}

 

void clear1()

{

    fstream cl;

    cl.open("inf.txt",ios::out);

    cl.close();

    cout<<"销毁成功";

    exit(1);

}

int main()

{

LIIIII:

    readin();

    system("cls");

    char get = mainmenu();

    if(get=='1')

    {

        char adminname[20],mima[20];

        ifstream in;

        ofstream out;

        in.open("admin.txt",ios::in);

        if(!in)

        {

            cout<<"无管理员账号,请先设定:"<<endl<<endl;

FF:

            cout<<"输入账号名:";

            cin>>adminname;

            cout<<"输入密码:";

            cin>>mima;

            cout<<"确定创建(y/n)";

            char fff=getch();

            if(fff=='y')

            {

                out.open("admin.txt",ios::app);

                out<<adminname<<' '<<mima<<' ';

                system("cls");

                cout<<" 已创建,按任意键返回";

                getch();

                out.close();

                goto LIIIII;

            }

            else if(fff=='n')

                goto LIIIII;

        }

        else

        {

            system("cls");

            cout<<" 已存在用户"<<endl<<endl;

            cout<<"是否新建管理员账户(y/n)";

            char gr=getch();

            if(gr=='y')

            {

                system("cls");

                goto FF;

            }

ss1:

            system("cls");

            cout<<"登录账号:";

            cin>>adminname;

            cout<<"输入密码:";

            cin>>mima;

            char adminname1[20],mima1[20];

            int flog=0;

            while(!in.eof())

            {

                in>>adminname1>>mima1;

                if(!strcmp(adminname,adminname1)&&!strcmp(mima1,mima))

                {

                    flog=0;

                    break;

                }

            }

            if(flog==0)

            {

                system("cls");

                cout<<" 登陆成功 按任意键继续";

                getch();

            }

            else

            {

                cout<<"密码错误"<<endl<<endl;

                cout<<"[1]返回初始界面 [2]重新输入密码";

                char gg=getch();

                if(gg=='1')

                    goto LIIIII;

                else

                {

                    system("cls");

                    goto ss1;

                }

            }

        }

        while(1)

        {

            adminmainmenu();

            char ch;

            ch=getchar();

            system("CLS");

            switch(ch)

            {

            case '1':

                zhuo_yue[student::NUM].input();

                break;

            case '2':

                show();

                break;

            case '3':

                mood();

                break;

            case '4':

                del();

                break;

            case '5':

                findyou();

                break;

            case '6':

                save();

                break;

            case '7':

                soort();

                break;

            case '8':

                goto LIIIII;

            case 'F':

                clear1();

            case '0':

                cout<<"\n\n\n\n 谢谢使用~~";

                exit(1);

            }

        }

    }

    else if(get=='2')

    {

        char stuname[20],stumima[20];

        ifstream in;

        ofstream out;

        in.open("student.txt",ios::in);

        if(!in)

        {

            cout<<"无学生账号,请先设定:"<<endl<<endl;

LL:

            cout<<"输入账号名:";

            cin>>stuname;

            cout<<"输入密码:";

            cin>>stumima;

            cout<<"确定创建(y/n)";

            char fff=getch();

            if(fff=='y')

            {

                out.open("student.txt",ios::app);

                out<<stuname<<' '<<stumima<<' ';

                system("cls");

                cout<<" 已创建,按任意键返回";

                getch();

                out.close();

                goto LIIIII;

            }

            else if(fff=='n')

                goto LIIIII;

        }

        else

        {

            system("cls");

            cout<<" 已存在用户"<<endl<<endl;

            cout<<" 是否新建账户(y/n)"<<endl;

            char gr=getch();

            if(gr=='y')

            {

                system("cls");

                goto LL;

            }

sss:

            system("cls");

            cout<<"登录账号:";

            cin>>stuname;

            cout<<"输入密码:";

            cin>>stumima;

            char stuname1[20],stumima1[20];

            int flog=1;

            while(!in.eof())

            {

                in>>stuname1>>stumima1;

                if(!strcmp(stuname,stuname1)&&!strcmp(stumima1,stumima))

                {

                    flog=0;

                    break;

                }

            }

            if(flog==0)

            {

                system("cls");

                cout<<" 登陆成功 按任意键继续";

                getch();

            }

            else if(flog==1)

            {

                system("cls");

                cout<<"密码错误"<<endl<<endl;

                cout<<"[1]返回初始界面 [2]重新输入密码";

                char gg=getch();

                if(gg=='1')

                    goto LIIIII;

                else

                {

                    system("cls");

                    goto sss;

                }

            }

            in.close();

        }

        while(1)

        {

            mainmenu1();

            char ch;

            ch=getchar();

            system("CLS");

            switch(ch)

            {

            case '1':

                show();

                break;

            case '2':

                findyou();

                break;

            case '3':

                soort();

                break;

            case 'F':

                clear1();

            case '4':

                goto LIIIII;

            case '0':

                cout<<"\n\n\n\n 谢谢使用~~";

                exit(1);

            }

        }

    }

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值