欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng)

 更新時間:2022年03月16日 16:13:27   作者:DialogD  
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

C++使用IO流關(guān)聯(lián).txt文件

各模塊之間的調(diào)用關(guān)系如下:

函數(shù)的調(diào)用關(guān)系反映了演示程序的層次結(jié)構(gòu):

代碼如下:

#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib>
#include<string>
using namespace std;
#define MAXSIZE 100 ? ? //順序表的最大長度
typedef struct {
? ? string name; ? ? ? ?//姓名
? ? string id; ? ? ? ? ?//學(xué)號
? ? 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 << "學(xué)號" << 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 << "學(xué)生信息數(shù):" << stu.length << endl;
? ? outfile.close();
? ? cout << stu.length;
}

//創(chuàng)建學(xué)生信息(只能創(chuàng)建一次,不然會被刷新)
void InitList(SqList &stu)
{

? ? int i;
? ? cout << "學(xué)號" << 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);
}

//增加學(xué)生信息
void Addstudent(SqList &stu)
{
? ? int n;
? ? int i = stu.length + 1;
? ? cout << "輸入增加學(xué)生人數(shù)" << endl;
? ? cin >> n;
? ? cout << "學(xué)號" << 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);
}

//查詢學(xué)生信息
void Findstudent(SqList &stu)
{
? ? string a, b, c;
? ? string name, id, dormid;
? ? cout << "1.學(xué)號查詢 ?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 << "請輸入學(xué)生學(xué)號:" << 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();//關(guān)閉磁盤文件

? ? }
? ? if (2 == n)
? ? {
? ? ? ? cout << "請輸入學(xué)生姓名:" << 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();//關(guān)閉磁盤文件
? ? }
? ? if (3 == n)
? ? {
? ? ? ? cout << "請輸入學(xué)生宿舍號:" << 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;
? ? ? ? }
? ? }

}

//修改學(xué)生信息
void Renewstudent(SqList &stu)
{
? ? int n;
? ? string id, name, dormid;
? ? cout << "1.姓名 ?2.宿舍號" << endl;
? ? cout << "請輸入您的選擇(1~2):" << endl;
? ? cin >> n;
? ? cout << "請輸入需要修改學(xué)生的學(xué)號" << 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 << "學(xué)生的信息如下:" << endl;
? ? cout << "**********************************" << endl;
? ? ifstream infile("student.txt", ios::in);
? ? if (!infile) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//如果文件打開失敗
? ? ? ? cout << "文件打開失敗" << endl;
? ? ? ? exit(1);
? ? }
? ? /*infile >> a >> b >> c;//從磁盤文件讀入
? ? cout << a << setw(8) << b << setw(8) << c << endl;//在顯示器上顯示*/
? ? 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 << "請輸入刪除學(xué)生學(xué)號" << 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;
? ? ? ? }
? ? }
}

//主函數(shù)
int main()
{
? ? SqList stu;
? ? int n;
? ? for (;;)
? ? {
? ? ? ? cout << "**************************宿舍管理查詢軟件**************************" << endl;
? ? ? ? cout << "1. 創(chuàng)建學(xué)生信息" << endl; ? ? ? ? ? ? ? ? ? ? ? ?//InitList
? ? ? ? cout << "2. 增加學(xué)生信息" << endl; ? ? ? ? ? ? ? ? ? ? ? ?//Addstudent ? ?
? ? ? ? cout << "3. 查詢學(xué)生信息" << endl; ? ? ? ? ? ? ? ? ? ? ? ?//Findstudent
? ? ? ? cout << "4. 顯示學(xué)生信息" << endl; ? ? ? ? ? ? ? ? ? ? ? ?//Showstudent
? ? ? ? cout << "5. 修改學(xué)生信息" << endl; ? ? ? ? ? ? ? ? ? ? ? ?//Renewstudent
? ? ? ? cout << "6. 刪除學(xué)生信息" << endl; ? ? ? ? ? ? ? ? ? ? ? ?//Deletstudent
? ? ? ? cout << "0. 退出系統(tǒng)" << endl;
? ? ? ? cout << "*******************************************************************" << endl;
? ? ? ? cout << "請輸入你需要的操作(0~6):" << endl;
? ? ? ? cin >> n;
? ? ? ? switch (n)
? ? ? ? {
? ? ? ? case 1:
? ? ? ? ? ? cout << "輸入學(xué)生人數(shù)" << 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 << "您已退出系統(tǒng)!" << endl;
? ? ? ? ? ? return 0;
? ? ? ? }

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++ deque容器的用法詳解

    C++ deque容器的用法詳解

    在處理一些數(shù)組的事情,所以隨手保留一下Deque容器的使用方法很有必要,接下來通過本文給大家重點(diǎn)介紹C++ deque容器的用法及deque和vector的區(qū)別講解,感興趣的朋友跟隨小編一起看看吧
    2021-05-05
  • C語言動態(tài)數(shù)組的使用實(shí)現(xiàn)代碼

    C語言動態(tài)數(shù)組的使用實(shí)現(xiàn)代碼

    這篇文章主要介紹了C語言動態(tài)數(shù)組的使用實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • C語言編程中建立和解除內(nèi)存映射的方法

    C語言編程中建立和解除內(nèi)存映射的方法

    這篇文章主要介紹了C語言編程中建立和解除內(nèi)存映射的方法,分別為mmap()函數(shù)和munmap()函數(shù)的使用,需要的朋友可以參考下
    2015-08-08
  • C++實(shí)現(xiàn)投骰子的隨機(jī)游戲

    C++實(shí)現(xiàn)投骰子的隨機(jī)游戲

    這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)投骰子的隨機(jī)游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • C語言實(shí)現(xiàn)簡易版三子棋游戲

    C語言實(shí)現(xiàn)簡易版三子棋游戲

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)簡易版三子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • STL常用容器詳細(xì)解析

    STL常用容器詳細(xì)解析

    這里我們不涉及容器的基本操作之類,只是要討論一下各個容器其各自的特點(diǎn)STL中的常用容器包括:順序性容器(vector、deque、list)、關(guān)聯(lián)容器(map、set)、容器適配器(queue、stac)
    2013-09-09
  • C++發(fā)送郵件實(shí)現(xiàn)代碼

    C++發(fā)送郵件實(shí)現(xiàn)代碼

    這篇文章主要為大家詳細(xì)介紹了C++發(fā)送郵件的實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • C++入門之實(shí)現(xiàn)十步萬度游戲

    C++入門之實(shí)現(xiàn)十步萬度游戲

    這篇文章主要介紹了C++入門實(shí)現(xiàn)十步萬度游戲,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-10-10
  • windows下安裝QT及visual studio 2017搭建開發(fā)環(huán)境

    windows下安裝QT及visual studio 2017搭建開發(fā)環(huán)境

    這篇文章主要介紹了windows下安裝QT及visual studio 2017搭建開發(fā)環(huán)境,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • C++事件驅(qū)動型銀行排隊模擬

    C++事件驅(qū)動型銀行排隊模擬

    這篇文章主要為大家詳細(xì)介紹了C++事件驅(qū)動型銀行排隊模擬,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09

最新評論