| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1335 人关注过本帖
标题:宿舍管理查询系统
取消只看楼主 加入收藏
peng823
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-1-4
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:0 
宿舍管理查询系统
想在查询前增加排序功能(排序方式不限)
#include<iostream>
#include<fstream>
#include<string>
#include<conio.h>
#include<Windows.h>
using namespace std;

int i=0;
class Student
{private:
    string number[100];
    string name[100];
    string address[100];
   
public:
    void add()
    {      
        cout<<"***************新增学生信息****************"<<endl;//添加学生信息
        cout<<"输入姓名"<<endl;
        cin>>name[i];
        cout<<"输入学号"<<endl;
        cin>>number[i];
        cout<<"输入房号"<<endl;
        cin>>address[i];
        save();
        cout<<"******添加成功!******"<<endl;
        i++;
            cout<<"是否继续添加(Y/N)?"<<endl;
            char c;
            cin>>c;
            if(toupper(c)=='Y')
            {
                add();
            }
            else
            {
                show();
                return;   
            }
    }



    void del()//删除
    {
    cout<<"请输入要删除的姓名"<<endl;
    string na;
    cin>>na;
        for(int j=0; j < i; j++)
        {
            string *a = &name[j];
            if(*a == na)
            {
                cout<<"姓名:"<<name[j]<<endl;
                cout<<"学号:"<<number[j]<<endl;
                cout<<"房号:"<<address[j]<<endl;
                break;
            }
            else
            {
            cout<<"没有该学生的信息!"<<endl;
            show();
            return;
            }
        }
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
        FOREGROUND_INTENSITY |
             FOREGROUND_RED);
        cout<<"请确认是否删除(Y/N)?"<<endl;
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
            FOREGROUND_INTENSITY
           | FOREGROUND_GREEN);
        char a;
        cin>>a;
        if(toupper(a)=='Y')
        {
            for(int j=0;j<i;j++)
            {
                string *p=&name[j];
                if(na == *p)
                {
                    name[j] = name[i - 1];
                    number[j] = number [i - 1];
                    address[j]=address[i-1];
                    i--;
                }
            }

            cout<<"***********已删除!!!************"<<endl;
             cout<<"是否继续删除(Y/N)?"<<endl;
            char c;
             cin>>c;
            if(toupper(c)=='Y')
            {
                del();
                return;
            }
            else
            {
                show();
                return;
            }   
               
        }
        else
        {
            show();
            return;
        }
    }



    void modif(int j)
    {
        cout<<"输入修改后姓名"<<endl;
        cin>>name[j];
        cout<<"输入修改后学号"<<endl;
        cin>>number[j];
        cout<<"输入修改后房号"<<endl;
        cin>>address[j];
        cout << "******修改完成!******" << endl;
        show();
        return;
    }
    void modify()
    {
        string na;
        cout<<"请输入要修改的姓名"<<endl;
        cin >> na;
        int j = 0;
        for(; j < i; j++)
        {
            string *c = &name[j];
            if(*c == na)
            {
                cout<<"姓名:"<<name[j]<<endl;
                cout<<"学号:"<<number[j]<<endl;
                cout<<"房号:"<<address[j]<<endl;
                break;
            }
            else
            {
            cout<<"没有该学生的信息!"<<endl;
            show();
            return;
            }
        }
        modif(j);
        return;
    }




void find()//查找
    {
   
        cout<<"                     ┏━━━━━━━━━━━━━┓\n";
        cout<<"                              查找方式         ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃1.按姓名查找              ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃2.按学号查找              ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃3.按房号查找              ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃输入1——3进行选择        ┃\n";
        cout<<"                     ┗━━━━━━━━━━━━━┛\n";
        cout<<"请输入:"<<endl;

        int n;
            do{
                cin>>n;
                if(n==1||n==2||n==3)
                {
                    switch(n)
                    {
                    case 1:find1();break;
                    case 2:find2();break;
                    case 3:find3();break;
                    }
                    show();
                    return;
                                 }
                else   
                    cout<<"输入错误,请重新输入"<<endl;
               }
            while(true);

        cout<<"是否继续查找(Y/N)?"<<endl;
        char c;
        cin>>c;
        if(toupper(c)=='Y')
        {
            find();
        }
        else
        {
            show();
            return;
        }

    }


    void find1()//按姓名查找
    {   
            cout<<"请输入要查找的姓名"<<endl;
            string na;
            cin>>na;
            bool test = false;
            for(int j=0;j<i;j++)
            {
                string* p = &name[j];
                if(*p==na)
                {
                    cout<<"姓名:"<<name[j]<<endl;
                    cout<<"学号:"<<number[j]<<endl;
                    cout<<"房号:"<<address[j]<<endl;
                    cout<<"******查找成功******"<<endl;
                    test = true;
                };
            }
            if(test == false)
            {
                cout << "未找到,请重新输入要查找的姓名" << endl;
                find1();
            }
    }

    void find2()//按学号查找
    {   
            cout<<"请输入要查找的学号"<<endl;
            //output();
            string num;
            cin>>num;   
            bool test = false;
            for(int j=0;j<i;j++)
            {
                string *p=&number[j];
                if(*p==num)
                {
                    cout<<"姓名:"<<name[j]<<endl;
                    cout<<"学号:"<<number[j]<<endl;
                    cout<<"房号:"<<address[j]<<endl;
                    cout<<"******查找成功******"<<endl;
                    test = true;
                };
            }
            if(test == false)
            {
                cout << "未找到,请重新输入要查找的学号" << endl;
                find2();
                  }      
    }

    void find3()
    {   
            cout<<"请输入要查找的房号"<<endl;
            string add;
            cin>>add;
            bool test = false;
            for(int j=0;j<i;j++)
            {
                string* p = &address[j];
                if(*p==add)
                {
                    cout<<"姓名:"<<name[j]<<endl;
                    cout<<"学号:"<<number[j]<<endl;
                    cout<<"房号:"<<address[j]<<endl;
                    cout<<"******查找成功******"<<endl;
                    test = true;
                };
            }
            if(test == false)
            {
                cout << "未找到,请重新输入要查找的房号" << endl;
                find3();
            }
    }


    void look()
    {
        for(int j=0;j<i;j++)
        {
            cout<<"姓名:"<<name[j]<<endl;
            cout<<"学号:"<<number[j]<<endl;
            cout<<"房号:"<<address[j]<<endl;
            
        }
        cout<<"预览成功!"<<endl;   
        cout<<"                     ┏━━━━━━━━━━━━━┓\n";
        cout<<"                     ┃1.添                    ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃2.删                    ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃3.修                    ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃4.清空管理软件            ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃5.返回主菜单              ┃\n";
        cout<<"                     ┃━━━━━━━━━━━━━┃\n";
        cout<<"                     ┃输入1——5进行选择        ┃\n";
        cout<<"                     ┗━━━━━━━━━━━━━┛\n";
        cout<<"请输入:"<<endl;
        do
        {
            int choice;
            cin>>choice;
            if(choice==1||choice==2||choice==3||choice==4||choice==5)
            {
                switch(choice)
                {
                case 1:add();break;
                case 2:del();break;
                case 3:modify();break;
                case 4:close();break;
                case 5:show();
                    return;
                }
            }
            else
                cout<<"输入错误,请重新输入!!!"<<endl;
        }
        while(true);
    }

   

void save()
    {
        ofstream student("student.txt",ios::out);
        student<<"学号:"<<number[i]<<endl;
        student<<"姓名:"<<name[i]<<endl;
        student<<"房号:"<<address[i]<<endl;
        //i++;
}


    void close()//清空
    { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
    FOREGROUND_INTENSITY |
             FOREGROUND_RED);
        cout<<"请确认是否全部清除(Y/N)?"<<endl;
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
            FOREGROUND_INTENSITY |
             FOREGROUND_GREEN);
        char c;
        cin>>c;
            if(toupper(c)=='Y')
            {
                i=0;
            
                system("cls");//清屏
                cout<<"***********已清除管理软件!!!************"<<endl;
                show();
                return;   
            }
            else
            {
                show();
                return;
            }
               
    }



void show()
    {
  cout<<"                     ┏━━━━━━━━━━━━━┓\n";
  cout<<"                           宿舍管理查询        ┃\n";
  cout<<"                     ┃━━━━━━━━━━━━━┃\n";
  cout<<"                     ┃1.新 增                   ┃\n";
  cout<<"                     ┃━━━━━━━━━━━━━┃\n";
  cout<<"                     ┃2.删 除                   ┃\n";
  cout<<"                     ┃━━━━━━━━━━━━━┃\n";
  cout<<"                     ┃3.修 改                   ┃\n";
  cout<<"                     ┃━━━━━━━━━━━━━┃\n";
  cout<<"                     ┃4.查 询                   ┃\n";
  cout<<"                     ┃━━━━━━━━━━━━━┃\n";
  cout<<"                     ┃5.预 览                   ┃\n";
  cout<<"                     ┃━━━━━━━━━━━━━┃\n";
  cout<<"                     ┃6.清 空                   ┃\n";
  cout<<"                     ┃━━━━━━━━━━━━━┃\n";
  cout<<"                     ┃7.退 出                   ┃\n";
  cout<<"                     ┃━━━━━━━━━━━━━┃\n";
  cout<<"                     ┃输入1——7进行选择        ┃\n";
  cout<<"                     ┗━━━━━━━━━━━━━┛\n";
  cout<<"请输入:"<<endl;
    }
};


int main()
{

     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
         FOREGROUND_INTENSITY |
             FOREGROUND_GREEN);
   

     
int choice;
string name;
Student s;
s.show();
  do{
  cin>>choice;
  if(choice==1||choice==2||choice==3||choice==4||choice==5||choice==6||choice==7)
  {
switch(choice){
    case 1:s.add();break;
    case 2:s.del();break;
    case 3:s.modify();break;
    case 4:s.find();break;
    case 5:s.look();break;
    case 6:s.close();break;
    case 7:cout<<"***退出程序***"<<endl;
return 0;
  }}
  else
  {cout<<"输入错误,请重新输入"<<endl;}
  }
  while(true);
}
搜索更多相关主题的帖子: 查询系统 private address include public 
2016-01-04 15:07
快速回复:宿舍管理查询系统
数据加载中...
 
   



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

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