广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >C++实现宿舍管理查询系统
  • 137
分享到

C++实现宿舍管理查询系统

2024-04-02 19:04:59 137人浏览 薄情痞子
摘要

本文实例为大家分享了c++实现宿舍管理查询系统的具体代码,供大家参考,具体内容如下 C++使用io流关联.txt文件 各模块之间的调用关系如下: 函数的调用关系反映了演示程序的层次

本文实例为大家分享了c++实现宿舍管理查询系统的具体代码,供大家参考,具体内容如下

C++使用io流关联.txt文件

各模块之间的调用关系如下:

函数的调用关系反映了演示程序的层次结构:

代码如下:

#include<iOStream>
#include<fstream>
#include<iomanip>
#include<cstdlib>
#include<string>
using namespace std;
#define MAXSIZE 100     //顺序表的最大长度
typedef struct {
    string name;        //姓名
    string id;          //学号
    string dORMid;      //宿舍号
}Student;
typedef struct {
    Student r[MAXSIZE + 1];     //r[0]做单元哨兵
    int length;//长度
}sqlist;


//用直接插入排序存入到student.txt文件中
void InsertSort(SqList &stu)
{
    int i, j;
    for (i = 2; i <= stu.length; i++)
        if (stu.r[i].id < stu.r[i - 1].id)
        {
            stu.r[0] = stu.r[i];
            stu.r[i] = stu.r[i - 1];
            for (j = i - 2; stu.r[0].id < stu.r[j].id; j--)
                stu.r[j + 1] = stu.r[j];
            stu.r[j + 1] = stu.r[0];
        }
    ofstream outfile("student.txt", ios::out);
    if (!outfile) {                             //如果文件打开失败
        cout << "文件打开失败" << endl;
        exit(1);
    }
    //outfile << "学号" << setw(8) << "姓名" << setw(8) << "宿舍号" << endl;
    outfile << stu.length << endl;

    for (i = 1; i <= stu.length; i++) {
        outfile << stu.r[i].id << setw(8) << stu.r[i].name << setw(8) << stu.r[i].dormid << endl;
    }
    cout << "学生信息数:" << stu.length << endl;
    outfile.close();
    cout << stu.length;
}

//创建学生信息(只能创建一次,不然会被刷新)
void InitList(SqList &stu)
{

    int i;
    cout << "学号" << setw(8) << "姓名" << setw(8) << "宿舍号" << endl;
    for (i = 1; i <= stu.length; i++) {
        cin >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
    }
    InsertSort(stu);
}

//增加学生信息
void Addstudent(SqList &stu)
{
    int n;
    int i = stu.length + 1;
    cout << "输入增加学生人数" << endl;
    cin >> n;
    cout << "学号" << setw(8) << "姓名" << setw(8) << "宿舍号" << endl;
    stu.length = stu.length + n;
    for (i; i <= stu.length; i++)
        cin >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
    InsertSort(stu);
}

//查询学生信息
void Findstudent(SqList &stu)
{
    string a, b, c;
    string name, id, dormid;
    cout << "1.学号查询  2.姓名查询  3.宿舍号查询" << endl;
    cout << "请输入你的查询选择(1~3)" << endl;
    int i;
    int n;
    cin >> n;
    if (n < 1 && n>3)
    {
        cout << "您输入有误,请重新输入:" << endl;
        Findstudent(stu);
    }
    if (1 == n)
    {
        cout << "请输入学生学号:" << endl;
        cin >> id;

        ifstream infile("student.txt", ios::in);//定义输入文件流对象,以输入方式打开磁盘文件"student.txt"
        infile >> stu.length;
        for (i = 1; i <= stu.length; i++) {
            infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
        }
        infile.close();
        for (i = 1; i <= stu.length; i++)
        {
            infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
            if (stu.r[i].id == id)
                cout << stu.r[i].id << setw(8) << stu.r[i].name << setw(8) << stu.r[i].dormid << endl;
        }

        infile.close();//关闭磁盘文件

    }
    if (2 == n)
    {
        cout << "请输入学生姓名:" << endl;
        cin >> name;

        ifstream infile("student.txt", ios::in);//定义输入文件流对象,以输入方式打开磁盘文件"student.txt"
        infile >> stu.length;
        for (i = 1; i <= stu.length; i++) {
            infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
        }
        infile.close();
        for (i = 1; i <= stu.length; i++)
        {
            infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
            if (stu.r[i].name == name)
                cout << stu.r[i].id << setw(8) << stu.r[i].name << setw(8) << stu.r[i].dormid << endl;
        }

        infile.close();//关闭磁盘文件
    }
    if (3 == n)
    {
        cout << "请输入学生宿舍号:" << endl;
        cin >> dormid;

        ifstream infile("student.txt", ios::in);//定义输入文件流对象,以输入方式打开磁盘文件"student.txt"
        infile >> stu.length;
        for (i = 1; i <= stu.length; i++) {
            infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
        }
        infile.close();
        for (i = 1; i <= stu.length; i++)
        {
            infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
            if (stu.r[i].dormid == dormid)
                cout << stu.r[i].id << setw(8) << stu.r[i].name << setw(8) << stu.r[i].dormid << endl;
        }
    }

}

//修改学生信息
void Renewstudent(SqList &stu)
{
    int n;
    string id, name, dormid;
    cout << "1.姓名  2.宿舍号" << endl;
    cout << "请输入您的选择(1~2):" << endl;
    cin >> n;
    cout << "请输入需要修改学生的学号" << endl;
    cin >> id;
    if (n != 1 && n != 2)
    {
        cout << "输入有误,请重新输入:" << endl;
        Renewstudent(stu);
    }
    if (1 == n)
    {
        cout << "请输入修改姓名" << endl;
        cin >> name;
        int i = 0;
        ifstream infile("student.txt", ios::in);
        infile >> stu.length;
        for (i = 1; i <= stu.length; i++) {
            infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
        }
        infile.close();
        for (i = 1; i <= stu.length; i++)//先找到再修改
        {
            if (stu.r[i].id == id)
            {
                stu.r[i].name = name;
                InsertSort(stu);
                return;
            }
        }
    }
    if (2 == n)
    {
        int i;
        cout << "请输入修改宿舍号" << endl;
        cin >> dormid;
        ifstream infile("student.txt", ios::in);
        infile >> stu.length;
        for (i = 1; i <= stu.length; i++) {
            infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
        }
        infile.close();
        for (i = 1; i <= stu.length; i++)//先找到再修改
        {
            if (stu.r[i].id == id)
            {
                stu.r[i].dormid = dormid;
                InsertSort(stu);
                return;
            }
        }
    }

}

//显示宿舍信息
void Showstudent(SqList &stu)
{
    string a, b, c;
    int i;
    cout << "学生的信息如下:" << endl;
    cout << "**********************************" << endl;
    ifstream infile("student.txt", ios::in);
    if (!infile) {                              //如果文件打开失败
        cout << "文件打开失败" << endl;
        exit(1);
    }
    
    infile >> stu.length;
    for (i = 1; i <= stu.length; i++) {
        infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
        cout << stu.r[i].id << setw(8) << stu.r[i].name << setw(8) << stu.r[i].dormid << endl;
    }
    infile.close();
}

//删除宿舍信息
void Deletstudent(SqList &stu)
{
    int  i, j;
    string a, b, c, id;
    cout << "请输入删除学生学号" << endl;
    cin >> id;
    ifstream infile("student.txt", ios::in);//定义输入文件流对象,以输入方式打开磁盘文件"student.txt"
    infile >> stu.length;
    for (i = 1; i <= stu.length; i++) {
        infile >> stu.r[i].id >> stu.r[i].name >> stu.r[i].dormid;
    }
    infile.close();
    for (i = 1; i <= stu.length; i++)//先找到再删除
    {
        if (stu.r[i].id == id)
        {
            for (j = i; j<stu.length; j++)
                stu.r[j] = stu.r[j + 1];
            stu.length--;
            InsertSort(stu);
            return;
        }
    }
}

//主函数
int main()
{
    SqList stu;
    int n;
    for (;;)
    {
        cout << "**************************宿舍管理查询软件**************************" << endl;
        cout << "1. 创建学生信息" << endl;                        //InitList
        cout << "2. 增加学生信息" << endl;                        //Addstudent    
        cout << "3. 查询学生信息" << endl;                        //Findstudent
        cout << "4. 显示学生信息" << endl;                        //Showstudent
        cout << "5. 修改学生信息" << endl;                        //Renewstudent
        cout << "6. 删除学生信息" << endl;                        //Deletstudent
        cout << "0. 退出系统" << endl;
        cout << "*******************************************************************" << endl;
        cout << "请输入你需要的操作(0~6):" << endl;
        cin >> n;
        switch (n)
        {
        case 1:
            cout << "输入学生人数" << endl;
            cin >> stu.length;
            InitList(stu);
            cout << "###########################################" << endl;
            break;
        case 2:
            Addstudent(stu);
            cout << "###########################################" << endl;
            break;
        case 3:
            Findstudent(stu);
            cout << "###########################################" << endl;
            break;
        case 4:
            Showstudent(stu);
            cout << "###########################################" << endl;
            break;
        case 5:
            Renewstudent(stu);
            cout << "###########################################" << endl;
            break;
        case 6:
            Deletstudent(stu);
            cout << "###########################################" << endl;
            break;
        case 0:
            cout << "您已退出系统!" << endl;
            return 0;
        }

    }
    system("pause");
    return 0;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: C++实现宿舍管理查询系统

本文链接: https://www.lsjlt.com/news/142745.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • C++实现宿舍管理查询系统
    本文实例为大家分享了C++实现宿舍管理查询系统的具体代码,供大家参考,具体内容如下 C++使用IO流关联.txt文件 各模块之间的调用关系如下: 函数的调用关系反映了演示程序的层次...
    99+
    2022-11-13
  • 基于C#实现宿舍管理系统
    目录前言一、项目创建二、主页面设计三、主页面代码1.登录按钮2.退出按钮3.注册按钮4.SQL配置5.主页总体代码前言 本次项目主要是因为我们的大作业要求要求,因为网上C#的资源不太...
    99+
    2022-11-13
  • C++实现学生宿舍管理系统
    本文实例为大家分享了C++实现学生宿舍管理系统的具体代码,供大家参考,具体内容如下 非常简易,完成个作业够用,仅供初学者参考,不喜勿喷。 #include<stdio.h>...
    99+
    2022-11-13
  • C语言实现宿舍管理系统
    本文实例为大家分享了C语言实现宿舍管理系统的具体代码,供大家参考,具体内容如下 本次大一课设的作品,从空项目开始写的,全部在txt文件中增改删。变量命名太土了,代码格式还有待优化,望...
    99+
    2022-11-13
  • 宿舍管理系统的设计与实现/学生宿舍管理系统
    摘 要 随着信息技术和网络技术的飞速发展,人类已进入全新信息化时代,传统管理技术已无法高效,便捷地管理信息。为了迎合时代需求,优化管理效率,各种各样的管理系统应运而生,各行各业相继进入信息管理时代,宿舍管理系统就是信息时代变革中的产物之一...
    99+
    2023-10-06
    java 数据库 开发语言
  • 基于C#如何实现宿舍管理系统
    本篇内容主要讲解“基于C#如何实现宿舍管理系统”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“基于C#如何实现宿舍管理系统”吧!一、项目创建首先通过创建C#的Windows窗体应用程序,名字可以自...
    99+
    2023-07-02
  • C语言实现学生宿舍管理系统
    本文实例为大家分享了C语言实现学生宿舍管理系统的具体代码,供大家参考,具体内容如下 实现简单的学生宿舍基本信息管理,宿舍的基本信息包括楼号、房间号、面积、所容纳人数、已入住人数等,系...
    99+
    2022-11-13
  • C语言实现宿舍管理系统设计
    本文实例为大家分享了C语言实现宿舍管理系统的具体代码,供大家参考,具体内容如下 设计目的 《数据结构》课程主要介绍最常用的数据结构,进行数据结构课程设计要达到以下目的: (1)了解并...
    99+
    2022-11-13
  • 期末作业C#实现学生宿舍管理系统
    🚀开发背景 完整代码下载地址:点我下载 优化移步: 《c#中在datagridview的表格动态增加一个按钮方法》 《C#实现多窗口切换:Panel详细教程(亲测)》 文章还在更新,...
    99+
    2023-09-12
    c# microsoft 数据库 mysql
  • C语言实现学生宿舍信息管理系统
    本文实例为大家分享了C语言实现学生宿舍信息管理系统的具体代码,供大家参考,具体内容如下 功能描述 该学生宿舍信息管理系统主要实现的功能有:创建学生宿舍信息,显示学生宿舍信息,查询学生...
    99+
    2022-11-13
  • C语言实现宿舍管理系统课程设计
    宿舍管理系统C语言源码,供大家参考,具体内容如下 内容摘要 学生宿舍管理系统时应对学生宿舍管理的现代化、网络化,逐步摆脱学生宿舍管理的人工管理方式,提高学生宿舍管理效率而开发的,它包...
    99+
    2022-11-13
  • 如何使用C++实现学生宿舍管理系统
    这篇文章给大家分享的是有关如何使用C++实现学生宿舍管理系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。具体内容如下非常简易,完成个作业够用,仅供初学者参考,不喜勿喷。#include<stdio.h&g...
    99+
    2023-06-29
  • 怎么用C语言实现学生宿舍管理系统
    这篇文章主要讲解了“怎么用C语言实现学生宿舍管理系统”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用C语言实现学生宿舍管理系统”吧!实现简单的学生宿舍基本信息管理,宿舍的基本信息包括楼号...
    99+
    2023-06-29
  • C语言如何实现学生宿舍信息管理系统
    这篇文章主要讲解了“C语言如何实现学生宿舍信息管理系统”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“C语言如何实现学生宿舍信息管理系统”吧!功能描述该学生宿舍信息管理系统主要实现的功能有:创...
    99+
    2023-06-29
  • 数据库系统实现 大学生宿舍管理系统
    目录 目录 第一章绪论 1.1项目研究的背景 第二章可行性分析与需求分析 2.1可行性分析 2.1.1操作可行性 2.1.2技术可行性 2.1.3设计可行性 2.2需求分析 2.2.1处理对象分析 ...
    99+
    2023-09-25
    java servlet mysql html5 Powered by 金山文档
  • C语言实现学生宿舍信息管理系统的方法
    这篇文章主要介绍“C语言实现学生宿舍信息管理系统的方法”,在日常操作中,相信很多人在C语言实现学生宿舍信息管理系统的方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”C语言实现学生宿舍信息管理系统的方法”的疑...
    99+
    2023-06-29
  • 基于javaweb+jsp实现学生宿舍管理系统
    目录运行环境开发工具适用功能说明技术框架部分代码实现JSP 效果图运行环境 Java≥6、Tomcat≥7.0、MySQL≥5.5 开发工具 idea/eclipse/MyEclip...
    99+
    2022-11-12
  • C语言实现宿舍管理课程设计
    本文实例为大家分享了C语言实现宿舍管理的具体代码,供大家参考,具体内容如下 和本编前几个程序结构差不多,比较简单直观,希望可以给你带来帮助。 #include <stdio.h...
    99+
    2022-11-13
  • C语言实现学生宿舍信息管理系统课程设计
    本文实例为大家分享了C语言实现学生宿舍信息管理系统的具体代码,供大家参考,具体内容如下 一、问题陈述 宿舍对于大学生在校生活来说相当于家的存在,而宿舍管理又是学校后勤管理的重要环节,...
    99+
    2022-11-13
  • java实现学生宿舍系统
    本文实例为大家分享了java实现学生宿舍管理系统的具体代码,供大家参考,具体内容如下 学生类代码 Student.java package dormitory; public c...
    99+
    2022-11-13
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作