| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 852 人关注过本帖
标题:学生管理系统
只看楼主 加入收藏
riliang_1987
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-12-27
收藏
 问题点数:0 回复次数:1 
学生管理系统
#include<iostream.h>
#include<iomanip>
#include<string.h>
#include<iomanip>
#include<sstream>
#include<fstream>
#include<conio.h>
using namespace std;
//全局变量
int i=0;
int j=0;

class Jiemian     
{
public:
    int jiemian1();
    char jiemian2(int x);
};

int Jiemian::jiemian1()
{
    int a;
    while(1)
    {
       system("cls");
       cout<<endl;
       cout<<"*"<<"欢迎进入学生成绩管理系统"<<"*"<<endl;
       cout<<"*"<<"Welcome!"<<"*"<<endl;
       cout<<endl;
       cout<<endl<<"1 学生\n"<<"2 教师\n"<<"3 退出系统\n";
       cout<<"请选择您的身份(输入相应序号)进入我们的系统!\n";
       cin>>a;
       if(3==a) exit(1);
       if(1==a||2==a)  break;
       cout<<"请输入正确的序号!\n";  
       getch();
    }
    return a;
}

char Jiemian::jiemian2(int x)
{
    char a;
    while(1)
    {
        system("cls");
        cout<<"**"<<"欢迎进入学生成绩管理系统"<<"**"<<endl;
                 cout<<endl;
        if(1==x) cout<<"-----欢迎您进入学生查询系统!-----";
                 cout<<endl;
        if(2==x) cout<<"-----欢迎您进入教师管理系统!-----";
                 cout<<endl;
        cout<<"a 登录\n"<<"b 注册\n"<<"c 返回主界面\n"<<"d 退出系统\n"<<"请选择操作!\n";    
        cin>>a;
        if('d'==a)  exit(1);
        if('a'==a||'b'==a||'c'==a)  break;
        cout<<"请输入正确的字母!\n";
        getch();
    }
    return a;
}


class Register:public Jiemian
{
private:
    string name;
    string cipher;
public:
    bool regist(int x);
    bool load(int x);
};

bool Register::regist(int x)        //注册
{    
    char name[20];
    int a=0;
    string ss;
    while(1)
    {
        cout<<"请设置用户名:";
        cin>>name;
        if(1==x)  
        {
            ifstream infile("用户信息s.txt");    
            for(;getline(infile,ss);)
            {    
                if(ss==name)  {  a=1;  cout<<"用户名重复,请重新设置!"; break;  }
            }
            infile.close();
        }
        if(2==x)   
        {
            ifstream infile("用户信息t.txt");
            for(;getline(infile,ss);)
            {    
                if(ss==name)  {  a=1;  cout<<"用户名重复,请重新设置!"; break;  }
            }
            infile.close();
        }
        if(1==a) a=0;
        else break;
    }
    while(1)
    {
        cout<<"请设置密码:";
        char c,m[50];
        int i=0;
        while(1)
        {
            c=getch();
            if(13==c&&0==i)  continue;
            if(13==c&&i>0)   break;
            m[i]=c;
            cout<<"*";
            i++;
        }
        char*lp1=new char[i+1];
        for(int j=0;j<i;j++)
            lp1[j]=m[j];
        lp1[i]=NULL;
        cipher=lp1;
        delete []lp1;
        cout<<endl<<"请确认密码:";
        i=0;
        string k;
        while(1)
        {
            c=getch();
            if(13==c&&0==i)  continue;
            if(13==c&&i>0)   break;
            m[i]=c;
            cout<<"*";
            i++;
        }
        char*lp2=new char[i+1];
        for(j=0;j<i;j++)
            lp2[j]=m[j];
        lp2[i]=NULL;
        k=lp2;
        delete []lp2;
        if(k!=cipher)
        {
            cout<<endl<<"确认密码失败!请重新设置密码!\n";
        }
        else break;
    }
    ofstream outfile("临时文件.txt");
    outfile<<name<<endl<<cipher<<endl;
    outfile.close();
    ofstream outf("临时用户信息.txt");
    if(1==x)  
    {
        ifstream inf("用户信息s.txt");
        for(string aa;getline(inf,aa);)
            outf<<aa<<endl;
        inf.close();
    }
    if(2==x)  
    {
        ifstream inf("用户信息t.txt");
        for(string aa;getline(inf,aa);)
            outf<<aa<<endl;
        inf.close();
    }
    outf.close();    
    ifstream li1("临时文件.txt");
    ifstream li2("临时用户信息.txt");
    if(1==x)  
    {
        ofstream ou("用户信息s.txt");    
        for(string bb;getline(li1,bb);)
            ou<<bb<<endl;
        li1.close();
        for(string cc;getline(li2,cc);)
            ou<<cc<<endl;
        ou.close();
    }
    if(2==x)  
    {
        ofstream ou("用户信息t.txt");
        for(string bb;getline(li1,bb);)
            ou<<bb<<endl;
        li1.close();
        for(string cc;getline(li2,cc);)
            ou<<cc<<endl;
        ou.close();
    }
    li2.close();    
    cout<<endl<<"注册成功!\n";
    return 0;
}

bool Register::load(int x)      //登录
{
    int a=0;
    string ss;
    char name[20];
    while(1)
    {
        cout<<"请输入用户名:";
        cin>>name;
        if(1==x)
        {
            ifstream infile("用户信息s.txt");
            for(;getline(infile,ss);)
            {    
                if(1==a)   break;
                if(ss==name)  a=1;
            }  
            infile.close();
        }
        if(2==x)
        {
            ifstream infile("用户信息t.txt");
            for(;getline(infile,ss);)
            {    
                if(1==a)   break;
                if(ss==name)  a=1;
            }  
            infile.close();
        }
    cout<<"请输入密码:";
    char c,m[50];
    int i=0;
    while(1)
    {
        c=getch();
        if(13==c&&0==i)  continue;
        if(13==c&&i>0)   break;
        m[i]=c;
        cout<<"*";
        i++;
    }
    char*lp=new char[i+1];
    for(int j=0;j<i;j++)
        lp[j]=m[j];
    lp[i]=NULL;
    cipher=lp;
    if(cipher==ss&&1==a)  break;
    else {  cout<<endl<<"用户名或密码错误!";  getch();  return 0;}
    }
    return 1;
}

class teacher:public Register
{
protected:
    teacher *s[50];
    ofstream *file[50];
    char name[20];
    double math,chinese,english,average,sum;
public:
    teacher()
    {
    }
    teacher(char n[20],double ma,double chin,double eng)
    {
        strcpy(name,n);
        math=ma;
        chinese=chin;
        english=eng;
    }
    void sr();
    void zj();
    void sc();
    void xg();
    void qb();
    void xitong();
    double getsum()
    {
        sum=chinese+english+math;
        return sum;
    }
    double getaver()
    {
        average=getsum()/3;
        return average;
    }

    ~teacher()
    {
    }
};
void teacher::sr()
{
    char c;
    do{
        cout<<"请输入姓名"<<endl;
        cin>>name;
        cout<<"请输入数学成绩:"<<endl;
        cin>>math;
        cout<<"请输入语文成绩:"<<endl;
        cin>>chinese;
        cout<<"请输入外语成绩:"<<endl;
        cin>>english;
        file[j]=new ofstream("d:\\document",ios::ate);
        *file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
        j++;
        s[i]=new teacher(name, math, chinese, english);
        i++;

        cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
        cin>>c;
        int flag2=0;
        do
        {
            if(c!='y'&&c!='n')
            {
                cout<<"指令错误!请重新输入!"<<endl;
                cin>>c;
            }
            else
                flag2=1;
        }while(flag2==0);
        ofstream outflie("d:\\document",ios::ate);
        for(int z=0;z<i;z++)
        {
            outflie<<s;
        }
        outflie.close();
    }while(c=='y');  
}
void teacher::zj()
{
    char c;
    do
    {
        cout<<"请输入您要增加的学生的姓名:"<<endl;
        cin>>name;
        cout<<"请输入数学成绩:"<<endl;
        cin>>math;
        cout<<"请输入语文成绩:"<<endl;
        cin>>chinese;
        cout<<"请输入外语成绩:"<<endl;
        cin>>english;
        file[j]=new ofstream("d:\\document",ios::ate);
        *file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
        j++;
        s[i]=new teacher(name, math, chinese, english);
        i++;
        cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
        cin>>c;
        if(c!='y'&&c!='n')
        {
            cout<<"指令错误!请重新输入!"<<endl;
            cin>>c;
        }
        ofstream inflie("d:\\document",ios::ate);
        for(int z=0;z<i;z++)
        {    
            inflie<<s;
        }
        inflie.close();

    }while(c=='y');
}
void teacher::sc()
{
    char name[20];bool flag3=0;char c;
    do{
        cout<<"请输入您要删除的学生姓名:"<<endl;
        cin>>name;
        ifstream outflie("d:\\document",ios::ate);
        for(int h=0;h<i;h++)
        {
            if(strcmp(name,s[h]->name)==0)
            {
                flag3=1;
                i--;
                do{
                    s[h]=s[h+1];
                    h++;
                }while(h<=i);
            }
        }
        if(flag3==0)
        cout<<"您要求删除的对象本来就不存在!请检查输入的正确性!";
        cout<<"要继续删除吗?(y/n)"<<endl;
        cin>>c;
        if(c!='y'&&c!='n')
        {
            cout<<"指令错误!请重新输入!"<<endl;
            cin>>c;
        }
        outflie.close();
    }while(c=='y');
}
void teacher::xg()
{
    /*ifstream fin("d:\\document",ios::ate)*/
    char name[20];
    double mat,chin,eng;
    int flag2=0;
    char c;
    do
    {
        cout<<"请输入您要修改的学生的姓名:"<<endl;
        cin>>name;
        ofstream inflie("d:\\document",ios::ate);
        for(int h=0;h<i;h++)
        {
            if(strcmp(name,s[h]->name)==0)
            {
                flag2=1;
                cout<<"请输入新的数学成绩:"<<endl;
                cin>>mat;
                cout<<"请输入新的语文成绩:"<<endl;
                cin>>chin;
                cout<<"请输入新的外语成绩:"<<endl;
                cin>>eng;
                s[h]->chinese=chin;
                s[h]->math=mat;
                s[h]->english=eng;
                cout<<"数据修改成功!";
            }
            inflie<<s;
        }
        if(flag2==0)
        {
            cout<<"您要修改的学生本来就不存在!请检查重新输入!"<<endl;
        }
        cout<<"想继续修改吗(y/n)"<<endl;
        cin>>c;
        if(c!='y'&&c!='n')
        {
            cout<<"指令错误!请重新输入!"<<endl;
            cin>>c;
        }
        inflie.close();
    }while(c=='y');  
}
void teacher::qb()
{
    cout<<"本系统所有学生数据如下:"<<endl;
    if(i==0)
    cout<<"管理系统中没有录入数据或者数据已经被删除!"<<endl;
    for(int k=0;k<i;k++)
    {
        cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<     "语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
            <<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<(*s[k]).getsum()
            <<"平均分:"<<" "<<(*s[k]).getaver()<<endl;
    }


}
void teacher::xitong()
{
    cout<<"请选择您需要的操作!"<<endl;
    cout<<"操作:"<<endl;
    cout<<"(0)数据录入"<<endl;
    cout<<"(1)增加人员"<<endl;
    cout<<"(2)删除人员"<<endl;
    cout<<"(3)修改数据"<<endl;
    cout<<"(4)输出所有学生的数据"<<endl;
    cout<<"选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;
    char p;char w;
    int flag2=0;
    do
    {
        cin>>p;
        if((p>='0'&&p<='4'))
            flag2=1;
        else
            cout<<"指令错误!请重新输入:"<<endl;
    }while(flag2==0);
    do
    {
        switch(p)
        {
        case'0':
            {
                teacher te;
                te.sr();
                break;
            }
        case'1':
            {
                teacher te;
                te.zj();
                break;
            }
        case'2':
            {
                teacher te;
                te.sc();
                break;
            }
        case'3':
            {
                teacher te;
                te.xg();
                break;
            }
        case'4':
            {
                teacher te;
                te.qb();
                break;
            }
        }
        cout<<"您想继续进行其他操作吗?(y/n)"<<endl;
        int flag4=0;
        do{
            cin>>w;
            if(w!='y'&&w!='n')
                cout<<"指令错误!请重新输入!"<<endl;
            else
                flag4=1;
        }while(flag4==0);
        if(w=='y')
        {
            cout<<"请输入操作代码"<<endl;
            cout<<"(0)数据录入"<<endl;
            cout<<"(1)增加人员"<<endl;
            cout<<"(2)删除人员"<<endl;
            cout<<"(3)修改数据"<<endl;
            cout<<"(4)输出所有学生的数据"<<endl;
            cin>>p;
        }
    }while(w=='y');    

}
class student:public teacher
{
    char n[20];char c;
public:
    void chazhao();
};
void student::chazhao()
{
        do{
        int flag=0;
        cout<<"请输入你要查询的学生姓名"<<endl;
        cin>>n;
        ifstream outflie("d:\\document",ios::ate);
        for(int s=0;s<i;s++)
        {
            if(strcmp(n,(*s[s]).name)==0)
            {
                flag=1;
                cout<<"您要查询的学生是:"<<(s[s]).name<<endl;
                cout<<(*s[s]).name<<"的总成绩成绩是"<<(s[s]).getsum()<<endl<<"平均成绩是:"<<(*s[s]).getaver()<<endl;
            }
        }
        if(flag==0)
            cout<<"对不起!您要查询的学生不存在!"<<endl;
            cout<<"您想继续查询吗?(y/n)"<<endl;
            cin>>c;
            if(c!='y'&&c!='n')
            {
                cout<<"指令错误!请重新输入!"<<endl;
                cin>>c;
            }
    } while(c=='y');
}
int main()
{

    system("color 9f");
    teacher te;

    while(1)
    {
        int a=te.jiemian1();
        char b;
        bool c;
        do
        {
            b=te.jiemian2(a);
            if('c'==b)  break;
            switch(b)
            {
            case 'a': c=te.load(a);
                break;
            case 'b':  c=te.regist(a);  getch();
                break;
            }
            if(2==a&&'a'==b&&1==c)
            {
                te.xitong();
            }
            if(1==a&&'b'==b&&1==c)
            {
                student stu;
                stu.chazhao();
            }
        }while(0==c);

    }
    
    return 0;
}
搜索更多相关主题的帖子: int include cout endl 
2008-01-07 01:25
riliang_1987
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-12-27
收藏
得分:0 
有哪位高手能指教小弟我!~!
我这个程序哪里错了????
告诉我错在哪里~!~!
2008-01-07 01:26
快速回复:学生管理系统
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030551 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved