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

C++實現(xiàn)圖書管理系統(tǒng)簡易版

 更新時間:2022年03月14日 09:51:26   作者:阿白i  
這篇文章主要為大家詳細介紹了C++實現(xiàn)圖書管理系統(tǒng)簡易版,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

包括管理員端和學(xué)生端,可以對圖書進行借閱,歸還,還可以修改賬號登陸密碼等

#include<iostream>
#include<string>
#include<string.h>
#include<cstdio>
#include<conio.h>
#include<fstream>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<regex>
#include<windows.h>
#include<sstream>//stringstream要使用到的頭文件
#define STUDENT_FILE "student_text.txt"
#define BOOK_FILE "book_text.txt"
#define CLASS_FILE "class.txt"
#define MAX 1000
#define MIN 100
using namespace std;
class Student;
class Book;
class Clazz;
void initialize();//初始化
void Manager_Menu();
void Student_Menu();
void existSystem(); ?//退出圖書管理系統(tǒng)
?
void show_book_base();
string input_password();//不可見輸入密碼
int student_id_exist(int id);//查找用戶是否存在
int manager_id_exist(int id);
int book_id_exist(int id);//查找書籍是否存在
int class_id_exist(int id);
int random_id(); //產(chǎn)生隨機圖書編號
void book_find();
void load_information();
void update_information();
void regist_windows();
void regist_manager();
void regist_student();
bool student_cmp(Student a, Student b);
bool class_cmp(Clazz a, Clazz b);
bool book_cmp(Book a, Book b);
class Book
{
? ? int book_id; ? ? ? ? ? ? ? ? ? ?//書籍編號
? ? string book_name; ? ? ? ? ? ? ? //書籍名稱
? ? int book_total_num; ? ? ? ? ? ? //該類書籍總數(shù)
? ? string book_author; ? ? ? ? ? ? //書籍作者
? ? string book_type; ? ? ? ? ? ? ? //書籍分類
? ? string book_present; ? ? ? ? ? ?//書籍簡介
? ? int book_student_len; ? ? ? ? ? //每種書共有幾人選
? ? int student_id[MIN]; ? ? ? //借閱該書籍的學(xué)生學(xué)號
? ? string student_name[MIN]; ?//借閱該書籍的學(xué)生姓名
public:
? ? Book()
? ? {
? ? ? ? book_id = -1;
? ? ? ? book_total_num = 0;
? ? ? ? book_student_len = 0;
? ? ? ? book_type = "";
? ? ? ? book_present = "";
? ? ? ? memset(student_id, 0, MIN);
? ? ? ? for (int i = 0; i < MIN; i++)
? ? ? ? {
? ? ? ? ? ? student_name[i] = "";
? ? ? ? }
? ? }
? ? void set_book_name(string book_name)
? ? {
? ? ? ? this->book_name = book_name;
? ? }
? ? void set_book_author(string book_author)
? ? {
? ? ? ? this->book_author = book_author;
? ? }
? ? void set_book_type(string book_type)
? ? {
? ? ? ? this->book_type = book_type;
? ? }
? ? void set_book_total_num(int book_total_num)
? ? {
? ? ? ? this->book_total_num = book_total_num;
? ? }
? ? void set_book_id(int book_id)
? ? {
? ? ? ? this->book_id = book_id;
? ? }
? ? int get_book_id()
? ? {
? ? ? ? return book_id;
? ? }
? ? void set_book_information(int book_id, string book_name, int book_total_num, string book_author, string book_type)
? ? {
? ? ? ? set_book_id(book_id);
? ? ? ? set_book_name(book_name);
? ? ? ? set_book_author(book_author);
? ? ? ? set_book_type(book_type);
? ? ? ? set_book_total_num(book_total_num);
? ? ? ? //set_book_present(book_present);
? ? }
? ? void set_book_present(string book_present)
? ? {
? ? ? ? this->book_present = book_present;
? ? }
? ? string& get_book_present()
? ? {
? ? ? ? return book_present;
? ? }
? ? void show_book_information();
? ? friend int book_id_exist(int id);
? ? friend void show_book_base();
? ? friend class Student;
? ? friend class Manager;
? ? friend void initialize();
? ? friend void load_information();
? ? friend void update_information();
};
Book book[MAX];
int book_len = 0;
class User
{
protected:
? ? int id;
? ? string name;
? ? string password;
? ? int mark;
public:
? ? User()
? ? {
? ? ? ? id = -1;
? ? ? ? mark = 0;
? ? ? ? name = "";
? ? ? ? password = "";
? ? }
? ? void password_update();
? ? virtual void book_insert()=0;
? ? virtual void book_delete()=0;
? ? friend void initialize();
? ? void set_id(int id)
? ? {
? ? ? ? this->id = id;
? ? }
? ? void set_name(string name)
? ? {
? ? ? ? this->name = name;
? ? }
? ? void set_mark(int mark)
? ? {
? ? ? ? this->mark = mark;
? ? }
? ? void set_password(string password)
? ? {
? ? ? ? this->password = password;
? ? }
? ? int get_id()
? ? {
? ? ? ? return ?id;
? ? }
? ? int get_mark()
? ? {
? ? ? ? return this->mark;
? ? }
? ? string get_name()
? ? {
? ? ? ? return name;
? ? }
? ? string get_password()
? ? {
? ? ? ? return password;
? ? }
};
class Student:public User
{
? ? int student_grade; ? ?//入學(xué)年份--年級
? ? int class_id;
? ? string student_gender;
? ? int student_book_len;//借閱書籍總數(shù)
public:
? ? Student()
? ? {
? ? ? ? id = -1; ?//id為-1時表示該賬戶無效
? ? ? ? class_id = -1;
? ? ? ? name = "";
? ? ? ? student_gender = "";
? ? ? ? student_grade = -1;
? ? ? ? student_book_len = 0;
? ? }
? ? Student operator = (const Student& p);
? ? void set_class_id(int id)
? ? {
? ? ? ? class_id = id;
? ? }
? ? void set_student_grade(int student_grade)
? ? {
? ? ? ? this->student_grade = student_grade;
? ? }
? ? void set_student_gender(string student_gender)
? ? {
? ? ? ? this->student_gender = student_gender;
? ? }
? ? int get_class_id()
? ? {
? ? ? ? return class_id;
? ? }
? ? int get_student_grade()
? ? {
? ? ? ? return student_grade;
? ? }
? ? string get_student_gender()
? ? {
? ? ? ? return ?student_gender;
? ? }
? ??
? ? //學(xué)生
? ? void book_insert();
? ? void student_information_view();
? ? void book_delete();
? ? void student_information_update();
? ? //學(xué)生修改賬號密碼
? ??
? ? void show_self();
? ? void student_windows();
?
? ? friend void eroll_windows();
?
? ? friend class Manager;
? ? friend void load_information();
? ? friend void update_information();
? ? friend bool student_cmp(Student a,Student b);
};
Student student[MAX];
int student_len = 0;
class Manager :public User
{
public:
? ? Manager()
? ? {
? ? ? ? id = -1;
? ? ? ? mark = 0;
? ? ? ? name = "";
? ? ? ? password = "";
? ? }
? ? Manager(int id,int mark,string name,string password)
? ? {
? ? ? ? this->id =id;
? ? ? ? this->mark = mark;
? ? ? ? this->name = name;
? ? ? ? this->password = password;
? ? }
? ? Manager operator = (const Manager& p);
? ? //管理員對學(xué)生賬號的管理
? ? void student_insert();
? ? void student_delete();
? ? void student_view();
?
? ? //管理員對書籍的管理
? ? void book_insert();
? ? void book_delete();
? ? void book_view();
? ? void book_update();
? ? //班級
? ? void class_insert();
? ? void class_update();
? ? void class_view();
? ? void class_delete();
? ? void manager_windows();
? ? void manager_insert();
? ??
? ? friend void load_information();
? ? friend void update_information();
};
Manager manager[MIN];
int manager_len = 0;
class Clazz
{
? ? int class_id;
? ? string class_name;
? ? string teacher_name;
? ? int student_len;
public:
? ? Clazz()
? ? {
? ? ? ? class_id = -1;
? ? ? ? class_name = "";
? ? ? ? teacher_name = "";
? ? ? ? student_len = 0;
? ? }
? ? int get_class_id()
? ? {
? ? ? ? return class_id;
? ? }
? ? string get_class_name()
? ? {
? ? ? ? return class_name;
? ? }
? ? string get_teacher_name()
? ? {
? ? ? ? return teacher_name;
? ? }
? ? void set_class_id(int id)
? ? {
? ? ? ? this->class_id =id;
? ? }
? ? void set_class_name(string name)
? ? {
? ? ? ? this->class_name = name;
? ? }
? ? void set_teacher_name(string name)
? ? {
? ? ? ? this->teacher_name = name;
? ? }
? ??
? ? friend int class_id_exist(int id);
? ? friend void load_information();
? ? friend void update_information();
};
Clazz clazz[MIN];
int class_len = 0;
?
int main()
{
? ? initialize();
? ? //登錄
? ? regist_windows();
? ? system("pause");
? ? return 0;
}
?
void initialize()
{
? ? system("title 圖書信息管理系統(tǒng)");
? ? system("color f0");
? ? system("mode con cols=90 lines=38");
? ? srand((int)time(0));
?
? ? load_information();
? ? Manager p1;
? ? p1.set_id(111111);
? ? p1.set_name("張暉");
? ? p1.set_password("111111");
? ? manager[0]=p1; manager_len++;
? ? Manager p2(222222,1, "李四", "222222");
? ? manager[1]=p2; manager_len++;
}
void Manager_Menu()
{
?
? ? cout << " ________________________________________________________________________________________" << endl;
? ? cout << " | ? ? ? ? ? ? ? ? ? ? ? ? ? ? 圖書管理管理系統(tǒng) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |" << endl;
? ? cout << " |______________________________________________________________________________________|" << endl;
? ? cout << " | ? ? ? ? ? ? ?1.增加學(xué)生信息 ? ? ? ? ? ? ?| ? ? ? ? ? ? ?13.修改登錄密碼 ? ? ? ? ? ? ?|" << endl;
? ? cout << " | ? ? ? ? ? ? ?2.查看學(xué)生信息 ? ? ? ? ? ? ?| ? ? ? ? ? ? ?14.退出當前賬號 ? ? ? ? ? ? ?|" << endl;
? ? cout << " | ? ? ? ? ? ? ?3.刪除學(xué)生信息 ? ? ? ? ? ? ?| ? ? ? ? ? ? ?0.退出管理系統(tǒng) ? ? ? ? ? ? ? |" << endl;
? ? cout << " |__________________________________________|___________________________________________|" << endl;
? ? cout << " | ? ? ? ? ? ? ?4.增加書籍信息 ? ? ? ? ? ? ?| ? ? ? ? ? ? ?8.增加班級信息 ? ? ? ? ? ? ? |" << endl;
? ? cout << " | ? ? ? ? ? ? ?5.查看書籍信息 ? ? ? ? ? ? ?| ? ? ? ? ? ? ?9.查看班級信息 ? ? ? ? ? ? ? |" << endl;
? ? cout << " | ? ? ? ? ? ? ?6.修改書籍信息 ? ? ? ? ? ? ?| ? ? ? ? ? ? ?10.修改班級信息 ? ? ? ? ? ? ?|" << endl;
? ? cout << " | ? ? ? ? ? ? ?7.刪除書籍信息 ? ? ? ? ? ? ?| ? ? ? ? ? ? ?11.刪除班級信息 ? ? ? ? ? ? ?|" << endl;
? ? cout << " | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| ? ? ? ? ? ? ?12.增加管理員 ? ? ? ? ? ? ? ?|" << endl;
? ? cout << " |__________________________________________|___________________________________________|" << endl;
? ? cout << endl;
}
void Student_Menu()
{
? ? cout << " ? ? ? ? ? ______________________________________________" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? ?學(xué)生圖書系統(tǒng) ? ? ? ? ? ? ? ?|" << endl;
? ? cout << " ? ? ? ? ? |____________________________________________|" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? 1.選擇借閱書籍 ? ? ? ? ? ? ? |" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? 2.查找書籍信息 ? ? ? ? ? ? ? |" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? 3.歸還借閱書籍 ? ? ? ? ? ? ? |" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? 4.查詢個人信息 ? ? ? ? ? ? ? |" << endl;
? ? cout << " ? ? ? ? ? |____________________________________________|" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? 5.修改個人信息 ? ? ? ? ? ? ? |" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? 6.修改登錄密碼 ? ? ? ? ? ? ? |" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? 7.退出當前賬號 ? ? ? ? ? ? ? |" << endl;
? ? cout << " ? ? ? ? ? | ? ? ? ? ? ? ? 0.退出管理系統(tǒng) ? ? ? ? ? ? ? |" << endl;
? ? cout << " ? ? ? ? ? |____________________________________________|" << endl;
? ? cout << endl;
}
void Manager::manager_windows()
{
? ? while (true)
? ? {
? ? ? ? int choice = 0;
? ? ? ? Manager_Menu();
? ? ? ? cout << "\t\t請輸入您的選擇:" << endl;
? ? ? ? cout << " ? ? ? ? ?";
? ? ? ? cin >> choice;
? ? ? ? switch (choice)
? ? ? ? {
? ? ? ? case 0://退出
? ? ? ? {
? ? ? ? ? ? existSystem();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 1://添加
? ? ? ? {
? ? ? ? ? ? student_insert();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 2://顯示
? ? ? ? {
? ? ? ? ? ? student_view();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 3://刪除
? ? ? ? {
? ? ? ? ? ? student_delete();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 4:
? ? ? ? {
? ? ? ? ? ? book_insert();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 5:
? ? ? ? {
? ? ? ? ? ? book_view();//book_find();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 6://查找
? ? ? ? {
? ? ? ? ? ? book_update();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 7:
? ? ? ? {
? ? ? ? ? ? book_delete();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 8:
? ? ? ? {
? ? ? ? ? ? class_insert();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 9:
? ? ? ? {
? ? ? ? ? ? class_view();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 10://查找
? ? ? ? {
? ? ? ? ? ? class_update();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 11:
? ? ? ? {
? ? ? ? ? ? class_delete();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 12:
? ? ? ? {
? ? ? ? ? ? manager_insert();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 13:
? ? ? ? {
? ? ? ? ? ? password_update();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 14://回到登錄界面
? ? ? ? {
? ? ? ? ? ? system("cls");
? ? ? ? ? ? update_information();
? ? ? ? ? ? regist_windows();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? default:
? ? ? ? {
? ? ? ? ? ? cout << "沒有該選項!" << endl;
? ? ? ? ? ? system("cls");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? }
? ? }
}
void Student::student_windows()
{
?
? ? while (true)
? ? {
? ? ? ? int choice = 0;
? ? ? ? Student_Menu();
? ? ? ? cout << "\t\t請輸入您的選擇:" << endl;
? ? ? ? cout << " ? ? ? ? ";
? ? ? ? cin >> choice;
? ? ? ? switch (choice)
? ? ? ? {
? ? ? ? case 0://退出
? ? ? ? {
? ? ? ? ? ? existSystem();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 1://添加
? ? ? ? {
? ? ? ? ? ? book_insert();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 2:
? ? ? ? {
? ? ? ? ? ? book_find();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 3:
? ? ? ? {
? ? ? ? ? ? book_delete();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 4:
? ? ? ? {
? ? ? ? ? ? student_information_view();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 5:
? ? ? ? {
? ? ? ? ? ? student_information_update();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 6:
? ? ? ? {
? ? ? ? ? ? password_update();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 7://回到登錄界面
? ? ? ? {
? ? ? ? ? ? system("cls");
? ? ? ? ? ? update_information();
? ? ? ? ? ? regist_windows();
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? default:
? ? ? ? {
? ? ? ? ? ? cout << "沒有該選項" << endl;
? ? ? ? ? ? system("cls");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? }
? ? }
}
void regist_windows()
{
? ? int select = 0;
? ? cout << "\t\t1.管理員登錄" << endl;
? ? cout << "\t\t2.學(xué)生登錄" << endl;
? ? cin >> select;
? ? system("cls");
? ? if (select == 1)
? ? {
? ? ? ? regist_manager();
? ? }
? ? else if (select == 2)
? ? {
? ? ? ? regist_student();
? ? }
? ? else
? ? {
? ? ? ? cout << "該選項不存在!請選擇1或2!" << endl;
? ? }
}
void regist_manager()
{
? ? cout << "\t用戶名:";
? ? int temp_user_id = -1; cin >> temp_user_id; cout << endl;
? ? cout << "\t密碼:";
? ? string temp_password; ?temp_password = input_password();
? ? int flag = 0;
? ? int position = manager_id_exist(temp_user_id);
? ? if (position == -1)
? ? {
? ? ? ? cout << "該用戶不存在!" << endl;
? ? ? ? regist_manager();
?
? ? }
? ? else if (manager[position].get_password() == temp_password)
? ? {
? ? ? ? system("cls");
? ? ? ? while (true)
? ? ? ? {
? ? ? ? ? ? manager[position].manager_windows();
? ? ? ? }
? ? }
? ? else
? ? {
? ? ? ? cout << "\t\t用戶名或密碼錯誤" << endl << endl;
? ? ? ? regist_manager();
? ? }
? ? system("pause");
? ? system("cls");
}
void regist_student()
{
? ? int temp_user_id = 0;
? ? string temp_password;
? ? cout << "\t用戶名:";
? ? cin >> temp_user_id;
? ? cout << endl;
? ? cout << "\t密碼:";
? ? temp_password = input_password();
? ? int flag = 0;
? ? int position = student_id_exist(temp_user_id);
? ? if (position == -1)
? ? {
? ? ? ? cout << "\t該用戶不存在!" << endl;
? ? ? ? regist_student();
? ? }
? ? else if (student[position].get_password() == temp_password)
? ? {
? ? ? ? system("cls");
? ? ? ? while (true)
? ? ? ? {
? ? ? ? ? ? student[position].student_windows();
? ? ? ? }
? ? }
? ? else
? ? {
? ? ? ? cout << "\t\t用戶名或密碼錯誤" << endl << endl;
? ? ? ? regist_student();
? ? }
? ? system("pause");
? ? system("cls");
}
void Book::show_book_information()
{
? ? cout << "-------------------------------------------------------------------------------------\n";
? ? cout << " 書名\t\t\t類型\t\t\t\t作者\n";
? ? cout << book_name << "\t\t\t" << book_type << "\t\t\t" << book_author << endl;
? ? cout << "-------------------------------------------------------------------------------------\n";
? ? cout << " 總數(shù)\t\t\t剩余量\n";
? ? cout << book_total_num << "\t\t\t" << (book_total_num - book_student_len) << endl;
? ? cout << "-------------------------------------------------------------------------------------\n";
? ? cout << "\t\t\t小說簡介\n";
? ? cout << book_present << endl;
? ? cout << "-------------------------------------------------------------------------------------\n";
}
void User::password_update()
{
? ? int flag = 0;
? ? while (true)
? ? {
? ? ? ? cout << "請輸入舊密碼:";
? ? ? ? string last_password, new_password1, new_password2;
? ? ? ? last_password = input_password();
? ? ? ? if (last_password == password)
? ? ? ? {
? ? ? ? ? ? cout << "請輸入新密碼(大于等于6位):"; new_password1 = input_password();
? ? ? ? ? ? cout << "請再次輸入新密碼:"; ? ? ? ? new_password2 = input_password();
? ? ? ? ? ? if (new_password1 == new_password2)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if ((new_password1.size() >= 6) && (new_password1.size() <= 13))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? this->password = new_password1;
? ? ? ? ? ? ? ? ? ? cout << "密碼修改成功!" << endl;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cout << "密碼應(yīng)大于等于6位!修改失?。? << endl;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "兩次密碼不一致!請重新輸入!" << endl;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? flag++;
? ? ? ? ? ? if (flag <= 3)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "舊密碼錯誤!" << endl;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "密碼多次輸入錯誤!返回菜單界面!";
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? system("pause");
? ? system("cls");
}
?
Manager ?Manager::operator = (const Manager& p)
{
? ? this->id = p.id;
? ? this->mark = p.mark;
? ? this->name = p.name;
? ? this->password = p.password;
? ? return *this;
}
void Manager::student_insert()
{
? ? if (student_len > MAX)
? ? {
? ? ? ? cout << "信息系統(tǒng)已滿,無法添加!" << endl;
? ? ? ? return;
? ? }
? ? else
? ? {
? ? ? ? Student temp_student;
? ? ? ? cout << "請輸入學(xué)號:" << endl;
? ? ? ? int temp_id; cin >> temp_id;
? ? ? ? cout << "請輸入姓名:" << endl;
? ? ? ? string temp_name; cin >> temp_name;
? ? ? ? cout << "請輸入權(quán)限:" << endl;
? ? ? ? cout << "1.普通用戶權(quán)限" << endl;
? ? ? ? cout << "2.高級用戶權(quán)限" << endl;
? ? ? ? int temp_mark; cin >> temp_mark;
? ? ? ? temp_student.set_mark(temp_mark);
? ? ? ? string temp_student_gender;
? ? ? ? while (true)
? ? ? ? {
? ? ? ? ? ? cout << "請選擇性別:" << endl;
? ? ? ? ? ? cout << "1.女\n2.男\(zhòng)n";
? ? ? ? ? ? int choice = 0; cin >> choice;
? ? ? ? ? ? if (choice == 1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp_student_gender = "女"; break;
? ? ? ? ? ? }
? ? ? ? ? ? else if (choice == 2)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp_student_gender = "男"; break;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "沒有該選項!請重新選擇!\n";
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? int temp_student_grade;
? ? ? ? while (true)
? ? ? ? {
? ? ? ? ? ? cout << "請輸入年級(入學(xué)年份):" << endl;
? ? ? ? ? ? cout << "1.2018\n2.2019\n3.2020\n4.2021\n";
? ? ? ? ? ? int choice = 0; cin >> choice;
? ? ? ? ? ? if (choice == 1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp_student_grade = 2018; break;
? ? ? ? ? ? }
? ? ? ? ? ? else if (choice == 2)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp_student_grade = 2019; break;
? ? ? ? ? ? }
? ? ? ? ? ? else if (choice == 3)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp_student_grade = 2020; break;
? ? ? ? ? ? }
? ? ? ? ? ? else if (choice == 2)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp_student_grade = 2021; break;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "沒有該選項!請重新選擇!\n";
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? cout << "\t\t班級信息如下\n";
? ? ? ? for (int i = 0; i < class_len; i++)
? ? ? ? ? ? cout << clazz[i].get_class_id() << "\t\t" << clazz[i].get_class_name() << endl;
? ? ? ? while (1)
? ? ? ? {
? ? ? ? ? ? cout << "請輸入班級編號\n";
? ? ? ? ? ? int temp_id = 0; cin >> temp_id;
? ? ? ? ? ? if (class_id_exist(temp_id) != -1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp_student.set_class_id(temp_id);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "該班級編號不存在!\n";
? ? ? ? ? ? }
? ? ? ? }
?
? ? ? ? string temp_password;
? ? ? ? stringstream transform;
? ? ? ? transform << temp_id; transform >> temp_password;
? ? ? ? temp_student.set_password(temp_password);
? ? ? ? temp_student.set_id(temp_id);
? ? ? ? temp_student.set_student_grade(temp_student_grade);
? ? ? ? temp_student.set_name(temp_name);
? ? ? ? temp_student.set_student_gender(temp_student_gender);
? ? ? ? student[student_len] = temp_student;
? ? ? ?/* while (1)
? ? ? ? {
? ? ? ? ? ? cout << "請設(shè)置您的密碼:" << endl;
? ? ? ? ? ? temp_password1 = input_password();
? ? ? ? ? ? temp_password2 = input_password();
? ? ? ? ? ? if (temp_password1 == temp_password2)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? student[student_len].password = temp_password1;
? ? ? ? ? ? ? ? student_len++;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "兩次密碼不一致!請重新設(shè)置密碼!" << endl;
? ? ? ? ? ? }
? ? ? ? }*/
? ? ? ? student_len++;
? ? ? ? cout << "學(xué)生信息添加成功!" << endl;
? ? ? ? sort(student, student + student_len, student_cmp);
? ? }
? ? system("pause");
? ? system("cls");
}
void Manager::student_view()
{
? ? cout << "\t\t1.查詢單個賬號信息" << endl;
? ? cout << "\t\t2.查看所有賬號信息" << endl;
? ? int choice; cin >> choice;
? ? if (choice == 1)
? ? {
? ? ? ? cout << "\t\t請輸入查詢賬號:" << endl;
? ? ? ? int id; cin >> id;
? ? ? ? int pos = student_id_exist(id);
? ? ? ? if (pos == -1)
? ? ? ? {
? ? ? ? ? ? cout << "\t\t該賬號不存在!" << endl;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? student[pos].show_self();
? ? ? ? }
? ? }
? ? else
? ? {
? ? ? ? if (student_len == 0)
? ? ? ? {
? ? ? ? ? ? cout << "當前記錄為空" << endl;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? cout << "序號:\t姓名:\t學(xué)號: \t年級: \t性別\n";
? ? ? ? ? ? for (int i = 0; i < student_len; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << i + 1 << "\t\t";
? ? ? ? ? ? ? ? cout << student[i].name << "\t\t" << student[i].id << "\t\t";
? ? ? ? ? ? ? ? if (student[i].student_book_len == 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cout << "未借閱書籍";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? for (int j = 0; j < book_len; j++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? for (int k = 0; k < book[j].book_total_num; k++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (book[j].student_name[k] == student[i].name)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cout << book[j].book_id << "\t\t" << book[j].book_name << endl;;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? cout << endl;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? system("pause");
? ? system("cls");
}
void Manager::student_delete()
{
? ? cout << "請輸入您要刪除的學(xué)生賬號:" << endl;
? ? int temp_id;
? ? cin >> temp_id;
? ? int position = student_id_exist(temp_id);
? ? if (position != -1)
? ? {
? ? ? ? for (int i = position; i < student_len - 1; i++)
? ? ? ? {
? ? ? ? ? ? student[i] = student[i + 1];
? ? ? ? }
? ? ? ? student_len--;
? ? ? ? cout << "刪除成功" << endl;
? ? }
? ? else
? ? {
? ? ? ? cout << "該學(xué)生賬號不存在!" << endl;
? ? }
? ? system("pause");
? ? system("cls");
}
void Manager::book_insert()
{
? ? int temp_book_id;
? ? string temp_book_name;
? ? show_book_base();
? ? //cout << "請輸入想增加的書籍編號:" << endl;
? ? cout << "書籍編號由系統(tǒng)自動生成!" << endl;
? ? temp_book_id = random_id();
? ? cout << "請輸入想增加的書籍名稱:" << endl;
? ? cin >> temp_book_name;
? ? cout << "請輸入書籍數(shù)量:" << endl;
? ? int temp_book_len; cin >> temp_book_len;
? ? cout << "請輸入書籍作者:" << endl;
? ? string temp_book_author; cin >> temp_book_author;
? ? cout << "請輸入書籍分類:" << endl;
? ? string temp_book_type; cin >> temp_book_type;
? ? cout << "請輸入書籍簡介:" << endl;
? ? string temp_book_present; cin >> temp_book_present;
? ? book[book_len].set_book_information(temp_book_id, temp_book_name, temp_book_len, temp_book_author, temp_book_type);
? ? book[book_len].set_book_present(temp_book_present);
? ? book_len++;
? ? cout << "書籍信息添加成功!" << endl;
? ? sort(book, book + book_len, book_cmp);
? ? system("pause");
? ? system("cls");
}
void Manager::book_delete()
{
? ? int temp_book_id;
? ? show_book_base();
? ? cout << "請輸入想刪除的書籍id號:" << endl;
? ? cin >> temp_book_id;
? ? if (book_id_exist(temp_book_id) == -1)
? ? {
? ? ? ? cout << "該書籍不存在!" << endl;
? ? }
? ? else
? ? {
? ? ? ? for (int i = 0; i < book_len - 1; i++)
? ? ? ? {
? ? ? ? ? ? book[i] = book[i + 1];
? ? ? ? }
? ? ? ? book_len--;
? ? ? ? cout << "書籍信息刪除成功!" << endl;
? ? }
? ? system("pause");
? ? system("cls");
}
void Manager::book_update()
{
? ? show_book_base();
? ? cout << "請輸入想修改的書籍編號:" << endl;
? ? int temp_book_id; ?cin >> temp_book_id;
? ? cout << "請選擇你要修改的書籍信息" << endl;
? ? cout << "1--修改書籍名稱" << endl;
? ? cout << "2--修改書籍總數(shù)" << endl;
? ? cout << "3--修改書籍作者" << endl;
? ? cout << "4--修改書籍分類" << endl;
? ? cout << "5--修改書籍簡介" << endl;
? ? cout << "0--返回菜單" << endl;
? ? int choice = 0; cin >> choice;
? ? switch (choice)
? ? {
? ? case 0: break;
? ? case 1:
? ? {
? ? ? ? cout << "請輸入書籍名稱:" << endl;
? ? ? ? string temp_book_name; cin >> temp_book_name;
? ? ? ? book[book_len].set_book_name(temp_book_name);
? ? ? ? cout << "修改成功\n";
? ? ? ? break;
? ? }
? ? case 2:
? ? {
? ? ? ? cout << "請輸入書籍總數(shù):" << endl;
? ? ? ? int temp_book_len; cin >> temp_book_len;
? ? ? ? book[book_len].set_book_total_num(temp_book_len);
? ? ? ? break;
? ? }
? ? case 3:
? ? {
? ? ? ? cout << "請輸入書籍作者:" << endl;
? ? ? ? string temp_book_author; cin >> temp_book_author;
? ? ? ? book[book_len].set_book_author(temp_book_author);
? ? ? ? break;
? ? }
? ? case 4:
? ? {
? ? ? ? cout << "請輸入書籍分類:" << endl;
? ? ? ? int temp_book_type; cin >> temp_book_type;
? ? ? ? book[book_len].book_type = temp_book_type;
? ? ? ? break;
? ? }case 5:
? ? {
? ? ? ? cout << "請輸入書籍簡介:" << endl;
? ? ? ? string temp_book_present; cin >> temp_book_present;
? ? ? ? book[book_len].book_present = temp_book_present;
? ? ? ? break;
? ? }
? ? default:
? ? {
? ? ? ? cout << "沒有該選項!" << endl; break;
? ? }
? ? }
? ? system("pause");
? ? system("cls");
?
}
void Manager::book_view()
{
? ? if (book_len == 0)
? ? {
? ? ? ? cout << "無借閱信息!" << endl;
? ? }
? ? for (int i = 0; i < book_len; i++)
? ? {
? ? ? ? cout << "書籍id號:" << book[i].book_id << "\t書籍名:" << book[i].book_name
? ? ? ? ? ? << "\t作者:" << book[i].book_author
? ? ? ? ? ? << "\t書籍剩余數(shù):" << (book[i].book_total_num - book[i].book_student_len)
? ? ? ? ? ? << "\t書籍總數(shù):" << book[i].book_total_num << endl;
? ? ? ? if (book[i].book_student_len == 0)
? ? ? ? {
? ? ? ? ? ? cout << "\t\t空!" << endl;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? cout << "學(xué)號\t\t" << "姓名" << endl;
? ? ? ? ? ? for (int j = 0; j < book[i].book_student_len; j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << book[j].book_id << "\t" << book[j].book_name << endl;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? cout << endl;
? ? }
? ? cout << "\t如果您需要查詢書籍詳細信息,請輸入1;不需要則輸入0\n";
? ? int ch = 0; cin >> ch;
? ? if (ch==1)
? ? ? ? book_find();
? ? system("pause");
? ? system("cls");
}
void Manager::class_insert()
{
? ? int temp_id;
? ? string temp_name;
? ? cout << "請輸入想增加的班級編號:" << endl;
? ? cin >> temp_id;
? ? clazz[class_len].set_class_id(temp_id);
? ? cout << "請輸入想增加的班級名稱:" << endl;
? ? cin >> temp_name;
? ? clazz[class_len].set_class_name(temp_name);
? ? cout << "請輸入想增加的班主任姓名:" << endl;
? ? string temp_teacher_name; cin >> temp_teacher_name;
? ? clazz[class_len].set_teacher_name(temp_teacher_name);
? ? class_len++;
? ? cout << "班級信息添加成功!" << endl;
? ? sort(clazz, clazz + class_len, class_cmp);
? ? system("pause");
? ? system("cls");
}
void Manager::class_delete()
{
? ? int temp_book_id;
? ? cout << "班級編號\t\t\t班級名稱\n";
? ? for (int i = 0; i < book_len; i++)
? ? ? ? cout << clazz[i].get_class_id()<< "\t\t" << clazz[i].get_class_name () << endl;
? ? cout << "請輸入想刪除的班級編號:" << endl;
? ? cin >> temp_book_id;
? ? if (class_id_exist(temp_book_id) == -1)
? ? {
? ? ? ? cout << "該班級不存在!" << endl;
? ? }
? ? else
? ? {
? ? ? ? for (int i = 0; i < class_len - 1; i++)
? ? ? ? {
? ? ? ? ? ? clazz[i] = clazz[i + 1];
? ? ? ? }
? ? ? ? class_len--;
? ? ? ? cout << "班級信息刪除成功!" << endl;
? ? }
? ? system("pause");
? ? system("cls");
}
void Manager::class_update()
{
? ? class_view();
? ? cout << "請輸入想修改的班級編號:" << endl;
? ? int temp_book_id; ?cin >> temp_book_id;
? ? cout << "請選擇你要修改的班級信息" << endl;
? ? cout << "1--修改班級名稱" << endl;
? ? cout << "2--修改班主任姓名" << endl;
? ? cout << "0--返回菜單" << endl;
? ? int choice = 0; cin >> choice;
? ? switch (choice)
? ? {
? ? case 0: break;
? ? case 1:
? ? {
? ? ? ? cout << "請輸入班級名稱:" << endl;
? ? ? ? string temp_name; cin >> temp_name;
? ? ? ? clazz[class_len].set_class_name(temp_name);
? ? ? ? cout << "修改成功\n";
? ? ? ? break;
? ? }
? ? case 2:
? ? {
? ? ? ? cout << "請輸入班主任名稱:" << endl;
? ? ? ? string temp_teacher_name; cin >> temp_teacher_name;
? ? ? ? clazz[class_len].set_teacher_name(temp_teacher_name);
? ? ? ? cout << "修改成功\n";
? ? ? ? break;
? ? }
? ? default:
? ? {
? ? ? ? cout << "沒有該選項!" << endl; break;
? ? }
? ? }
? ? system("pause");
? ? system("cls");
?
}
void Manager::class_view()
{
? ? if (class_len == 0)
? ? {
? ? ? ? cout << "無班級信息!" << endl;
? ? }
? ? else
? ? {
? ? ? ? cout << "\t\t班級信息如下" << endl;
? ? ? ? cout << "班級編號\t\t班級名稱\t\t班主任姓名" << endl;
? ? ? ? for (int i = 0; i < class_len; i++)
? ? ? ? ? ? cout << clazz[i].get_class_id() << setw(32) << clazz[i].get_class_name() << setw(26) << clazz[i].get_teacher_name() << endl;
? ? }
? ? system("pause");
? ? system("cls");
}
void Manager::manager_insert()
{
? ? if (this->mark == 0)
? ? {
? ? ? ? cout << "\t\t權(quán)限不足!" << endl;
? ? }
? ? else
? ? {
? ? ? ? cout << "請輸入賬號:" << endl;
? ? ? ? int temp_id; cin >> temp_id;
? ? ? ? cout << "請輸入姓名:" << endl;
? ? ? ? string temp_name; cin >> temp_name;
? ? ? ? cout << "請輸入權(quán)限:" << endl;
? ? ? ? cout << "1.普通管理員權(quán)限" << endl;
? ? ? ? cout << "2.高級管理員權(quán)限" << endl;
? ? ? ? int temp_mark; cin >> temp_mark;
? ? ? ? cout << "密碼默認為賬號!" << endl;
? ? ? ? string temp_password;
? ? ? ? stringstream transform;
? ? ? ? transform << temp_id; transform >> temp_password;
? ? ? ? Manager temp(temp_id, temp_mark, temp_name, temp_password);
? ? ? ? manager[manager_len] = temp;
? ? ? ? manager_len++;
? ? }
? ? system("pause");
? ? system("cls");
}
?
Student Student::operator = (const Student& p)
{
? ? this->id = p.id;
? ? this->name = p.name;
? ? this->student_gender = p.student_gender;
? ? this->student_grade = p.student_grade;
? ? this->class_id = p.class_id;
? ? this->student_book_len = p.student_book_len;
? ? this->password = p.password;
? ? return *this;
}
void Student::book_insert()
{
? ? cout << "可選書籍如下:" << endl;
? ? show_book_base();
? ? int temp_book_id;
? ? cout << "請輸入你要借閱的書籍編號:" << endl;
? ? cin >> temp_book_id;
? ? int position = book_id_exist(temp_book_id);
? ? int count = book[position].book_student_len;
? ? if (position == -1)
? ? {
? ? ? ? cout << "該書籍不存在!" << endl;
? ? }
? ? else
? ? {
? ? ? ? book[position].student_id[count] = this->id;
? ? ? ? book[position].student_name[count] = this->name;
? ? ? ? book[position].book_student_len++;
? ? ? ? student_book_len++;
? ? ? ? cout << "借閱成功!" << endl;
? ? }
? ? system("pause");
? ? system("cls");
}
void Student::student_information_view()
{
? ? cout << "\t\t請輸入查詢賬號:" << endl;
? ? int id; cin >> id;
? ? int pos =student_id_exist(id);
? ? if (pos != student_id_exist(id))
? ? {
? ? ? ? cout << "\t\t您無查看他人賬號權(quán)限!" << endl;
? ? }
? ? else
? ? {
? ? ? ? show_self();
? ? }
? ? system("pause");
? ? system("cls");
}
void Student::student_information_update()
{
? ? cout << "請選擇你要更改的信息:\n";
? ? cout << "1.修改性別\n";
? ? cout << "2.修改年級\n";
? ? cout << "3.修改班級\n";
? ? int choice; cin >> choice;
? ? if (choice == 1)
? ? {
? ? ? ? cout << "1.男\(zhòng)n2.女\n";
? ? ? ? int select; cin >> select;
? ? ? ? if (select == 1)
? ? ? ? {
? ? ? ? ? ? this->student_gender = "男";
? ? ? ? ? ? cout << "修改成功!\n";
? ? ? ? }
? ? ? ? else if (select == 1)
? ? ? ? {
? ? ? ? ? ? this->student_gender = "女";
? ? ? ? ? ? cout << "修改成功!\n";
? ? ? ? }
? ? ? ? else
? ? ? ? ? ? cout << "沒有該選項!\n";
? ? }
? ? else if (choice == 2)
? ? {
? ? ? ? cout << "1.2018\n2.2019\n3.2020\n4.2021\n";
? ? ? ? int select; cin >> select;
? ? ? ? if (select == 1)
? ? ? ? {
? ? ? ? ? ? this->student_grade = 2018;
? ? ? ? ? ? cout << "修改成功!\n";
? ? ? ? }
? ? ? ? else if (select == 2)
? ? ? ? {
? ? ? ? ? ? this->student_grade = 2019;
? ? ? ? ? ? cout << "修改成功!\n";
? ? ? ? }
? ? ? ? else if (select == 3)
? ? ? ? {
? ? ? ? ? ? this->student_grade = 2020; cout << "修改成功!\n";
? ? ? ? }
? ? ? ? else if (select == 4)
? ? ? ? {
? ? ? ? ? ? this->student_grade = 2021; cout << "修改成功!\n";
? ? ? ? }
? ? ? ? else
? ? ? ? ? ? cout << "沒有該選項!\n";
? ? }
? ? else if(choice == 3)
? ? {
? ? ? ? cout << "\t\t班級信息如下" << endl;
? ? ? ? cout << "班級編號\t\t班級名稱\t\t班主任姓名" << endl;
? ? ? ? for (int i = 0; i < class_len; i++)
? ? ? ? ? ? cout << clazz[i].get_class_id() << "\t\t" << clazz[i].get_class_name() << "\t\t" << clazz[i].get_teacher_name() << endl;
? ? ? ? while (1)
? ? ? ? {
? ? ? ? ? ? cout << "\t\t請輸入你選擇的班級編號\n" << endl;
? ? ? ? ? ? int select; cin >> select;
? ? ? ? ? ? if (class_id_exist(select) != -1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int temp_id; cin >> temp_id;
? ? ? ? ? ? ? ? this->class_id = temp_id;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "\t\t該班級編號不存在!\n";
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? else
? ? {
? ? ? ? cout << "該選項不存在!\n";
? ? }
? ? system("pause");
? ? system("cls");
}
void Student::book_delete()
{
? ? cout << "您的已選書籍如下:" << endl;
? ? if (student_book_len == 0)
? ? {
? ? ? ? cout << "空!" << endl;
? ? }
? ? else
? ? {
? ? ? ? cout << "序號\t\t書籍名稱\t\t書籍編號" << endl;;
? ? ? ? for (int i = 0; i < book_len; i++)
? ? ? ? {
? ? ? ? ? ? for (int j = 0; j < book[i].book_student_len; j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (book[i].student_id[j] == this->id)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cout << i + 1 << "\t\t" << book[i].book_name << "\t\t\t" << book[i].book_id << endl;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? cout << endl << "請輸入您想退還的書籍編號:" << endl;
? ? int temp_book_id; ?cin >> temp_book_id;
? ? int book_position = book_id_exist(temp_book_id);
? ? if (book_position == -1)
? ? {
? ? ? ? cout << "該書籍不存在!" << endl;
? ? }
? ? else
? ? {
? ? ? ? int student_position = -1;
? ? ? ? for (int i = 0; i < book[book_position].book_student_len; i++)
? ? ? ? {
? ? ? ? ? ? if (book[book_position].student_id[i] == id)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? student_position = i;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if (student_position != -1)
? ? ? ? {
? ? ? ? ? ? for (int i = student_position; i < book[book_position].book_student_len - 1; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? book[book_position].student_id[i] = book[book_position].student_id[i + 1];
? ? ? ? ? ? ? ? book[book_position].student_name[i] = book[book_position].student_name[i + 1];
? ? ? ? ? ? }
? ? ? ? ? ? book[book_position].book_student_len--;
? ? ? ? ? ? student_book_len--;
? ? ? ? ? ? cout << "書籍歸還成功!" << endl;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? cout << "你并未借閱過該書籍!" << endl;
? ? ? ? }
? ? }
? ? system("pause");
? ? system("cls");
}
void Student::show_self()
{
? ? cout << "\t\t賬號信息如下:" << endl;
? ? cout << "______________________________________________________________________________\n";
? ? cout << " 姓名:" << this->name << "\t\t 學(xué)號:" << this->id << "\n";
? ? cout << "______________________________________________________________________________\n";
? ? cout << " 性別:" << this->student_gender << "\t\t 班級編號:" << this->class_id << "\n";
? ? cout << "______________________________________________________________________________\n";
? ? cout << " 書籍編號" << "\t\t書籍名稱" << "\n";
? ? cout << "______________________________________________________________________________\n";
? ? if (this->student_book_len == 0)
? ? {
? ? ? ? cout << "\t\t暫未借閱書籍" << "\n";
? ? }
? ? else
? ? {
? ? ? ? for (int i = 0; i < book_len; i++)
? ? ? ? {
? ? ? ? ? ? for (int j = 0; j < book[i].book_student_len; j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (book[i].student_id[j] == this->id)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cout << "\t\t" << book[i].book_id
? ? ? ? ? ? ? ? ? ? ? ? << "\t\t" << book[i].book_name << "\n";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? cout << "______________________________________________________________________________\n";
}
void book_find()
{
? ? cout << "請輸入你要查找的書籍編號:" << endl;
? ? int temp_book_id; cin >> temp_book_id;
? ? int position = book_id_exist(temp_book_id);
? ? if (position == -1)
? ? {
? ? ? ? cout << "該書籍編號不存在!查找失敗!" << endl;
? ? }
? ? else
? ? {
? ? ? ? book[position].show_book_information();
? ? }
? ? system("pause");
? ? system("cls");
}
void show_book_base()
{
? ? cout << "書籍id號:\t" << "書籍名稱:" << endl;
? ? for (int i = 0; i < book_len; i++)
? ? {
? ? ? ? cout << book[i].book_id << "\t\t" << book[i].book_name << endl;
? ? }
}
int student_id_exist(int id)//二分查找
{
? ? int left = 0;
? ? int right = student_len;
? ? int mid = 0;
? ? while (left < right)
? ? {
? ? ? ? mid = (left + right) / 2;
? ? ? ? if (id == student[mid].get_id())
? ? ? ? ? ? return mid;
? ? ? ? if (id > student[mid].get_id())
? ? ? ? ? ? left = mid + 1;
? ? ? ? else if (id < student[mid].get_id())
? ? ? ? ? ? right = mid;
? ? }
? ? return -1;
}
int manager_id_exist(int id)
{
? ? for (int i = 0; i < manager_len; i++)
? ? {
? ? ? ? if (manager[i].get_id() == id)
? ? ? ? {
? ? ? ? ? ? return i;
? ? ? ? }
? ? }
? ? return -1;
}
int book_id_exist(int id)
{
? ? int left = 0;
? ? int right = book_len;
? ? int mid = 0;
? ? while (left < right)
? ? {
? ? ? ? mid = (left + right) / 2;
? ? ? ? if (id == book[mid].get_book_id())
? ? ? ? ? ? return mid;
? ? ? ? if (id > book[mid].get_book_id())
? ? ? ? ? ? left = mid + 1;
? ? ? ? else if (id < book[mid].get_book_id())
? ? ? ? ? ? right = mid;
? ? }
? ? return -1;
}
int class_id_exist(int id)
{
? ? int left = 0;
? ? int right = class_len;
? ? int mid = 0;
? ? while (left < right)
? ? {
? ? ? ? mid = (left + right) / 2;
? ? ? ? if (id == clazz[mid].get_class_id())
? ? ? ? ? ? return mid;
? ? ? ? if (id > clazz[mid].get_class_id())
? ? ? ? ? ? left = mid + 1;
? ? ? ? else if (id < clazz[mid].get_class_id())
? ? ? ? ? ? right = mid;
? ? }
? ? return -1;
}
bool student_cmp(Student a, Student b)
{
? ? return ?a.id < b.id;
}
bool class_cmp(Clazz a, Clazz b)
{
? ? return a.get_class_id() < b.get_class_id();
}
bool book_cmp(Book a, Book b)
{
? ? return a.get_book_id() < b.get_book_id();
}
void existSystem()
{
? ? cout << "歡迎下次使用" << endl;
? ? system("pause");
? ? exit(0);
}
int random_id() //產(chǎn)生隨機書籍編號
{
? ? int id;
? ? for (int i = 0; i < 8; i++)
? ? {
? ? ? ? id = rand();
? ? }
? ? return id;
}
string input_password()
{
? ? char temp_password[20];
? ? int len = 0; char key;
? ? while ((key = _getch()) != '\r')//不可見輸入
? ? {
? ? ? ? if (len < 12)
? ? ? ? {
? ? ? ? ? ? temp_password[len++] = key;
? ? ? ? ? ? putchar('*');
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? cout << endl << endl;;
? ? ? ? ? ? cout << "\t ?密碼過長" << endl;
? ? ? ? }
? ? }
? ? temp_password[len] = '\0';//字符串結(jié)束標記:\0;
? ? cout << endl;
? ? return temp_password;
}
void load_information()
{
? ? ifstream fin;
? ? fin.open(BOOK_FILE, ios::in);
? ? if (fin.is_open() == false)
? ? {
? ? ? ? cout << "文件打開失敗!" << endl;
? ? }
? ? fin >> book_len;
?
? ? for (int i = 0; i < book_len; i++)
? ? {
? ? ? ??
? ? ? ? fin >> book[i].book_id >> book[i].book_name >> book[i].book_total_num
? ? ? ? ? ? >> book[i].book_student_len >> book[i].book_author >> book[i].book_type
? ? ? ? ? ? >> book[i].book_present;
? ? }
? ? fin.close();
?
?
? ? fin.open(CLASS_FILE, ios::in);
? ? if (fin.is_open() == false)
? ? {
? ? ? ? cout << "文件打開失敗!" << endl;
? ? }
? ? fin >> class_len;
?
? ? for (int i = 0; i < class_len; i++)
? ? {
? ? ? ? fin >> clazz[i].class_id >> clazz[i].class_name >> clazz[i].teacher_name;
? ? }
? ? fin.close();
?
? ? fin.open(STUDENT_FILE, ios::in);
? ? if (fin.is_open() == false)
? ? {
? ? ? ? cout << "文件打開失??!" << endl;
? ? }
? ? fin >> student_len;
?
? ? for (int i = 0; i < student_len; i++)
? ? {
? ? ? ? fin >> student[i].id >> student[i].name >> student[i].mark>>student[i].student_grade>> student[i].class_id?
? ? ? ? ? ? >> student[i].student_gender >> student[i].password >> student[i].student_book_len;
? ? }
? ? fin.close();
? ? sort(book, book + book_len, book_cmp);
? ? sort(clazz, clazz + class_len, class_cmp);
? ? sort(student, student + student_len, student_cmp);
}
void update_information()
{
? ? ofstream fou;
? ? fou.open(BOOK_FILE, ios::out);
? ? if (fou.is_open() == false)
? ? {
? ? ? ? cout << "文件打開失??!" << endl;
? ? }
? ? fou << book_len << endl;
? ? for (int i = 0; i < book_len; i++)
? ? {
? ? ? ? fou << book[i].book_id << " " << book[i].book_name << " " << book[i].book_total_num << " " << book[i].book_student_len
? ? ? ? ? ? << " " << book[i].book_author << " " << book[i].book_type << " " << book[i].book_present << endl;
? ? }
? ? fou.close();
?
? ? fou.open(CLASS_FILE, ios::out);
? ? if (fou.is_open() == false)
? ? {
? ? ? ? cout << "文件打開失??!" << endl;
? ? }
? ? fou << class_len << endl;
? ? for (int i = 0; i < class_len; i++)
? ? {
? ? ? ? fou << clazz[i].class_id <<" "<< clazz[i].class_name <<" "<< clazz[i].teacher_name << endl;
? ? }
? ? fou.close();
?
? ? fou.open(STUDENT_FILE, ios::out);
? ? if (fou.is_open() == false)
? ? {
? ? ? ? cout << "文件打開失敗!" << endl;
? ? }
? ? fou << student_len << endl;
? ? for (int i = 0; i < student_len; i++)
? ? {
? ? ? ? fou << student[i].id << " " << student[i].name << " " << student[i].mark<<" "<<student[i].student_grade<<" "<<student[i].class_id
? ? ? ? ? ? << " " << student[i].student_gender << " " << student[i].password << " " << student[i].student_book_len << endl;
? ? }
? ? fou.close();
}

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

相關(guān)文章

  • C語言實現(xiàn)學(xué)生宿舍信息管理系統(tǒng)課程設(shè)計

    C語言實現(xiàn)學(xué)生宿舍信息管理系統(tǒng)課程設(shè)計

    這篇文章主要為大家詳細介紹了C語言實現(xiàn)學(xué)生宿舍信息管理系統(tǒng)課程設(shè)計,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • C語言面試C++二維數(shù)組中的查找示例

    C語言面試C++二維數(shù)組中的查找示例

    這篇文章主要介紹了C語言面試C++二維數(shù)組中的查找示例,文中給出基本能拿下面試官的操作示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2021-09-09
  • C++ 中try finally關(guān)鍵字詳解

    C++ 中try finally關(guān)鍵字詳解

    本文給大家介紹C++ 中try finally關(guān)鍵字的相關(guān)知識,非常不錯,本文介紹的非常詳細,具有參考借鑒價值,感興趣的朋友一起學(xué)習吧
    2016-05-05
  • OpenCV畫任意圓弧曲線

    OpenCV畫任意圓弧曲線

    這篇文章主要為大家詳細介紹了OpenCV畫任意圓弧曲線,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • 深入聊聊C語言中的Const關(guān)鍵字

    深入聊聊C語言中的Const關(guān)鍵字

    關(guān)鍵字const用來定義只讀變量,被const定義的變量它的值是不允許改變的,即不允許給它重新賦值,即使是賦相同的值也不可以,下面這篇文章主要給大家介紹了關(guān)于C語言中Const關(guān)鍵字的相關(guān)資料,需要的朋友可以參考下
    2022-02-02
  • C語言自動生成enum值和名字映射代碼

    C語言自動生成enum值和名字映射代碼

    這篇文章主要介紹了C語言自動生成enum值和名字映射代碼的相關(guān)資料,需要的朋友可以參考下
    2015-12-12
  • C++中發(fā)聲函數(shù)Beep用法

    C++中發(fā)聲函數(shù)Beep用法

    本文給大家分享的是Beep函數(shù)的用法以及會使揚聲器發(fā)出簡單的聲音的示例,有需要的小伙伴可以參考下
    2017-05-05
  • C++之vector內(nèi)存釋放原理

    C++之vector內(nèi)存釋放原理

    這篇文章主要介紹了C++之vector內(nèi)存釋放原理,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • c++11 新特性——智能指針使用詳解

    c++11 新特性——智能指針使用詳解

    這篇文章主要介紹了c++11 新特性——智能指針使用的相關(guān)資料,幫助大家更好的理解和使用c++,感興趣的朋友可以了解下
    2021-02-02
  • 北郵計算機考研復(fù)試題的C語言解答精選

    北郵計算機考研復(fù)試題的C語言解答精選

    這篇文章主要介紹了北郵計算機考研復(fù)試題目的C語言解答精選,選自2012年的一些基礎(chǔ)的上機題目,需要的朋友可以參考下
    2015-08-08

最新評論