iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >C++实现图书馆管理系统的代码怎么写
  • 714
分享到

C++实现图书馆管理系统的代码怎么写

2023-06-29 11:06:40 714人浏览 安东尼
摘要

这篇文章主要介绍“c++实现图书馆管理系统的代码怎么写”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“C++实现图书馆管理系统的代码怎么写”文章能帮助大家解决问题。总体思想用C++开发图书馆管理系统需

这篇文章主要介绍“c++实现图书馆管理系统的代码怎么写”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“C++实现图书馆管理系统的代码怎么写”文章能帮助大家解决问题。

总体思想

用C++开发图书馆管理系统需要对学生和图书分别建立class,调用class中的方法实现学生登陆账号借书,还书,图书馆管理员查看信息等操作。

Student.h

#pragma once#include<string>#include<vector>#include<iOStream>#include<fstream>#include<sstream>#include<string>using namespace std;class Student{private:    int id;                          //student's ID number    int year;                        //student's grade    string name;    string passWord;    string gender;    string telephone;    string address;                  //student's name, password, gender, telephone number and address    vector<int> book;    vector<int> grade;               //student's books and their markspublic:    Student();    ~Student();    Student(int a, int b, string c, string d, string e, string f, string g);    //constructors    int get_id();    int get_year();    string get_name();    string get_pass();    string get_gend();    string get_tele();    string get_addr();    vector<int> get_book();          //get the variables of class    void change(int a, int b, string c, string d, string e, string f, string g);    //change the infORMation    void display();                  //display the information on the screen    int length();                    //get the number of all students    bool canopen();                  //check whether the file 'student.txt' can be opened    void write();                    //write the information current into file 'student.txt'    void read(int n);                //read the information of the number n student from file 'student.txt'    void write_book();               //write the books information of the student into file 'mybook.txt'     void read_book();                //read the infomation of the student from file 'mybook.txt'    void change_book(int a, int b);  //change the information of vector book and grade    void add_book(int a);            //add a new book    void display_book();             //display the information of books on the screen    void add_student();              //add a student into the file 'mybook.txt'    void sub_student();              //subtract a student in the file 'mybook.txt'    bool is_same_book(int a);        //check whether there exist a same book in the file 'mybook.txt'};Student::Student(){    id = 0;    year = 0;    name = "not given";    password = "not given";    gender = "not given";    telephone = "not given";    address = "not given";             //define the default constructor}Student::~Student() {}Student::Student(int a, int b, string c, string d, string e, string f, string g){    id = a;    year = b;    name = c;    password = d;    gender = e;    telephone = f;    address = g;                       //define the normal constructor}int Student::get_id(){    return id;}int Student::get_year(){    return year;}string Student::get_name(){    return name;}string Student::get_pass(){    return password;}string Student::get_gend(){    return gender;}string Student::get_tele(){    return telephone;}string Student::get_addr(){    return address;}vector<int> Student::get_book(){    return book;}void Student::change(int a, int b, string c, string d, string e, string f, string g){    id = a;    year = b;    name = c;    password = d;    gender = e;    telephone = f;    address = g;}void Student::display(){    cout << "Name:   " << name << endl;    cout << "ID number:   " << id << endl;    cout << "Grade:   " << year << endl;    cout << "Gender:   " << gender << endl;    cout << "Telephone:   " << telephone << endl;    cout << "Address:   " << address << endl << endl;}int Student::length(){    int i = 0;    string temp;    ifstream fin("student.txt");    while (getline(fin, temp))        i += 1;    fin.close();    return i;}bool Student::canopen(){    ifstream fin1("student.txt");    ifstream fin2("mybook.txt");    if (fin1&&fin2)        return 1;    else        return 0;    fin1.close();    fin2.close();}void Student::write(){    ofstream fout("student.txt", ios::app);    fout << id << "\t" << year << "\t" << name << "\t" << password << "\t" << gender << "\t" << telephone << "\t" << address << endl;    fout.close();}void Student::read(int n){    int i = 0;    string temp, data[999], a[6];    ifstream fin("student.txt");    while (getline(fin, temp))    {        data[i] = temp;        i += 1;    }    fin.close();    istringstream stream(data[n]);    for (i = 0; i < 6; i++)    {        data[n].erase(0, data[n].find("\t") + 1);        a[i] = data[n].substr(0, data[n].find("\t"));    }    name = a[1];    password = a[2];    gender = a[3];    telephone = a[4];    address = a[5];    stream >> id >> year;}void Student::write_book(){    int i, n, l = 0;    string data[999], temp;    ifstream fin("mybook.txt");    while (getline(fin, temp))    {        data[l] = temp;        l += 1;    }    fin.close();    ofstream fout("mybook.txt");    for (i = 0; i < l; i++)    {        istringstream stream(data[i]);        stream >> n;        if (n == id)        {            fout << id;            for (int i = 0; i < book.size(); i++)                fout << "\t" << book[i] << "\t" << grade[i];            fout << endl;        }        else            fout << data[i] << endl;    }    fout.close();}void Student::read_book(){    int i = 0, x, y, n;    string data[999], temp;    ifstream fin("mybook.txt");    while (getline(fin, temp))    {        data[i] = temp;        i += 1;    }    fin.close();    for (i = 0; i < 999; i++)    {        istringstream stream(data[i]);        stream >> n;        if (id == n)            while (stream >> x >> y)            {                book.push_back(x);                grade.push_back(y);            }    }}void Student::change_book(int a, int b){    int i;    for (i = 0; i < book.size(); i++)        if (book[i] == a)            grade[i] = b;}void Student::add_book(int a){    book.push_back(a);    grade.push_back(-1);}void Student::display_book(){    int i;    for (i = 0; i < book.size(); i++)    {        cout << book[i] << "\t\t";        if (grade[i] == -1)            cout << "None." << endl;        else            cout << grade[i] << endl;    }}void Student::add_student(){    ofstream fout("mybook.txt", ios::app);    fout << id << endl;    fout.close();}void Student::sub_student(){    int i = 0, n, m, l;    string data[999], temp;    ifstream fin("mybook.txt");    while (getline(fin, temp))    {        data[i] = temp;        i += 1;    }    fin.close();    l = i;    for (i = 0; i < l; i++)    {        istringstream stream(data[i]);        stream >> n;        if (id == n)            m = i;    }    ofstream fout("mybook.txt");    for (i = 0; i < l; i++)        if (i != m)            fout << data[i] << endl;    fout.close();}bool Student::is_same_book(int a){    int i;    bool success = 0;    for (i = 0; i < book.size(); i++)        if (book[i] == a)            success = 1;    return success;}

Book.h

#pragma once#include<iostream>#include<fstream>#include<string>#include<sstream>using namespace std;class Book{private:    int id;    string name;    string professor;                //the information of a book    int place;                       //left seats    int year;                        //available to which gradespublic:    Book();    ~Book();    Book(int a, string b, string c, int d, int e);    int get_id();    string get_name();    string get_prof();    int get_place();    int get_year();                  //get the variables of class    void change(int a, string b, string c, int d, int e);                                     //change the information    void display();                  //display the information on the screen    int length();                    //get the number of all the Books    bool canopen();                  //check whether the file 'book.txt' can be opened    void write();                    //write the information into the file 'book.txt'    void read(int n);                //read the information of number n book form the file 'book.txt'};Book::Book(){    name = "not given";    id = 0;    professor = "not given";    place = 0;    year = 0;                         //difine the default constructor}Book::~Book() {}Book::Book(int a, string b, string c, int d, int e){    id = a;    name = b;    professor = c;    place = d;    year = e;                         //define the normal constructor}int Book::get_id(){    return id;}string Book::get_name(){    return name;}string Book::get_prof(){    return professor;}int Book::get_place(){    return place;}int Book::get_year(){    return year;}void Book::change(int a, string b, string c, int d, int e){    id = a;    name = b;    professor = c;    place = d;    year = e;}void Book::display(){    cout << "Name:   " << name << endl;    cout << "ID number:   " << id << endl;    cout << "Professor:   " << professor << endl;    cout << "Left seats:   " << place << endl;    cout << "Available grade:   ";    if (year > 0 && year < 5)        cout << "year " << year;    else if (year == 5)        cout << "All of students.";    else        cout << "error in data.";    cout << endl << endl;}int Book::length(){    int i = 0;    string temp;    ifstream fin("book.txt");    while (getline(fin, temp))        i += 1;    fin.close();    return i;}bool Book::canopen(){    ifstream fin1("book.txt");    if (fin1)        return 1;    else        return 0;    fin1.close();}void Book::write(){    ofstream fout("book.txt", ios::app);    fout << id << "\t" << place << "\t" << year << "\t" << name << "\t" << professor << "\t" << endl;    fout.close();}void Book::read(int n){    int i = 0;    string temp, data[999], a[4];    ifstream fin("book.txt");    while (getline(fin, temp))    {        data[i] = temp;        i += 1;    }    fin.close();    istringstream stream(data[n]);    for (i = 0; i < 4; i++)    {        data[n].erase(0, data[n].find("\t") + 1);        a[i] = data[n].substr(0, data[n].find("\t"));    }    name = a[2];    professor = a[3];    stream >> id >> place >> year;}

main.cpp

#include<iostream>#include<string>#include<vector>#include"Book.h"#include"Student.h"using namespace std;void initialize();bool is_administrator();bool is_student(int *n);void menu1();void menu2();void menu3();void wrong_input();void mag_book();void mag_student();void show_book_list();void show_student_list();void give_mark();void change_password();void choose_book(int n);void my_book(int n);void check_info(int n);void can_open(Book a);void can_open(Student a);bool is_same_student_name(string n);bool is_same_student_tele(string n);bool is_same_student_addr(string n);bool is_same_book_name(string n);int main(){    int user;    char choice;    bool success = 0;    initialize();    do {        menu1();        cin >> choice;        switch (choice)        {        case'1':        {            if (is_administrator()) {                do {                    menu2();                    cin >> choice;                    getchar();                    switch (choice)                    {                    case'1':mag_book(); success = 0; break;                    case'2':mag_student(); success = 0; break;                    case'3':show_book_list(); success = 0; break;                    case'4':show_student_list(); success = 0; break;                    case'5':give_mark(); success = 0; break;                    case'6':change_password(); success = 0; break;                    case'9':success = 1; break;                    case'0':success = 1; break;                    default:wrong_input(); break;                    }                } while (!success);            }            else            {                cout << "The password is incorrect." << endl;                system("pause");            }        }        break;        case'2':        {            if (is_student(&user))            {                do {                    menu3();                    cin >> choice;                    switch (choice)                    {                    case'1':choose_book(user); success = 0; break;                    case'2':my_book(user); success = 0; break;                    case'3':check_info(user); success = 0; break;                    case'9':success = 1; break;                    case'0':success = 1; break;                    default:wrong_input(); break;                    }                } while (!success);            }            else            {                cout << "Your name or password is incorrect." << endl;                system("pause");            }        }        break;        case'0':success = 1; break;        default:wrong_input(); break;        }    } while (choice != '0');    return 0;}void initialize(){    ifstream infile1("book.txt");    if (!infile1)    {        ofstream outfile1("book.txt");        outfile1.close();    }    infile1.close();    ifstream infile2("student.txt");    if (!infile2)    {        ofstream outfile2("student.txt");        outfile2.close();    }    infile2.close();    ifstream infile3("password.txt");    if (!infile3)    {        ofstream outfile3("password.txt");        outfile3 << "123";        outfile3.close();    }    infile3.close();    ifstream infile4("mybook.txt");    if (!infile4)    {        ofstream outfile4("mybook.txt");        outfile4.close();    }    infile4.close();}bool is_administrator(){    string p1, p2;    getchar();    cout << "Please input the password:";    getline(cin, p1);    ifstream infile("password.txt");    if (!infile)    {        cout << endl << "Out of service" << endl;        cout << "Please press enter to exit." << endl;        system("pause");        exit(0);    }    getline(infile, p2);    infile.close();    if (p1 == p2)        return 1;    else        return 0;}bool is_student(int *n){    Student a[100];    Student s;    string p1, p2;    int i;    bool success = 0;    getchar();    cout << "Please input your name:";    getline(cin, p1);    cout << "Please input your password:";    getline(cin, p2);    can_open(s);    for (i = 0; i < s.length(); i++)    {        a[i].read(i);        if (a[i].get_name() == p1 && a[i].get_pass() == p2)        {            *n = i;            success = 1;        }    }    return success;}void menu1(){    system("cls");    cout << endl << endl << endl;    cout << "-------------------------------------------------------------------" << endl;    cout << "                University Student Management System               " << endl << endl;    cout << "      1.Administrator System." << endl << endl;    cout << "      2.Student System." << endl << endl;    cout << "      0.Exit." << endl;    cout << "-------------------------------------------------------------------" << endl;    cout << "Please input your choice:";}void menu2(){    system("cls");    cout << endl << endl << endl;    cout << "-------------------------------------------------------------------" << endl;    cout << "                          Administrator System   " << endl << endl;    cout << "      1.Book Management." << endl << endl;    cout << "      2.Student Management." << endl << endl;    cout << "      3.Show the Book List." << endl << endl;    cout << "      4.Show the Student List." << endl << endl;    cout << "      5.Give Marks to Students." << endl << endl;    cout << "      6.Change Administrator Password." << endl << endl;    cout << "      9.Return to the main menu." << endl << endl;    cout << "      0.Exit." << endl;    cout << "-------------------------------------------------------------------" << endl;    cout << "Please input your choice:";}void menu3(){    system("cls");    cout << endl << endl << endl;    cout << "-------------------------------------------------------------------" << endl;    cout << "                          Student System" << endl << endl;    cout << "      1.Choose My Books" << endl << endl;    cout << "      2.Check My Books and Grades" << endl << endl;    cout << "      3.Check and Change My Infomation" << endl << endl;    cout << "      9.Return to the main menu." << endl << endl;    cout << "      0.Exit." << endl;    cout << "-------------------------------------------------------------------" << endl;    cout << "Please input your choice:";}void wrong_input(){    system("cls");    cout << endl << endl << endl << endl << endl << endl;    cout << "                        Wrong input! Please input again." << endl;    system("pause");}void mag_book(){    int i, id, plac, year;    char choice;    bool success = 0, success2 = 0;    string name, prof;    Book a[50];    Book c;    do {        fflush(stdin);        system("cls");        cout << endl << "                     Book Management" << endl << endl;        cout << "Which operation do you want about the list of book?" << endl;        cout << "1.Browse a book\n\n2.Add a book\n\n3.Modify a book\n\n4.Delete a book\n\n";        cin >> choice;        cout << "Please input the ID number of book:";        cin >> id;        getchar();        can_open(c);        if (choice == '1')        {            success2 = 1;            fflush(stdin);            for (i = 0; i < c.length(); i++)                a[i].read(i);            for (i = 0; i < c.length(); i++)                if (id == a[i].get_id())                {                    system("cls");                    a[i].display();                    success = 1;                }            if (!success)                cout << "The book cannot be found.";        }        else if (choice == '2')        {            success2 = 1;            fflush(stdin);            for (i = 0; i < c.length(); i++)            {                a[i].read(i);                if (id == a[i].get_id())                    success = 1;            }            if (success)                cout << "The book is exist";            else            {                do {                    cout << "Please input the name of book:";                    getline(cin, name);                } while (is_same_book_name(name));                cout << "Please input the professor's name:";                getline(cin, prof);                cout << "Please input the maximum quota of people(connot change later):";                cin >> plac;                cout << "Which grades are available?" << endl << "1. year 1\n2. year 2\n3. year 3\n4. year 4\n5. all of students\n";                cin >> year;                c.change(id, name, prof, plac, year);                c.write();                system("cls");                cout << "The book has been saved." << endl << endl;                c.display();            }        }        else if (choice == '3')        {            success2 = 1;            fflush(stdin);            int l, n;            l = c.length();            for (i = 0; i < l; i++)            {                a[i].read(i);                if (id == a[i].get_id())                {                    n = i;                    success = 1;                }            }            if (success)            {                do {                    cout << "Please input the new name of book " << id << ":";                    getline(cin, name);                } while (is_same_book_name(name));                cout << "Please input the new professor's name of book " << id << ":";                getline(cin, prof);                cout << "Which grades are available?" << endl << "1. year 1\n2. year 2\n3. year 3\n4. year 4\n5. all of students\n";                cin >> year;                a[n].change(id, name, prof, a[n].get_place(), year);                ofstream fout("book.txt");                fout.close();                for (i = 0; i < l; i++)                    a[i].write();                system("cls");                cout << "The book has been changed." << endl << endl;                a[n].display();            }            else                cout << "The book " << id << " cannot be found.";        }        else if (choice == '4')        {            success2 = 1;            fflush(stdin);            int n, l = c.length();            for (i = 0; i < l; i++)            {                a[i].read(i);                if (id == a[i].get_id())                {                    n = i;                    success = 1;                }            }            if (success)            {                ofstream fout("book.txt");                fout.close();                for (i = 0; i < l - 1; i++)                    if (i != n)                        a[i].write();                system("cls");                cout << "The book has been deleted." << endl << endl;                a[n].display();            }            else                cout << "The book " << id << " cannot be found.";        }        else        {            cout << "wrong input, please input again." << endl;            system("pause");        }    } while (!success2);    cout << endl;    system("pause");}void mag_student(){    int i, id, year;    char choice;    bool success = 0, success2 = 0;    string name, pass, gend, tele, addr;    Student a[50];    Student s;    do {        system("cls");        cout << endl << "                     Student Management" << endl << endl;        cout << "Which operation do you want about the list of student?" << endl;        cout << "1.Browse a student\n2.Add a student\n3.Modify a student\n4.Delete a student\n";        cin >> choice;        cout << "Please input the ID number of student:";        cin >> id;        getchar();        can_open(s);        if (choice == '1')        {            success2 = 1;            fflush(stdin);            for (i = 0; i < s.length(); i++)                a[i].read(i);            for (i = 0; i < s.length(); i++)                if (id == a[i].get_id())                {                    system("cls");                    a[i].display();                    success = 1;                }            if (!success)                cout << "The student cannot be found.";        }        else if (choice == '2')        {            success2 = 1;            fflush(stdin);            for (i = 0; i < s.length(); i++)            {                a[i].read(i);                if (id == a[i].get_id())                    success = 1;            }            if (success)                cout << "The student is exist";            else            {                do {                    cout << "Please input the name of student:";                    getline(cin, name);                } while (is_same_student_name(name));                cout << "Please input the password:";                getline(cin, pass);                do {                    cout << "What grade is the student in? (1-4)";                    cin >> year;                } while (year < 1 || year>4);                fflush(stdin);                do {                    cout << "Please input the student's gender:" << endl << "Please enter 'male' or 'female'  :";                    getline(cin, gend);                } while (!(gend == "male" || gend == "female"));                do {                    cout << "Please input the telephone number:";                    getline(cin, tele);                } while (is_same_student_tele(tele));                do {                    cout << "Please input the address:";                    getline(cin, addr);                } while (is_same_student_addr(addr));                s.change(id, year, name, pass, gend, tele, addr);                s.add_student();                s.write();                            system("cls");                cout << "The information of student has been saved." << endl << endl;                s.display();                        }        }        else if (choice == '3')        {            success2 = 1;            fflush(stdin);            int l, n;            l = s.length();            for (i = 0; i < l; i++)            {                a[i].read(i);                if (id == a[i].get_id())                {                    n = i;                    success = 1;                }            }            if (success)            {                do {                    cout << "Please input the new name of student " << id << ":";                    getline(cin, name);                } while (is_same_student_name(name));                pass = a[n].get_pass();                do {                    cout << "What grade is the student in? (1-4)";                    cin >> year;                } while (year < 1 || year>4);                fflush(stdin);                do {                    cout << "Please input the student's gender:" << endl << "Please enter 'male' or 'female'  :";                    getline(cin, gend);                } while (!(gend == "male" || gend == "female"));                do {                    cout << "Please input the new telephone number:";                    getline(cin, tele);                } while (is_same_student_tele(tele));                do {                    cout << "Please input the new address:";                    getline(cin, addr);                } while (is_same_student_addr(addr));                a[n].change(id, year, name, pass, gend, tele, addr);                ofstream fout("student.txt");                fout.close();                for (i = 0; i < l; i++)                    a[i].write();                system("cls");                cout << "The student has been changed." << endl << endl;                a[n].display();            }            else                cout << "The student " << id << " cannot be found.";        }        else if (choice == '4')        {            success2 = 1;            fflush(stdin);            int n, l = s.length();            for (i = 0; i < l; i++)            {                a[i].read(i);                if (id == a[i].get_id())                {                    n = i;                    success = 1;                }            }            if (success)            {                a[n].sub_student();                ofstream fout("student.txt");                fout.close();                for (i = 0; i < l; i++)                    if (i != n)                        a[i].write();                system("cls");                cout << "The student has been deleted." << endl << endl;                a[n].display();            }            else                cout << "The student " << id << " cannot be found.";        }        else        {            cout << "Wrong input, please input again." << endl;            system("pause");        }    } while (!success2);    cout << endl;    system("pause");}void show_book_list(){    Book a[100];    Book c;    int i;    system("cls");    cout << endl << "                     Books List" << endl << endl;    can_open(c);    for (i = 0; i < c.length(); i++)    {        a[i].read(i);        a[i].display();    }    cout << endl;    system("pause");}void show_student_list(){    Student a[100];    Student s;    int i;    system("cls");    cout << endl << "                     Students List" << endl << endl;    can_open(s);    for (i = 0; i < s.length(); i++)    {        a[i].read(i);        a[i].display();    }    cout << endl;    system("pause");}void give_mark(){    int i, j, k = 0, id, temp;    bool success = 0;    vector<int> student, mark;    Student a[999];    Student s;    Book b[999];    Book c;    system("cls");    cout << endl << "                     Give Marks" << endl << endl;    cout << "Please input the ID number of book:";    cin >> id;    for (i = 0; i < c.length(); i++)    {        b[i].read(i);        if (b[i].get_id() == id)            success = 1;    }    if (!success)        cout << "The book " << id << " is not exist." << endl;    else    {        cout << "These student(s) are your student(s):";        for (i = 0; i < s.length(); i++)        {            a[i].read(i);            a[i].read_book();            for (j = 0; j < a[i].get_book().size(); j++)                if (id == a[i].get_book()[j])                {                    k += 1;                    cout << endl << k << ". " << a[i].get_name();                    student.push_back(i);                    break;                }        }        cout << endl << "Please give marks;" << endl;        for (i = 0; i < k; i++)        {            cout << a[student[i]].get_name() << ":   ";            cin >> temp;            a[student[i]].change_book(id, temp);        }        for (i = 0; i < s.length(); i++)            a[i].write_book();        cout << endl << "Giving marks successfully!";    }    cout << endl;    system("pause");}void change_password(){    string p1, p2, p3;    system("cls");    cout << endl << "                 Change Administrator Password." << endl << endl;    cout << "Please input the password:";    getline(cin, p1);    ifstream infile("password.txt");    if (!infile)    {        cout << endl << "Out of service" << endl;        cout << "Please press enter to exit." << endl;        system("pause");        exit(0);    }    getline(infile, p2);    infile.close();    if (p1 == p2)    {        cout << "Please input the new password:";        getline(cin, p3);        ofstream outfile("password.txt");        outfile << p3;        outfile.close();        cout << "The administrator password has been changed.";    }    else        cout << "Wrong password.";    cout << endl;    system("pause");}void choose_book(int n){    int i, l, m, id;    bool success = 0;    bool can_choose[999];    Student a[999];    Student s;    Book b[999];    Book c;    system("cls");    cout << endl << "                     Choose My Books" << endl << endl;    can_open(s);    can_open(c);    l = c.length();    for (i = 0; i < s.length(); i++)    {        a[i].read(i);        a[i].read_book();    }    cout << "                                                   Welcome," << a[n].get_name() << endl << endl;    for (i = 0; i < l; i++)    {        b[i].read(i);        if (((b[i].get_year() == a[n].get_year()) || b[i].get_year() == 5) && (b[i].get_place() > 0))        {            can_choose[i] = 1;            cout << "Status:   Available" << endl;            b[i].display();        }        else        {            can_choose[i] = 0;            cout << "Status:   Unavailable" << endl;            b[i].display();        }    }    do {        cout << "Please input the ID number of the book you want to choose:";        cin >> id;        success = 0;        for (i = 0; i < l; i++)            if (b[i].get_id() == id)            {                m = i;                success = 1;            }    } while (!success);    system("cls");    cout << endl << endl << endl;    if (can_choose[m])    {        if (a[n].is_same_book(id))            cout << "                  You have selected the book " << id << endl;        else        {            b[m].change(b[m].get_id(), b[m].get_name(), b[m].get_prof(), b[m].get_place() - 1, b[m].get_year());            ofstream outfile("book.txt");            outfile.close();            for (i = 0; i < l; i++)                b[i].write();            a[n].add_book(id);            a[n].write_book();            cout << "Here is the list of your books now:" << endl << endl << "ID\t\tGrade" << endl;            a[n].display_book();        }    }    else        cout << "               The book '" << b[m].get_name() << "' cannot be selected." << endl;    system("pause");}void my_book(int n){    int i, l;    Student a[999];    Student s;    system("cls");    cout << endl << "                     Check My Books ang Grades" << endl << endl;    can_open(s);    l = s.length();    for (i = 0; i < l; i++)        a[i].read(i);    cout << "                                                        Welcome," << a[n].get_name() << endl << endl;    a[n].read_book();    cout << "Book ID\tGrade" << endl << endl;    a[n].display_book();    system("pause");}void check_info(int n){    int i, l;    char choice;    bool success = 0;    string tele, addr, pass;    Student a[999];    Student s;    system("cls");    cout << endl << "                     Check and Change My Information" << endl << endl;    can_open(s);    l = s.length();    for (i = 0; i < l; i++)        a[i].read(i);    cout << "                                                              Welcome," << a[n].get_name() << endl << endl;    a[n].display();    cout << endl << "Enter 1: Change my information." << endl;    cout << "Enter 2: Change my password." << endl;    cout << "Enter else: Return to the student menu:";    cin >> choice;    getchar();    if (choice == '1')    {        do {            cout << "Please input the new telephone number:";            getline(cin, tele);        } while (is_same_student_tele(tele));        do {            cout << "Please input the new address:";            getline(cin, addr);        } while (is_same_student_addr(addr));        a[n].change(a[n].get_id(), a[n].get_year(), a[n].get_name(), a[n].get_pass(), a[n].get_gend(), tele, addr);        ofstream outfile("student.txt");        outfile.close();        for (i = 0; i < l; i++)            a[i].write();        cout << "The information has been changed:" << endl;        a[n].display();        system("pause");    }    else if (choice == '2')    {        cout << "Please input the new password.";        getline(cin, pass);        a[n].change(a[n].get_id(), a[n].get_year(), a[n].get_name(), pass, a[n].get_gend(), a[n].get_tele(), a[n].get_addr());        ofstream outfile("student.txt");        outfile.close();        for (i = 0; i < l; i++)            a[i].write();        cout << "The password has been changed." << endl;        system("pause");    }}void can_open(Book a){    if (!a.canopen())    {        cout << endl << "The file cannot open.";        cout << endl << "You have to restart the program to repair the error.";        cout << endl << "Press enter to exit." << endl;        system("pause");        exit(0);    }}void can_open(Student a){    if (!a.canopen())    {        cout << endl << "The file cannot open.";        cout << endl << "You have to restart the program to repair the error.";        cout << endl << "Press enter to exit." << endl;        system("pause");        exit(0);    }}bool is_same_student_name(string n){    int i;    bool success = 0;    Student a[999];    Student s;    for (i = 0; i < s.length(); i++)    {        a[i].read(i);        if (a[i].get_name() == n)        {            cout << "There exist the same name." << endl;            success = 1;        }    }    return success;}bool is_same_student_tele(string n){    int i;    bool success = 0;    Student a[999];    Student s;    for (i = 0; i < s.length(); i++)    {        a[i].read(i);        if (a[i].get_tele() == n)        {            cout << "There exist the same telephone number." << endl;            success = 1;        }    }    return success;}bool is_same_student_addr(string n){    int i;    bool success = 0;    Student a[999];    Student s;    for (i = 0; i < s.length(); i++)    {        a[i].read(i);        if (a[i].get_addr() == n)        {            cout << "There exist the same address." << endl;            success = 1;        }    }    return success;}bool is_same_book_name(string n){    int i;    bool success = 0;    Book a[999];    Book c;    for (i = 0; i < c.length(); i++)    {        a[i].read(i);        if (a[i].get_name() == n)        {            cout << "There exist the same name." << endl;            success = 1;        }    }    return success;}

关于“C++实现图书馆管理系统的代码怎么写”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注编程网其他教程频道,小编每天都会为大家更新不同的知识点。

--结束END--

本文标题: C++实现图书馆管理系统的代码怎么写

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

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

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

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

下载Word文档
猜你喜欢
  • C++实现图书馆管理系统的代码怎么写
    这篇文章主要介绍“C++实现图书馆管理系统的代码怎么写”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“C++实现图书馆管理系统的代码怎么写”文章能帮助大家解决问题。总体思想用C++开发图书馆管理系统需...
    99+
    2023-06-29
  • C++实现简易图书馆管理系统的代码怎么写
    这篇文章主要讲解了“C++实现简易图书馆管理系统的代码怎么写”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“C++实现简易图书馆管理系统的代码怎么写”吧!思路在本程序中共有四个类:book类:...
    99+
    2023-06-29
  • 怎么用C++代码实现图书馆管理系统
    这篇“怎么用C++代码实现图书馆管理系统”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“怎么用C++代码实现图书馆管理系统”文...
    99+
    2023-06-29
  • C++实现图书馆管理系统源码
    本文实例为大家分享了C++实现图书馆管理系统的具体代码,供大家参考,具体内容如下 总体思想 用C++开发图书馆管理系统需要对学生和图书分别建立class,调用class中的方法实现学...
    99+
    2022-11-13
  • C++实现图书馆管理系统
    本文实例为大家分享了C++实现图书馆管理系统的具体代码,供大家参考,具体内容如下 一、实验名称 图书馆管理系统 二、实验目的 利用C++语言设计开发一个小型的图书馆管理系统模拟程序,...
    99+
    2022-11-13
  • C语言实现图书馆管理系统
    本文实例为大家分享了C语言实现图书馆管理系统的具体代码,供大家参考,具体内容如下 全部代码如下: #include <stdio.h> #include<str...
    99+
    2022-11-12
  • C++实现简单图书馆管理系统
    本文实例为大家分享了C++实现简单图书馆管理系统的具体代码,供大家参考,具体内容如下 写了一个小项目,图书馆系统,功能如下: 1,添加书籍2,删除书籍(可删除还没外借的书籍)3,读者...
    99+
    2022-11-13
  • C++实现简易图书馆管理系统
    本文实例为大家分享了C++实现简易图书馆管理系统的具体代码,供大家参考,具体内容如下 思路 在本程序中共有四个类: book类:此类有书的基本信息:书名,编号,作者,价格等,和基本的...
    99+
    2022-11-13
  • python实现图书管理系统的代码怎么写
    这篇文章主要介绍“python实现图书管理系统的代码怎么写”,在日常操作中,相信很多人在python实现图书管理系统的代码怎么写问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”python实现图书管理系统的代码...
    99+
    2023-06-29
  • C语言如何实现图书馆管理系统
    这篇文章主要介绍了C语言如何实现图书馆管理系统,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。全部代码如下:#include <stdio.h>#incl...
    99+
    2023-06-20
  • 如何用C++实现简单图书馆管理系统
    这篇文章主要介绍“如何用C++实现简单图书馆管理系统”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“如何用C++实现简单图书馆管理系统”文章能帮助大家解决问题。功能如下:1,添加书籍2,删除书籍(可删...
    99+
    2023-06-29
  • Python实现图书管理系统设计的代码怎么写
    本篇内容介绍了“Python实现图书管理系统设计的代码怎么写”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!基于python的tkinter,...
    99+
    2023-06-29
  • C++编写实现图书管理系统
    C++编写的一个图书管理系统,供大家参考,具体内容如下 2018大一的课设,搬到这纪念一下,共1200多行代码 为图书管理人员编写一个图书管理系统,图书管理系统的设计主要是实现对图书...
    99+
    2022-11-13
  • C++实现图书管理系统源码
    本文实例为大家分享了C++实现图书管理系统的具体代码,供大家参考,具体内容如下 直接上代码 #include <stdafx.h> #include <iostr...
    99+
    2022-11-13
  • C语言实现图书借阅系统的代码怎么写
    本文小编为大家详细介绍“C语言实现图书借阅系统的代码怎么写”,内容详细,步骤清晰,细节处理妥当,希望这篇“C语言实现图书借阅系统的代码怎么写”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。 #includ...
    99+
    2023-06-29
  • Java实现图片展览馆管理系统的代码
    今天小编给大家分享一下Java实现图片展览馆管理系统的代码的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。一、项目运行环境配置...
    99+
    2023-06-29
  • Java如何实现网上图书馆管理系统
    小编给大家分享一下Java如何实现网上图书馆管理系统,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!一、项目简述功能: 区分为管理员用户和普通用户,普通用户:用户登录,个 人信息修改,图书查询,用户借阅,用户归还,管理员用 ...
    99+
    2023-06-25
  • 如何使用C++实现一个简单的图书馆管理系统?
    如何使用C++实现一个简单的图书馆管理系统?图书馆是一个重要的知识和文化传播场所,而一个高效的图书馆管理系统能够提升图书馆的运作效率,方便读者借阅图书和管理图书馆资源。本文将介绍如何使用C++编程语言实现一个简单的图书馆管理系统。首先,我们...
    99+
    2023-11-02
    图书馆 C++ 管理系统
  • C#实现图书管理系统
    本文为大家分享了C#实现图书管理系统课程设计,供大家参考,具体内容如下 一、设计目的 通过模拟图书管理系统,实现以下功能学生账号的注册学生对馆藏图书状况的查询学生借书,还书状态的查询...
    99+
    2022-11-13
  • python怎么实现图书馆借阅系统
    本篇内容主要讲解“python怎么实现图书馆借阅系统”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python怎么实现图书馆借阅系统”吧!希望这个简易的程序可以做到:代码如下:class&nbs...
    99+
    2023-06-29
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作