C++ 项目实践课设 图书馆管理系统

一、项目介绍

(1)图书管理
(a)添加图书:在系统中增加图书信息(可自己设计图书的信息:如书号,书名,出版社,等等)
(b)查询图书
(c)编辑图书
(d)删除图书

(2)读者管理
(a)读者注册:在系统中增加读者信息(可自己设计读者信息:如读者姓名、读者性别,联系方式等)
(b)查询读者
(c)编辑读者
(d)删除读者

(3)借阅管理
当输入图书编号,读者编号之后,能对图书馆中现有的图书进行借阅。

(4)还书管理
当输入读者编号和要归还的图书编号,读者能进行还书。

利用文件保存

二、总体代码实现

#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <string>
// for std::setw and std::setfill

using namespace std;

// 图书类与读者类的声明
class Book;
class Reader;

// 管理图书馆的类
class Library {
private:
    vector<Book> books;
    vector<Reader> readers;

public:
    // 构造器
    Library();

    // 图书操作
    void addBook();
    void searchBook();
    void editBook();
    void deleteBook();

    // 读者操作
    void addReader();
    void searchReader();
    void editReader();
    void deleteReader();

    // 借阅与归还操作
    void borrowBook();
    void returnBook();

    // 文件操作
    void saveData();
    void loadData();
};

// 代表图书的类
class Book {
private:
    int book_id;
    string title;
    string publisher;

public:
    // 构造器
    Book(int id, const string& t, const string& pub) : book_id(id), title(t), publisher(pub) {}

    // get方法
    int getBookId() const { return book_id; }
    string getTitle() const { return title; }
    string getPublisher() const { return publisher; }

    // set方法
    void setTitle(const string& t) { title = t; }
    void setPublisher(const string& pub) { publisher = pub; }

    // 方法来显示读取构造器详细信息
    void display() const {
        cout << "图书书号: " << setw(5) << setfill('0') << book_id << " | 图书书名: " << title << " | 图书出版社: " << publisher << endl;
    }
};

// 代表读者的类
class Reader {
private:
    int reader_id;
    string name;
    char gender;
    string contact;

public:
    // 构造器
    Reader(int id, const string& n, char g, const string& con) : reader_id(id), name(n), gender(g), contact(con) {}

    // get方法
    int getReaderId() const { return reader_id; }
    string getName() const { return name; }
    char getGender() const { return gender; }
    string getContact() const { return contact; }

    // set方法
    void setName(const string& n) { name = n; }
    void setGender(char g) { gender = g; }
    void setContact(const string& con) { contact = con; }

    // 方法来显示读取构造器详细信息
    void display() const {
        cout << "读者编号: " << setw(5) << setfill('0') << reader_id << " | 读者姓名: " << name << " | 读者性别: " << gender << " | 读者联系方式: " << contact << endl;
    }
};

// 类方法的实现

Library::Library() {
    // 创建库对象时从文件加载数据
    loadData();
}

void Library::addBook() {
    int id;
    string title, publisher;

    cout << "请输入图书书号: ";
    cin >> id;
    cin.ignore(); // 从缓冲区中清除换行符

    cout << "请输入图书书名: ";
    getline(cin, title);

    cout << "请输入图书出版社: ";
    getline(cin, publisher);

    books.push_back(Book(id, title, publisher));

    cout << "图书添加成功。\n";

    saveData(); // 添加成功后保存数据
}

void Library::searchBook() {
    int search_id;
    cout << "请输入要搜索的图书书号: ";
    cin >> search_id;

    bool found = false;
    for (const auto& book : books) {
        if (book.getBookId() == search_id) {
            book.display();
            found = true;
            break;
        }
    }

    if (!found) {
        cout << "没有找到该图书: " << search_id << endl;
    }
}

void Library::editBook() {
    int edit_id;
    cout << "请输入要编辑的图书书号: ";
    cin >> edit_id;

    for (auto& book : books) {
        if (book.getBookId() == edit_id) {
            string new_title, new_publisher;

            cout << "请输入新的书名(输入以保持当前状态): ";
            cin.ignore(); // 从缓冲区中清除换行符
            getline(cin, new_title);
            if (!new_title.empty()) {
                book.setTitle(new_title);
            }

            cout << "情输入新的出版社 (输入以保持当前状态): ";
            getline(cin, new_publisher);
            if (!new_publisher.empty()) {
                book.setPublisher(new_publisher);
            }

            cout << "图书详细信息更新成功。\n";
            saveData(); // 更新后保存数据
            return;
        }
    }

    cout << "没有找到该图书: " << edit_id << endl;
}

void Library::deleteBook() {
    int delete_id;
    cout << "请输入要删除的图书书号: ";
    cin >> delete_id;

    auto it = books.begin();
    while (it != books.end()) {
        if (it->getBookId() == delete_id) {
            it = books.erase(it);
            cout << "图书删除成功。\n";
            saveData(); // 删除后保存数据
            return;
        }
        else {
            ++it;
        }
    }

    cout << "没有找到该图书: " << delete_id << endl;
}

void Library::addReader() {
    int id;
    string name, contact;
    char gender;

    cout << "请输入读者编号: ";
    cin >> id;
    cin.ignore(); // 从缓冲区中清除换行符

    cout << "请输入读者姓名: ";
    getline(cin, name);

    cout << "请输入读者性别(M/F): ";
    cin >> gender;

    cout << "请输入读者联系方式: ";
    cin.ignore(); // 从缓冲区中清除换行符
    getline(cin, contact);

    readers.push_back(Reader(id, name, gender, contact));

    cout << "读者添加成功。\n";

    saveData(); // 添加成功后保存数据
}

void Library::searchReader() {
    int search_id;
    cout << "请输入要查询的读者编号: ";
    cin >> search_id;

    bool found = false;
    for (const auto& reader : readers) {
        if (reader.getReaderId() == search_id) {
            reader.display();
            found = true;
            break;
        }
    }

    if (!found) {
        cout << "没有找到该读者: " << search_id << endl;
    }
}

void Library::editReader() {
    int edit_id;
    cout << "请输入要编辑的读者编号: ";
    cin >> edit_id;

    for (auto& reader : readers) {
        if (reader.getReaderId() == edit_id) {
            string new_name, new_contact;
            char new_gender;

            cout << "请输入新的姓名(输入以保持当前状态): ";
            cin.ignore(); // 从缓冲区中清除换行符
            getline(cin, new_name);
            if (!new_name.empty()) {
                reader.setName(new_name);
            }

            cout << "请输入新的性别 (M/F) (输入以保持当前状态): ";
            cin >> new_gender;
            if (new_gender == 'M' || new_gender == 'F') {
                reader.setGender(new_gender);
            }

            cout << "请输入新的联系方式(输入以保持当前状态): ";
            cin.ignore(); // 从缓冲区中清除换行符
            getline(cin, new_contact);
            if (!new_contact.empty()) {
                reader.setContact(new_contact);
            }

            cout << "读者详细信息更新完成。\n";
            saveData(); // 更新后保存数据
            return;
        }
    }

    cout << "没有找到该读者: " << edit_id << endl;
}

void Library::deleteReader() {
    int delete_id;
    cout << "请输入要删除的读者编号: ";
    cin >> delete_id;

    auto it = readers.begin();
    while (it != readers.end()) {
        if (it->getReaderId() == delete_id) {
            it = readers.erase(it);
            cout << "读者删除成功。\n";
            saveData(); // 删除后保存数据
            return;
        }
        else {
            ++it;
        }
    }

    cout << "没有找到该读者: " << delete_id << endl;
}

void Library::borrowBook() {
    int book_id, reader_id;
    cout << "请输入要借阅图书的图书编号: ";
    cin >> book_id;
    cout << "请输入要借阅图书的读者编号: ";
    cin >> reader_id;

    // 借用逻辑的占位符实现

    cout << "图书借阅成功。\n";
}

void Library::returnBook() {
    int book_id, reader_id;
    cout << "请输入要归还图书的图书编号: ";
    cin >> book_id;
    cout << "请输入要归还图书的读者编号: ";
    cin >> reader_id;

    // 借用逻辑的占位符实现

    cout << "图书归还成功。\n";
}

void Library::saveData() {
    ofstream bookFile("books.txt");
    if (!bookFile.is_open()) {
        cerr << "无法打开books.txt进行写入。\n";
        return;
    }

    for (const auto& book : books) {
        bookFile << book.getBookId() << ',' << book.getTitle() << ',' << book.getPublisher() << '\n';
    }

    bookFile.close();

    ofstream readerFile("readers.txt");
    if (!readerFile.is_open()) {
        cerr << "无法打开readers.txt进行写入。\n";
        return;
    }

    for (const auto& reader : readers) {
        readerFile << reader.getReaderId() << ',' << reader.getName() << ',' << reader.getGender() << ',' << reader.getContact() << '\n';
    }

    readerFile.close();

    cout << "数据保存成功。\n";
}

void Library::loadData() {
    ifstream bookFile("books.txt");
    if (!bookFile.is_open()) {
        cerr << "无法打开books.txt进行阅读。\n";
        return;
    }

    int id;
    string title, publisher;
    while (bookFile >> id) {
        bookFile.ignore(); // Ignore the comma
        getline(bookFile, title, ',');
        getline(bookFile, publisher);

        books.push_back(Book(id, title, publisher));
    }

    bookFile.close();

    ifstream readerFile("readers.txt");
    if (!readerFile.is_open()) {
        cerr << "无法打开readers.txt进行阅读。\n";
        return;
    }

    char gender;
    string name, contact;
    while (readerFile >> id) {
        readerFile.ignore(); // 忽略逗号
        getline(readerFile, name, ',');
        readerFile >> gender;
        readerFile.ignore(); // 忽略逗号
        getline(readerFile, contact);

        readers.push_back(Reader(id, name, gender, contact));
    }

    readerFile.close();

    cout << "数据加载成功。\n";
}

// 主界面(驱动程序的主要功能)
int main() {
    Library library;
    int choice;

    do {
        cout << "\n图书管理系统\n";
        cout << "1. 添加图书\n";
        cout << "2. 查询图书\n";
        cout << "3. 编辑图书\n";
        cout << "4. 删除图书\n";
        cout << "5. 读者注册\n";
        cout << "6. 查询读者\n";
        cout << "7. 编辑读者\n";
        cout << "8. 删除读者\n";
        cout << "9. 借阅图书\n";
        cout << "10.归还图书\n";
        cout << "0. 退出程序\n";
        cout << "请输入您的选择: ";
        cin >> choice;

        switch (choice) {
        case 1:
            library.addBook();
            break;
        case 2:
            library.searchBook();
            break;
        case 3:
            library.editBook();
            break;
        case 4:
            library.deleteBook();
            break;
        case 5:
            library.addReader();
            break;
        case 6:
            library.searchReader();
            break;
        case 7:
            library.editReader();
            break;
        case 8:
            library.deleteReader();
            break;
        case 9:
            library.borrowBook();
            break;
        case 10:
            library.returnBook();
            break;
        case 0:
            cout << "退出程序\n";
            break;
        default:
            cout << "无效选择。请再次输入。\n";
        }
    } while (choice != 0);

    return 0;
}

三、分布介绍

1.主页面展示

通过简单的可视化界面展示

// 主界面(驱动程序的主要功能)
int main() {
    Library library;
    int choice;

    do {
        cout << "\n图书管理系统\n";
        cout << "1. 添加图书\n";
        cout << "2. 查询图书\n";
        cout << "3. 编辑图书\n";
        cout << "4. 删除图书\n";
        cout << "5. 读者注册\n";
        cout << "6. 查询读者\n";
        cout << "7. 编辑读者\n";
        cout << "8. 删除读者\n";
        cout << "9. 借阅图书\n";
        cout << "10.归还图书\n";
        cout << "0. 退出程序\n";
        cout << "请输入您的选择: ";
        cin >> choice;

        switch (choice) {
        case 1:
            library.addBook();
            break;
        case 2:
            library.searchBook();
            break;
        case 3:
            library.editBook();
            break;
        case 4:
            library.deleteBook();
            break;
        case 5:
            library.addReader();
            break;
        case 6:
            library.searchReader();
            break;
        case 7:
            library.editReader();
            break;
        case 8:
            library.deleteReader();
            break;
        case 9:
            library.borrowBook();
            break;
        case 10:
            library.returnBook();
            break;
        case 0:
            cout << "退出程序\n";
            break;
        default:
            cout << "无效选择。请再次输入。\n";
        }
    } while (choice != 0);

    return 0;
}

2.代表图书和读者的类

// 图书类与读者类的声明
class Book;
class Reader;

// 管理图书馆的类
class Library {
private:
    vector<Book> books;
    vector<Reader> readers;

public:
    // 构造器
    Library();

    // 图书操作
    void addBook();
    void searchBook();
    void editBook();
    void deleteBook();

    // 读者操作
    void addReader();
    void searchReader();
    void editReader();
    void deleteReader();

    // 借阅与归还操作
    void borrowBook();
    void returnBook();

    // 文件操作
    void saveData();
    void loadData();
};

// 代表图书的类
class Book {
private:
    int book_id;
    string title;
    string publisher;

public:
    // 构造器
    Book(int id, const string& t, const string& pub) : book_id(id), title(t), publisher(pub) {}

    // get方法
    int getBookId() const { return book_id; }
    string getTitle() const { return title; }
    string getPublisher() const { return publisher; }

    // set方法
    void setTitle(const string& t) { title = t; }
    void setPublisher(const string& pub) { publisher = pub; }

    // 方法来显示读取构造器详细信息
    void display() const {
        cout << "图书书号: " << setw(5) << setfill('0') << book_id << " | 图书书名: " << title << " | 图书出版社: " << publisher << endl;
    }
};

// 代表读者的类
class Reader {
private:
    int reader_id;
    string name;
    char gender;
    string contact;

public:
    // 构造器
    Reader(int id, const string& n, char g, const string& con) : reader_id(id), name(n), gender(g), contact(con) {}

    // get方法
    int getReaderId() const { return reader_id; }
    string getName() const { return name; }
    char getGender() const { return gender; }
    string getContact() const { return contact; }

    // set方法
    void setName(const string& n) { name = n; }
    void setGender(char g) { gender = g; }
    void setContact(const string& con) { contact = con; }

    // 方法来显示读取构造器详细信息
    void display() const {
        cout << "读者编号: " << setw(5) << setfill('0') << reader_id << " | 读者姓名: " << name << " | 读者性别: " << gender << " | 读者联系方式: " << contact << endl;
    }
};

3.相关类方法的实现

// 类方法的实现

Library::Library() {
    // 创建库对象时从文件加载数据
    loadData();
}

void Library::addBook() {
    int id;
    string title, publisher;

    cout << "请输入图书书号: ";
    cin >> id;
    cin.ignore(); // 从缓冲区中清除换行符

    cout << "请输入图书书名: ";
    getline(cin, title);

    cout << "请输入图书出版社: ";
    getline(cin, publisher);

    books.push_back(Book(id, title, publisher));

    cout << "图书添加成功。\n";

    saveData(); // 添加成功后保存数据
}

void Library::searchBook() {
    int search_id;
    cout << "请输入要搜索的图书书号: ";
    cin >> search_id;

    bool found = false;
    for (const auto& book : books) {
        if (book.getBookId() == search_id) {
            book.display();
            found = true;
            break;
        }
    }

    if (!found) {
        cout << "没有找到该图书: " << search_id << endl;
    }
}

void Library::editBook() {
    int edit_id;
    cout << "请输入要编辑的图书书号: ";
    cin >> edit_id;

    for (auto& book : books) {
        if (book.getBookId() == edit_id) {
            string new_title, new_publisher;

            cout << "请输入新的书名(输入以保持当前状态): ";
            cin.ignore(); // 从缓冲区中清除换行符
            getline(cin, new_title);
            if (!new_title.empty()) {
                book.setTitle(new_title);
            }

            cout << "情输入新的出版社 (输入以保持当前状态): ";
            getline(cin, new_publisher);
            if (!new_publisher.empty()) {
                book.setPublisher(new_publisher);
            }

            cout << "图书详细信息更新成功。\n";
            saveData(); // 更新后保存数据
            return;
        }
    }

    cout << "没有找到该图书: " << edit_id << endl;
}

void Library::deleteBook() {
    int delete_id;
    cout << "请输入要删除的图书书号: ";
    cin >> delete_id;

    auto it = books.begin();
    while (it != books.end()) {
        if (it->getBookId() == delete_id) {
            it = books.erase(it);
            cout << "图书删除成功。\n";
            saveData(); // 删除后保存数据
            return;
        }
        else {
            ++it;
        }
    }

    cout << "没有找到该图书: " << delete_id << endl;
}

void Library::addReader() {
    int id;
    string name, contact;
    char gender;

    cout << "请输入读者编号: ";
    cin >> id;
    cin.ignore(); // 从缓冲区中清除换行符

    cout << "请输入读者姓名: ";
    getline(cin, name);

    cout << "请输入读者性别(M/F): ";
    cin >> gender;

    cout << "请输入读者联系方式: ";
    cin.ignore(); // 从缓冲区中清除换行符
    getline(cin, contact);

    readers.push_back(Reader(id, name, gender, contact));

    cout << "读者添加成功。\n";

    saveData(); // 添加成功后保存数据
}

void Library::searchReader() {
    int search_id;
    cout << "请输入要查询的读者编号: ";
    cin >> search_id;

    bool found = false;
    for (const auto& reader : readers) {
        if (reader.getReaderId() == search_id) {
            reader.display();
            found = true;
            break;
        }
    }

    if (!found) {
        cout << "没有找到该读者: " << search_id << endl;
    }
}

void Library::editReader() {
    int edit_id;
    cout << "请输入要编辑的读者编号: ";
    cin >> edit_id;

    for (auto& reader : readers) {
        if (reader.getReaderId() == edit_id) {
            string new_name, new_contact;
            char new_gender;

            cout << "请输入新的姓名(输入以保持当前状态): ";
            cin.ignore(); // 从缓冲区中清除换行符
            getline(cin, new_name);
            if (!new_name.empty()) {
                reader.setName(new_name);
            }

            cout << "请输入新的性别 (M/F) (输入以保持当前状态): ";
            cin >> new_gender;
            if (new_gender == 'M' || new_gender == 'F') {
                reader.setGender(new_gender);
            }

            cout << "请输入新的联系方式(输入以保持当前状态): ";
            cin.ignore(); // 从缓冲区中清除换行符
            getline(cin, new_contact);
            if (!new_contact.empty()) {
                reader.setContact(new_contact);
            }

            cout << "读者详细信息更新完成。\n";
            saveData(); // 更新后保存数据
            return;
        }
    }

    cout << "没有找到该读者: " << edit_id << endl;
}

void Library::deleteReader() {
    int delete_id;
    cout << "请输入要删除的读者编号: ";
    cin >> delete_id;

    auto it = readers.begin();
    while (it != readers.end()) {
        if (it->getReaderId() == delete_id) {
            it = readers.erase(it);
            cout << "读者删除成功。\n";
            saveData(); // 删除后保存数据
            return;
        }
        else {
            ++it;
        }
    }

    cout << "没有找到该读者: " << delete_id << endl;
}

void Library::borrowBook() {
    int book_id, reader_id;
    cout << "请输入要借阅图书的图书编号: ";
    cin >> book_id;
    cout << "请输入要借阅图书的读者编号: ";
    cin >> reader_id;

    // 借用逻辑的占位符实现

    cout << "图书借阅成功。\n";
}

void Library::returnBook() {
    int book_id, reader_id;
    cout << "请输入要归还图书的图书编号: ";
    cin >> book_id;
    cout << "请输入要归还图书的读者编号: ";
    cin >> reader_id;

    // 借用逻辑的占位符实现

    cout << "图书归还成功。\n";
}

void Library::saveData() {
    ofstream bookFile("books.txt");
    if (!bookFile.is_open()) {
        cerr << "无法打开books.txt进行写入。\n";
        return;
    }

    for (const auto& book : books) {
        bookFile << book.getBookId() << ',' << book.getTitle() << ',' << book.getPublisher() << '\n';
    }

    bookFile.close();

    ofstream readerFile("readers.txt");
    if (!readerFile.is_open()) {
        cerr << "无法打开readers.txt进行写入。\n";
        return;
    }

    for (const auto& reader : readers) {
        readerFile << reader.getReaderId() << ',' << reader.getName() << ',' << reader.getGender() << ',' << reader.getContact() << '\n';
    }

    readerFile.close();

    cout << "数据保存成功。\n";
}

void Library::loadData() {
    ifstream bookFile("books.txt");
    if (!bookFile.is_open()) {
        cerr << "无法打开books.txt进行阅读。\n";
        return;
    }

    int id;
    string title, publisher;
    while (bookFile >> id) {
        bookFile.ignore(); // Ignore the comma
        getline(bookFile, title, ',');
        getline(bookFile, publisher);

        books.push_back(Book(id, title, publisher));
    }

    bookFile.close();

    ifstream readerFile("readers.txt");
    if (!readerFile.is_open()) {
        cerr << "无法打开readers.txt进行阅读。\n";
        return;
    }

    char gender;
    string name, contact;
    while (readerFile >> id) {
        readerFile.ignore(); // 忽略逗号
        getline(readerFile, name, ',');
        readerFile >> gender;
        readerFile.ignore(); // 忽略逗号
        getline(readerFile, contact);

        readers.push_back(Reader(id, name, gender, contact));
    }

    readerFile.close();

    cout << "数据加载成功。\n";
}

图书馆流通管理软件 作为面向对象程序计的第一步,在实际系统中,识别对象和类是很重要的。在这里,我们以图书馆流通管理系统为例,介绍识别对象与类的一般方法。 1、对象和类的识别 在一个信息系统内识别对象最简单也是最主要的方法是对具体事物的属性和功能进行分析,一旦识别到一个对象,就能识别出相同类型的所有对象,把它们归纳为类。 图书馆流通系统内,有书、读者、借书证、管理人员、借书还书行为等对象和事件,他们分别各是一个群体。例如每个图书馆都有几万甚至几十万册图书,每册图书都是一个对象,它们形成图书类(在此暂时用Item款目表示)。相应的,在图书流通系统内,还可以得到以下类: 读者(Reader)类,在图书馆注册的每位借书人都是一个读者类的对象; 图书借阅信息类(Loan),每次发生借书行为,都产生一个借阅信息的对象; 管理人员类(Manager),是借书还书行为的操作人。 借书证对象虽然是实实在在的对象,但每位读者对应一本借书证,且只需要知道其编号,因此不需要另外定义类,只作为读者类的一个数据成员。 同一个信息系统,从不同的角度分析,或根据要求的不同,有不同的侧重面,这样建立的对象模型不同,可能得出的分类方法也不同。 2、对象属性的识别 每个对象的情况称为对象的属性,同类型的对象具有共同的属性,只是每个对象的属性值不一定相同。属性是对一个对象状态的描述,如“在馆图书类”,从流通管理的角度来看,应包含书名Title、作者名Author、分类号IndexCode、册数Number、条码号BarCode等属性。 其它类的属性如下: 读者类,包含姓名Name、职务Position、年龄Age、借书证编号Code等。一个读者允许借阅若干册书,在此用一个Item的数组items保存相应信息。另外对读者所借书册数要统计,定义一个计数的成员Counter; 图书借阅信息类,包含所借书item、借书人reader、借书操作员manager等; 管理人员类,包含姓名Name、年龄Age、工号Code等; 管理人员类只有在发生借书行为时才作为操作人员记录下来,可以作为借书信息类的一个数据成员记录备查,程序中未定义其对象。 同一个类(对象),从不同的角度分析,或根据要求的不同,描述它的属性也可能不一致。 3、对象功能的确定 对象的功能指为了达到目的必须执行的动作,或是对象对所发生事件的反应。功能也可称为对象的操作。 在图书馆流通管理系统内,图书类应包含为各属性赋值(Set…)的操作、读取条码(GetCode)和显示图书基本信息(Show)的操作,另外还定义了缺省构造函数和拷贝构造函数。 读者类,需定义为各属性赋值(Set…)的操作、读取借书证号的操作,借书和还书需要向所借书数组中添加或减少书,定义AddBook和DelBook两个操作,还有显示所借书的操作ShowBooks。 4、对象和类的标记 在这里采用科德(Coad)定义的面向对象方法的描述符号,这一方法是Peter Coad和Ed YourDon于1990年提出的,这一方法的优点是图形简单、易于理解和掌握,但对类和对象属性的访问权限无法进行有效的描述。 科德标记法中,使用一个圆角矩形表示类,矩形内部分为三个部分,上部写类名,中部写属性(数据成员),下部表示该类的操作(函数成员)。对象是类的实例,在科德标记法中,在相应类标记外加一个圆角矩形框表示对象,并将矩形内部的表示类名的地方写上对象名,如图4.15。 科德表示法可形象地用扑克牌示意图来表示。如图4.16,一个类可能有0个或1个2个3个甚至更多对象,但没有实例化以前,它们在图上只画一个圆角矩形,就像一叠扑克牌,只看见最上面的一张牌;当把这叠牌散开时,它们是若干个对象,就像类被实例化了。 科德标记法还有表示连接的符号,如图4.17,一个带线段的半圆弧表示A是通用类,B是特殊类,中间带空心三角形的线段表示A类包含B类即整体与部分的关系,中间带实心箭头的线段表示A向B发送消息,一段实线表示对象之间的连接线。 根据上面对的图书馆流通管理系统的分析,在图4.18中,用科德标记法表示Item, Reader, Manager, Loan四个类,它们的数据成员及其类型、函数成员的原型都在图中标出,但无法标出它们的访问权限。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值