zoukankan      html  css  js  c++  java
  • c++大作业 单词消除游戏 源代码

    #include<iostream>
    #include<cstring>
    #include<string>
    #include<vector>
    #include<stdlib.h>
    #include<time.h>
    #include<Windows.h>
    #include<fstream>
    
    using namespace std;
    
    string QuestionBank[3][1000];//分为3个难度,每个有1000个单词。
    int QuestionNum[3] = { 0 };//每个难度一共有几道题
    //user是出题人和答题人共同的基类
    //拥有姓名 ID 密码 等级四个属性 以及这些私有类的读入和输出函数
    class user {
    private:
        string name;
        string ID;
        string Password;
        int level = 0;
    public:
        void getName(string c) {
            //string c;
            name = c;
        }
        void getID(string c) {
            ID = c;
        }
        void getPassword(string c) {
            Password = c;
        }
        void getLevel(int a) {
            level = a;
        }
        string wrtName() {
            return name;
        }    
        string wrtID() {
            return ID;
        }
        string wrtPassword() {
            return Password;
        }
        int wrtLevel() {
            return level;
        }    
        user() {}
        ~user(){}
    };
    //出题人是在user的基础上 新增了出题数目 ,题库序号的类
    //多的函数:出题  升级 新的私有类的读入和输出
    class TestMaker:public user{
    private:
        string name;
        string ID;
        string Password;
        int level=0;
        int testnum=0;
        int testnumMod10;
    public:
        int PersonalBank[2][1000];//存储出题的难度等级和序号。
        void MakeTest(int hard,string test) {//出题时把这个单词的难度一起读入
            int num;
            //length = test.length();
            //if ((length >= 1) && (length <= 6))hard = 0;
            //else if (length <= 12)hard = 1;
            //else hard = 2;
    
            QuestionNum[hard]++;
            num = QuestionNum[hard];
            QuestionBank[hard][num] = test;
            testnum++;
            testnumMod10 = testnum;
            PersonalBank[0][testnum] = hard;
            PersonalBank[1][testnum] = num;
        }
        void getTestnum(int a) {
            testnum = a;
        }
        void levelup() {//每出十题升一级
            level = testnum / 10;
        }
        void InforOut() {
            //cout << "姓名:";
            //cout << name << endl;
            cout << "等级:" << level << endl;
            cout << "出题数目:" << testnum << endl;
        }
        /*void getPersonalBank(int a[2][1000]) {
            int i;
            for (i = 1; i <= testnum; i++) {
                PersonalBank[1][i] = a[1][i];
                PersonalBank[0][i] = a[0][i];
            }
        }*/
        int wrttestnum() {
            return(testnum);
        }
        TestMaker(const TestMaker &a) {//用于排序的拷贝构造函数
            int i;
            name = a.name;
            ID = a.ID;
            Password = a.Password;
            level = a.level;
            testnum = a.testnum;
            testnumMod10 = a.testnumMod10;
            for (i = 1; i <= testnum; i++) {
                PersonalBank[0][i] = a.PersonalBank[0][i];
                PersonalBank[1][i] = a.PersonalBank[1][i];
            }
        }
        TestMaker() {}
        ~TestMaker(){}
    };
    //玩家类多了等级 经验值和答题成功数目
    //多的函数:升级 新增属性的读入和输出
    class Player:public user{
    private:
        string name;
        string ID;
        string Password;
        int level = 0;
        int experience = 0;
        int outpost = 0;//答题成功数目
    public:
        void LevelUp(int a,int b) {//闯关成功后,a作为难度读入,b作为时间读入,获得经验和a,b都有关系
            outpost++;
            experience = experience + ((a + 1) * 10) + ((3000 - b) / 50);
            while (experience > 100) {
                level++;
                experience = experience - 100;
            }
        }
        void getExperience(int a) {
            experience = a;
        }
        void getOutpost(int a) {
            outpost = a;
        }
        int wrtExperience() {
            return experience;
        }
        int wrtOutpost() {
            return outpost;
        }
        void InforOut() {
            //cout << "姓名:" << name << endl;
            cout << "等级:" << level << endl;
            cout << "经验:" << experience << endl;
            cout << "答题数目:" << outpost << endl;
        }
        Player(const Player &a) {
            name = a.name;
            ID = a.ID;
            Password = a.Password;
            level = a.level;
            experience = a.experience;
            outpost = a.outpost;
        }
        Player(){}
        ~Player(){}
    };
    
    TestMaker TestMakerList[100];
    int TestMakerNum=0;
    Player PlayerList[100];
    int PlayerNum=0;
    int yournum;
    
    //对于排行榜功能,用简单的冒泡函数实现
    void paixu() {
        int i, j;
        TestMaker t;
        if (TestMakerNum == 0)cout << "无出题人" << endl;
        else {
            for (i = 1; i <= TestMakerNum; i++) {
                for (j = i; j <= TestMakerNum; j++) {
                    if (TestMakerList[i].wrttestnum() < TestMakerList[j].wrttestnum()) {
                        t = TestMakerList[i];
                        TestMakerList[i] = TestMakerList[j];
                        TestMakerList[j] = t;
                    }
                }
            }
    
            cout << "对出题人按出题数从高到低排序:" << endl;
            for (i = 1; i <= TestMakerNum; i++) {
                cout <<"姓名:"<< TestMakerList[i].wrtName() << " 出题数:" << TestMakerList[i].wrttestnum() << endl;
            }
        }
        if (PlayerNum == 0)cout << "无答题人" << endl;
        else {
            Player m;
            for (i = 1; i <= PlayerNum; i++) {
                for (j = i; j <= PlayerNum; j++) {
                    if ((PlayerList[i].wrtLevel() < PlayerList[j].wrtLevel())
                        || ((PlayerList[i].wrtLevel() == PlayerList[j].wrtLevel()) && (PlayerList[i].wrtExperience() < PlayerList[j].wrtExperience()))) {
                        m = PlayerList[i];
                        PlayerList[i] = PlayerList[j];
                        PlayerList[j] = m;
                    }
                }
            }
            cout << "对答题人按等级经验从高到低排序:" << endl;
            for (i = 1; i <= PlayerNum; i++) {
                cout <<"姓名:"<< PlayerList[i].wrtName() << " 等级:" << PlayerList[i].wrtLevel() << " 经验值:" << PlayerList[i].wrtExperience() << endl;
            }
        }
        return;
    }
    //第一种出题模式:难度等级不变
    void MakeTest1(int hard) {
        int max, length;
        string ans;
        int flag = 0;
        max = QuestionNum[hard];
        while (1) {
            srand((unsigned)time(NULL));
            int x;
            x = rand();
            x = (x % max) + 1;
            while (1) {
                cout << QuestionBank[hard][x];
                length = QuestionBank[hard][x].length();
                Sleep(3000);
                for (int i = 1; i <= length; i++)cout << "";
                cout << "输入答案:";
                cin >> ans;
                if (ans == QuestionBank[hard][x]) {
                    cout << "答案正确!" << endl;
                    PlayerList[yournum].LevelUp(hard,3000);
                    break;
                }
                else cout << "worng answer!" << endl;
            }
            cout << "continue or not? 1 or 0" << endl;
            cin >> flag;
            if (flag == 0)break;
        }
    }
    //第二种出题模式:难度等级递增
    void MakeTest2() {
        int max, length,hard;
        string ans;
        int flag = 0, gamelevel = 0;
        
        while (1) {
            gamelevel++;
            if (((gamelevel % 9) <= 3)&&((gamelevel%9)>=1))hard = 0;
            else if (((gamelevel % 9) <= 6)&&((gamelevel%9)>=4))hard = 1;
            else hard = 2;
    
            cout << "当前关卡:" << gamelevel << " 当前难度:" << hard << endl;
            max = QuestionNum[hard];
            srand((unsigned)time(NULL));
            int x;
            x = rand();
            x = (x % max) + 1;
            while (1) {
                cout << QuestionBank[hard][x];
                length = QuestionBank[hard][x].length();
                Sleep(3000);
                for (int i = 1; i <= length; i++)cout << "";
                cout << "输入答案: ";
                cin >> ans;
                if (ans == QuestionBank[hard][x]) {
                    cout << "答案正确!" << endl;
                    PlayerList[yournum].LevelUp(hard,3000);
                    break;
                }
                else cout << "worng ans!" << endl;
            }
            cout << "continue or not? 1 or 0" << endl;
            cin >> flag;
            if (flag == 0)break;
        }
    }
    //第三种出题模式:进行轮数增多
    void MakeTest3(int hard) {
        int max, length,Gametime=1;
        string ans;
        int flag = 0, gamelevel = 0;
        int i, j;
        max = QuestionNum[hard];
        while (1) {
            gamelevel++;
            if ((gamelevel% 3) == 0)Gametime++;//设定是每三关之后,轮数加一
    
            cout << "当前关卡:" << gamelevel << " 当前轮数:" << Gametime << endl;
    
            for (j = 1; j <= Gametime; j++) {
                srand((unsigned)time(NULL));
                int x;
                x = rand();
                x = (x % max) + 1;
    
                while (1) {
                    cout << QuestionBank[hard][x];
                    length = QuestionBank[hard][x].length();
                    Sleep(3000);
                    for (i = 1; i <= length; i++)cout << "";
                    cout << "输入答案: ";
                    cin >> ans;
                    if (ans == QuestionBank[hard][x]) {
                        cout << "答案正确!" << endl;
                        PlayerList[yournum].LevelUp(hard,3000);
                        break;
                    }
                    else cout << "worng ans!" << endl;
                }
            }
            cout << "continue or not? 1 or 0" << endl;
            cin >> flag;
            if (flag == 0)break;
        }
    }
    //第四种出题模式:答题时间缩短
    void MakeTest4(int hard) {
        int max, length, waittime=3500;
        string ans;
        int flag = 0, gamelevel = 0;
        max = QuestionNum[hard];
        while (1) {
            gamelevel++;
            if (waittime > 1000)waittime = waittime - 500;//每关等待时间减少0.5秒 1秒为下限
    
            cout << "当前关卡:" << gamelevel << " 当前时长:" << waittime <<"ms"<< endl;
            srand((unsigned)time(NULL));
            int x;
            x = rand();
            x = (x % max) + 1;
            while (1) {
                cout << QuestionBank[hard][x];
                length = QuestionBank[hard][x].length();
                Sleep(waittime);
                for (int i = 1; i <= length; i++)cout << "";
                cout << "输入答案: ";
                cin >> ans;
                if (ans == QuestionBank[hard][x]) {
                    cout << "答案正确!" << endl;
                    PlayerList[yournum].LevelUp(hard,waittime);
                    break;
                }
                else cout << "worng ans!" << endl;
            }
            cout << "continue or not? 1 or 0" << endl;
            cin >> flag;
            if (flag == 0)break;
        }
    }
    
    int main() {
        int i,j;
        string name,id, password;
        string pdid, pdpassword;
    
        int level = 0, testnum = 0, experience = 0, outpost = 0, gamelevel = 0;
        ifstream user_file;
        ifstream word_file;
        ofstream user_out;
        ofstream word_out;
        //先打开D盘中的读入文件,读入我们之前写入的用户信息
        user_file.open("D:\user.txt", ios::_Nocreate | ios::in);
        if (user_file) {
            //cout << "user_file succeed" << endl;
            user_file >> TestMakerNum;
            for (i = 1; i <= TestMakerNum; i++) {
                user_file >> name >> id >> password >> level >> testnum;
                TestMakerList[i].getID(id);
                TestMakerList[i].getName(name);
                TestMakerList[i].getPassword(password);
                TestMakerList[i].getTestnum(testnum);
                TestMakerList[i].getLevel(level);
                for (j = 1; j <= testnum; j++) {
                    int a, b;
                    user_file >> a >> b;
                    TestMakerList[i].PersonalBank[0][j] = a;
                    TestMakerList[i].PersonalBank[1][j] = b;
                }
            }
            user_file >> PlayerNum;
            //cout << "!:" << PlayerNum << endl;
            for (i = 1; i <= PlayerNum; i++) {
                user_file >> name >> id >> password >> level >> experience >> outpost;
                PlayerList[i].getID(id);
                PlayerList[i].getName(name);
                PlayerList[i].getPassword(password);
                PlayerList[i].getExperience(experience);
                PlayerList[i].getLevel(level);
                PlayerList[i].getOutpost(outpost);
            }
        }
        //然后关闭文件
        if (user_file) {
            //cout << "user_file close!" << endl;
            user_file.close();
        }
        //再打开之前的题库文件,读入出过的题目
        word_file.open("D:\word.txt", ios::_Nocreate | ios::in);
        //如果之前没出过题目,则读入自带题库
        if (!word_file) {//如果没有 系统自建一个文件库
            //Sleep(3000);
            //cout << "!word_file succeed" << endl;
            QuestionNum[0] = 11;
            QuestionNum[1] = 11;
            QuestionNum[2] = 11;
    
            QuestionBank[0][1] = "apple";
            QuestionBank[0][2] = "chorus";
            QuestionBank[0][3] = "facet";
            QuestionBank[0][4] = "denial";
            QuestionBank[0][5] = "black";
            QuestionBank[0][6] = "wind";
            QuestionBank[0][7] = "sheep";
            QuestionBank[0][8] = "chaos";
            QuestionBank[0][9] = "dazzle";
            QuestionBank[0][10] = "gray";
            QuestionBank[0][11] = "feast";
            //1-6
            QuestionBank[1][1] = "abandon";
            QuestionBank[1][2] = "ambitious";
            QuestionBank[1][3] = "bachelor";
            QuestionBank[1][4] = "basement ";
            QuestionBank[1][5] = "biography";
            QuestionBank[1][6] = "casualty";
            QuestionBank[1][7] = "ceramic";
            QuestionBank[1][8] = "degrade";
            QuestionBank[1][9] = "denounce";
            QuestionBank[1][10] = "disrupt";
            QuestionBank[1][11] = "fixture";
            //7-10
            QuestionBank[2][1] = "apprehension";
            QuestionBank[2][2] = "adolescent";
            QuestionBank[2][3] = "bureaucracy";
            QuestionBank[2][4] = "coincidence";
            QuestionBank[2][5] = "declaration";
            QuestionBank[2][6] = "descendant";
            QuestionBank[2][7] = "destructive";
            QuestionBank[2][8] = "forthcoming";
            QuestionBank[2][9] = "masterpiece";
            QuestionBank[2][10] = "mediterranean";
            QuestionBank[2][11] = "metropolitan";
            //11
        }
        if (word_file) {
            //cout << "word_file succeed" << endl;
            for (i = 0; i <= 2; i++) {
                word_file >> QuestionNum[i];
            }
            for (i = 0; i <= 2; i++) {
                for (j = 1; j <= QuestionNum[i]; j++) {
                    word_file >> QuestionBank[i][j];
                }
            }
        }
        if (word_file) {
            //cout << "word_file close" << endl;
            word_file.close();
        }
    
        int  c = 0;
        //因为没能实现图形化,黑框版本是要做到不断地询问客户需求地
        while (1) {        
             c = 0; 
            cout << "选择您的需求:1:登陆 2:注册 3:查询玩家 4:查看排行榜 5:结束程序" << endl;
            cin >> c;
    
            
            //int cc = 0;
            //登陆的情况
            if (c == 1) {        
                int type = 0;
                int flag = 0;
                int dlflag = 0;
                    cout << "您是出题人还是答题人,出题人请输入1,答题人请输入2:";
                    cin >> type;
                    //此处需要加一点东西 
                    
                    if (type == 1) {//出题人
                        if (TestMakerNum == 0) {
                            cout << "目前无出题人注册!" << endl;
                            flag = 0;
                        }
                        else {
                            flag = 1;
                            //int IDrepeat = 0;
                            cout << "请输入id,回车结束: ";
                            cin >> id;
                            
                            cout << "请输入密码,回车结束: ";
                            cin >> password;
                            dlflag = 0;
                            for (i = 1; i <= TestMakerNum; i++) {
                                pdid = TestMakerList[i].wrtID();
                                pdpassword = TestMakerList[i].wrtPassword();
                                if (id.compare(pdid) == 0) {
                                    if (password.compare(pdpassword) == 0) {
                                        yournum = i;
                                        name = TestMakerList[i].wrtName();
                                        testnum = TestMakerList[i].wrttestnum();
                                        level = TestMakerList[i].wrtLevel();
                                        dlflag = 1;
                                        break;
                                    }
                                }
                            }
                            if (dlflag == 0)cout << "账号或密码错误。" << endl;
                        }
                    }
    
    
                    if (type == 2) {
                        if (PlayerNum == 0) {
                            cout << "目前无答题人注册!" << endl;
                            flag = 0;
                        }
                        else {
                            flag = 1;
                            cout << "请输入id,回车结束: ";
                            cin >> id;
                            cout << "请输入密码,回车结束: ";
                            cin >> password;
                            dlflag = 0;
                            for (i = 1; i <= PlayerNum; i++) {
                                if (id.compare(PlayerList[i].wrtID())==0) {
                                    if (password.compare(PlayerList[i].wrtPassword())==0) {
                                        yournum = i;
                                        name = PlayerList[i].wrtName();
                                        experience = PlayerList[i].wrtExperience();
                                        outpost = PlayerList[i].wrtOutpost();
                                        level = PlayerList[i].wrtLevel();
                                        dlflag = 1;
                                        break;
                                    }
    
                                }
                            }
                            if (dlflag == 0)cout << "账号或密码错误。" << endl;
                        }
                    }
                    if ((flag == 1)&&(dlflag==1)) {//登陆成功了
                        cout << "您的个人信息为:" << endl;
                        if (type == 1) {
                            cout << "出题人:" << endl;
                            cout << "姓名:" << TestMakerList[i].wrtName() << endl;
                            TestMakerList[yournum].InforOut();
                        }
                        if (type == 2) {
                            cout << "答题人:" << endl;
                            cout << "姓名:" << PlayerList[i].wrtName() << endl;
                            PlayerList[yournum].InforOut();
                        }
                        string Npassword;
                        string word;
                        int a, b, pdsame = 0, length;//b:难度等级 pdsame:判断是否为重复的单词
                        int hard;
                        int cc = 0;
                        while (type == 1) {
                            cout << "请选择您的需求:" << endl;
                            cout << "1.修改密码 2.出题 3.登出" << endl;
                            cin >> cc;
                            if (cc == 1) {
                                cout << "old password:" << endl;
                                cin >> Npassword;
                                if (Npassword != password)cout << "password worng!" << endl;
                                else {
                                    cout << "new password:" << endl;
                                    cin >> Npassword;
                                    password = Npassword;
                                    TestMakerList[yournum].getPassword(password);
                                    cout << "修改成功!" << endl;
                                }
                            }
                            while (cc == 2) {
                                //cout << "请输入难度等级(0,1,2,3,4):" << endl;
                                //cin >> a;
                                cout << "请输入单词" << endl;
                                cin >> word;
                                length = word.length();
                                if ((length >= 1) && (length <= 6))b = 0;
                                else if (length <= 10)b = 1;
                                else b = 2;
    
                                for (i = 1; i <= QuestionNum[b]; i++) {
                                    if (QuestionBank[b][i] == word)pdsame = 1;
                                }
                                if (pdsame == 1) {
                                    cout << "单词与词库中已有词汇重复!" << endl;
                                    pdsame = 0;
                                }
                                else {
                                    TestMakerList[yournum].MakeTest(b, word);
                                    testnum++;
                                    //TestMakerList[i].getTestnum(testnum);
                                    TestMakerList[i].levelup();
                                    cout << "出题成功!" << endl;
                                }
                                cout << "是否继续出题?1:是 2:否" << endl;
                                cin >> a;
                                if (a == 2)break;
                            }
                            if (cc == 3) {
                                yournum = 0;
                                cout << "成功登出!" << endl;
                                break;
                            }
                        }
                        while (type == 2) {
                            cout << "请选择您的需求:" << endl;
                            cout << "1.修改密码 2.答题 3.登出" << endl;
                            cin >> cc;
                            if (cc == 1) {
                                cout << "old password:" << endl;
                                cin >> Npassword;
                                if (Npassword != password)cout << "password worng!" << endl;
                                else cout << "new password:" << endl;
                                cin >> Npassword;
                                password = Npassword;
                                PlayerList[yournum].getPassword(password);
                                cout << "修改成功!" << endl;
                            }
                            if (cc == 2) {
                                cout << "请输入游戏模式:" << endl;
                                cout << "1、单词难度不变 2、单词难度递增 3、进行轮数增多; 4、单词显示时间缩短" << endl;
                                cin >> a;
                                if (a == 1) {
                                    cout << "请输入难度等级(0,1,2):" << endl;
                                    cin >> hard;
                                    MakeTest1(hard);
                                }
                                if (a == 2) {
                                    MakeTest2();
                                }
                                if (a == 3) {
                                    cout << "请输入难度等级(0,1,2):" << endl;
                                    cin >> hard;
                                    MakeTest3(hard);
                                }
                                if (a == 4) {
                                    cout << "请输入难度等级(0,1,2):" << endl;
                                    cin >> hard;
                                    MakeTest4(hard);
                                }
                            }
                            if (cc == 3) {
                                yournum = 0;
                                cout << "成功登出!" << endl;
                                break;
                            }
                        }
                    }
                    
                }
            //注册的情况 要注意判断ID重复
            if (c == 2) {
                int type = 0;
                    cout << "您是出题人还是答题人,出题人请输入1,答题人请输入2:";
                    cin >> type;
                    if (type == 1) {
                        TestMakerNum++;//都是从1 开始的!
                        yournum = TestMakerNum;
                        int IDrepeat=0;
                        
                        while (1)  {
                            cout << "请输入id(长度大于6),回车结束: ";
                            cin >> id;
                            while (id.length() <= 6) {
                                cout << "请输入长度大于6的id!" << endl;
                                cin >> id;
                            }
                            for (i = 1; i <= TestMakerNum-1; i++) {
                                if (TestMakerList[i].wrtID() == id) {
                                    IDrepeat = 1;
                                }
                            }
                            if (IDrepeat == 0)break;
                            else cout << "ID重复,请重新输入!" << endl;
                        }
                        
                        cout << "请输入密码(长度大于6),回车结束: ";
                        cin >> password;
                        while (password.length() <= 6) {
                            cout << "请输入长度大于6的密码!" << endl;
                            cin >> password;
                        }
                        cout << "请输入姓名,回车结束:";
                        cin >> name;
                        TestMakerList[yournum].getID(id);
                        TestMakerList[yournum].getName(name);
                        TestMakerList[yournum].getPassword(password);
                        cout << "注册完成!您的个人信息为:" << endl;
                        if (type == 1) {
                            cout << "出题人:" << endl;
                            cout << "姓名:" << name << endl;
                            TestMakerList[yournum].InforOut();
                        }
                    }
                    if (type == 2) {
                        PlayerNum++;
                        yournum = PlayerNum;
                        //cout << "!:" << PlayerNum << endl;
                        int IDrepeat=0;
                        while (1) {
                            cout << "请输入id(长度大于6),回车结束: ";
                            cin >> id;
                            while (id.length() <= 6) {
                                cout << "请输入长度大于6的id!" << endl;
                                cin >> id;
                            }
                            for (i = 1; i <= PlayerNum-1; i++) {
                                if (PlayerList[i].wrtID() == id) {
                                    IDrepeat = 1;
                                }
                            }
                            if (IDrepeat == 0)break;
                            else cout << "ID重复,请重新输入!" << endl;
                        }
                        cout << "请输入密码(长度大于6),回车结束: ";
                        cin >> password;
                        while (password.length() <= 6) {
                            cout << "请输入长度大于6的密码!" << endl;
                            cin >> password;
                        }
                        cout << "请输入姓名,回车结束:";
                        cin >> name;
                        PlayerList[yournum].getID(id);
                        PlayerList[yournum].getName(name);
                        PlayerList[yournum].getPassword(password);
                        cout << "注册完成!您的个人信息为:" << endl;
                        if (type == 2) {
                            cout << "答题人:" << endl;
                            cout << "姓名:" << name << endl;
                            PlayerList[yournum].InforOut();
                        }
                    }
                    
                }
    
            int accord;
            
            int find = 0;
            //查找功能
            if (c == 3) {
                int type = 0;
                find = 0;
                cout << "您想查询出题人还是答题人?1:出题人 2:答题人" << endl;
                cin >> type;
                if (type == 1) {
                    cout << "您想按照1姓名 2等级 3出题数 查询:" << endl;
                    cin >> accord;
                    if (accord == 1) {
                        cout << "请输入姓名:" << endl;
                        cin >> name;
                        for (i = 1; i <= TestMakerNum; i++) {
                            if (name == TestMakerList[i].wrtName()) {
                                cout << "用户个人信息为:" << endl;
                                name = TestMakerList[i].wrtName();
                                cout << "姓名:" << name << endl;
                                TestMakerList[i].InforOut();
                                find = 1;
                                //break;
                            }
                        }
                        if (find == 0)cout << "用户不存在!" << endl;
                    }
                    if (accord == 2) {
                        cout << "请输入等级:" << endl;
                        cin >> level;
                        for (i = 1; i <= TestMakerNum; i++) {
                            if (level == TestMakerList[i].wrtLevel()) {
                                cout << "用户个人信息为:" << endl;
                                name = TestMakerList[i].wrtName();
                                cout << "姓名:" << name << endl;
                                TestMakerList[i].InforOut();
                                find = 1;
                                //break;
                            }
                        }
                        if (find == 0)cout << "用户不存在!" << endl;
                    }
                    if (accord == 3) {
                        cout << "请输入出题数:" << endl;
                        cin >> testnum;
                        for (i = 1; i <= TestMakerNum; i++) {
                            if (testnum == TestMakerList[i].wrttestnum()) {
                                cout << "用户个人信息为:" << endl;
                                name = TestMakerList[i].wrtName();
                                cout << "姓名:" << name << endl;
                                TestMakerList[i].InforOut();
                                find = 1;
                                //break;
                            }
                        }
                        if (find == 0)cout << "用户不存在!" << endl;
                    }
                }
                if (type == 2) {
                    cout << "您想按照1姓名 2等级 3答题数 查询:" << endl;
                    cin >> accord;
                    if (accord == 1) {
                        cout << "请输入姓名:" << endl;
                        cin >> name;
                        for (i = 1; i <= PlayerNum; i++) {
                            if (name == PlayerList[i].wrtName()) {
                                cout << "用户个人信息为:" << endl;
                                name = PlayerList[i].wrtName();
                                cout << "姓名:" << name << endl;
                                PlayerList[i].InforOut();
                                find = 1;
                                //break;
                            }
                        }
                        if (find == 0)cout << "用户不存在!" << endl;
                    }
                    if (accord == 2) {
                        cout << "请输入等级:" << endl;
                        cin >> level;
                        for (i = 1; i <= PlayerNum; i++) {
                            if (level == PlayerList[i].wrtLevel()) {
                                cout << "用户个人信息为:" << endl;
                                name = PlayerList[i].wrtName();
                                cout << "姓名:" << name << endl;
                                PlayerList[i].InforOut();
                                find = 1;
                                //break;
                            }
                        }
                        if (find == 0)cout << "用户不存在!" << endl;
                    }
                    if (accord == 3) {
                        cout << "请输入答题数:" << endl;
                        cin >> outpost;
                        for (i = 1; i <= PlayerNum; i++) {
                            if (outpost == PlayerList[i].wrtOutpost()) {
                                cout << "用户个人信息为:" << endl;
                                name = PlayerList[i].wrtName();
                                cout << "姓名:" << name << endl;
                                PlayerList[i].InforOut();
                                find = 1;
                                //break;
                            }
                        }
                        if (find == 0)cout << "用户不存在!" << endl;
                    }
                }
    
            }
            //排行榜功能 查询后直接输出
            if (c == 4)paixu();
            if (c == 5)break;
        }
        //cout << "1" << endl;
        user_out.open("D:\user.txt", ios::out);
        //cout << "2" << endl;
        if (user_out) {
            //cout << "user_out succeed" << endl;
            user_out << TestMakerNum << endl;
            /*user_file >> name >> id >> password >> level >> testnum;
            TestMakerList[i].getID(id);
            TestMakerList[i].getName(name);
            TestMakerList[i].getPassword(password);
            TestMakerList[i].getTestnum(testnum);
            TestMakerList[i].getLevel(level);
            for (j = 1; j <= testnum; j++) {
                int a, b;
                user_file >> a >> b;
                TestMakerList[i].PersonalBank[0][j] = a;
                TestMakerList[i].PersonalBank[1][j] = b;
            }*/
            for (i = 1; i <= TestMakerNum; i++) {
                name = TestMakerList[i].wrtName();
                id = TestMakerList[i].wrtID();
                password = TestMakerList[i].wrtPassword();
                level = TestMakerList[i].wrtLevel();
                testnum = TestMakerList[i].wrttestnum();
                user_out << name << ' ' << id << ' ' << password << endl;
                user_out << level << endl;
                user_out << testnum << endl;
                for (j = 1; j <= testnum; j++) {
                    user_out << TestMakerList[i].PersonalBank[0][j] << ' ' << TestMakerList[i].PersonalBank[1][j] << endl;
                }
            }
            user_out << PlayerNum << endl;
            for (i = 1; i <= PlayerNum; i++) {
                name = PlayerList[i].wrtName();
                id = PlayerList[i].wrtID();
                password = PlayerList[i].wrtPassword();
                level = PlayerList[i].wrtLevel();
                experience = PlayerList[i].wrtExperience();
                outpost = PlayerList[i].wrtOutpost();
                user_out << name << ' ' << id << ' ' << password << endl;
                user_out << level << endl;
                user_out << experience << endl;
                user_out << outpost << endl;
            }
        }
        if (user_out) {
            //cout << "user_out close" << endl;
            user_out.close();
        }
        word_out.open("D:\word.txt", ios::out); 
        if (word_out) {
            //cout << "word_out close" << endl;
            for (i = 0; i <= 2; i++) {
                word_out << QuestionNum[i] << endl;
            }
            for (i = 0; i <= 2; i++) {
                for (j = 0; j <= QuestionNum[i]; j++) {
                    word_out << QuestionBank[i][j] << ' ';
                }
                word_out << endl;
            }
        }
        if (word_out) {
            //cout << "word_out close" << endl;
            word_out.close();
        }
    
        return 0;
    }

    以上为该大作业代码加一部分注释

  • 相关阅读:
    Java加密AES算法及spring中应用
    IO流理解方式小结
    Spring CommonsMultipartResolver上传文件小结
    SpringMvc项目加载顺序及上下文小结
    Session学习小结
    MySql实现Oracle的row_number()over(partition by ... order by ...)
    Oracle存储过程小解
    mysql存储过程小解
    Java final关键字
    linux 同步 rsync的使用——远程服务器同步配置
  • 原文地址:https://www.cnblogs.com/liuxinyu/p/10982288.html
Copyright © 2011-2022 走看看