2019年11月

We can get paint and dyes from pigment, but Nobel believes he can made it into explosive. Though his parents didn't know what came over to him, they are supportive to him. Every time he don't eat anymore, they help him dispose of the food.

One day, when he mixed the chemicals in two flasks, the house vanished. He was so excited because it substantiated his idea. His parent suppressed their sadness and said "you are so~ good".

After the invention, he made an itinerary of Europe to tell others about it. And now it's prevalent to respect Nobel as a great scientist.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#define M 16        //M name_length
#define N 12        //N no_length
#define K 3            //K score_length

using namespace std;

class Student
{
    char num[N], name[M];
    int score[K];
    double gpa[K], agpa;
public:
    //there neednt be a constructor
    void setnum(char nu[]);        //set...
    void setname(char na[]);
    void setscore(int sc[]);
    void setgpa(double g[]);
    void setagpa(double ag);
    void computegpa();
    void computeagpa();

    char *getnum();            //get...
    char *getname();
    void getscore(int sc[]);
    void getgpa(double g[]);
    void getagpa(double &ag);

    void disp();        //display...
};

class UserDatabase
{
    int nElem, Maxu;
    Student *user;
public:
    UserDatabase(int n=30);
    ~UserDatabase();
    void add_record(char *nu,char *na, int sc[]);    //add record
    void modify_record(Student *p, int sc[]);        //modify record
    void delete_record(Student *p);                //delete record 不知道书上的第二个参数是干什么用的        
    int query(char *nu);                        //我这里把返回值改成了int,如果存在的话,返回下标,不存在的话返回-1,感觉这样比较简单
    Student *getStudent(int i);            //这个函数是我新加的用来解决上面那个函数修改的问题

    void sorta_num();        //sort by num ascend
    void sorta_name();        //name asc
    void sorta_agpa();        //agpa asc
    void sort_num();        //num descend
    void sort_name();        //name desc
    void sort_agpa();        //agpa desc

    void disp();    //display record
    void clear();    //delete all
};

void Student::setnum(char nu[])
{
    strcpy(num, nu);
}    
void Student::setname(char na[])
{
    strcpy(name, na);
}
void Student::setscore(int sc[])
{
    for (int i=0; i<K; i++)
        score[i] = sc[i];
}
void Student::setgpa(double g[])
{
    for (int i=0; i<K; i++)
        gpa[i] = g[i];
}
void Student::setagpa(double ag)
{
    agpa = ag;
}
void Student::computegpa()
{
    for (int i=0; i<K; i++)
        if (score[i]<60) gpa[i] = 0;
        else gpa[i] = score[i]/10.0-5;
}
void Student::computeagpa()
{
    double sum=0;
    for (int i=0; i<K; i++) sum += gpa[i];
    agpa = sum/K;
}
char *Student::getnum()
{
    return num;
}
char *Student::getname()
{
    return name;
}
void Student::getscore(int sc[])
{
    for (int i=0; i<K; i++)
        sc[i] = score[i];
}
void Student::getgpa(double g[])
{
    for (int i=0; i<K; i++)
        g[i] = gpa[i];
}
void Student::getagpa(double &ag)
{
    ag = agpa;
}
void Student::disp()
{
    int i;
    cout << setw(N-5) << left << num << setw(M-5) << left << name;
    for (i=0; i<K; i++)
        cout << setw(7) << left << score[i];
    for (i=0; i<K; i++)
        cout << setw(8) << left << fixed << setprecision(1) << gpa[i];
    cout << left << agpa << endl;
    cout.unsetf(ios::fixed);
}
UserDatabase::UserDatabase(int n)
{
    char nu[N], na[M];
    int sc[K], i;
    double g[K], ag;

    ifstream infile;
    infile.open("user.txt");
    if    (!infile)
    {
        cout << "user.txt文件不存在" << endl;
        exit(0);
    }
    nElem = 0;
    Maxu = n;
    if (n)
        user = new Student[n];
    else
        user = NULL;
    while (infile >> nu)
    {
        infile >> na;
        for (i=0; i<K; i++)
            infile >> sc[i];
        for (i=0; i<K; i++)
            infile >> g[i];
        infile >> ag;
        add_record(nu, na, sc);
    }
        infile.close();
}
UserDatabase::~UserDatabase()
{
    int i, j, sc[K];
    char nu[N], na[M];
    double g[K], ag;
    ofstream outfile;
    outfile.open("user.txt");
    for (i=0; i<nElem; i++)
    {
        strcpy(nu,user[i].getnum());
        strcpy(na,user[i].getname());
        user[i].getscore(sc);
        user[i].getgpa(g);
        user[i].getagpa(ag);
        outfile << nu << '\t' << na << '\t';
        for (j=0; j<K; j++)
            outfile << sc[j] << '\t';
        for (j=0; j<K; j++)
            outfile << g[j] << '\t';
        outfile << '\t' << ag << endl;
    }
    outfile.close();
}
void UserDatabase::add_record(char *nu,char *na, int sc[])
{
    int j;
    if (nElem == Maxu)
    {
        Student *newptr = new Student[Maxu +10];
        for(int i=0; i<nElem; i++)
            newptr[i] = user[i];
        delete []user;
        Maxu +=10;
        user = newptr;
    }
    for (j=nElem-1; j>=0&&(strcmp(user[j].getnum(),nu)==1); j--)
            user[j+1] = user[j];
    user[j+1].setnum(nu);
    user[j+1].setname(na);
    user[j+1].setscore(sc);
    user[j+1].computegpa();
    user[j+1].computeagpa();
    nElem++;
}
void UserDatabase::modify_record(Student *p, int sc[])
{
    p->setscore(sc);
    p->computegpa();
    p->computeagpa();
}
void UserDatabase::delete_record(Student *p)
{
    for (nElem--; p<user+nElem; p++)
        *p = *(p+1);
}
int UserDatabase::query(char *nu)
{
    for (int i=0; i<nElem; i++)
        if (strcmp(user[i].getnum(),nu)==0)
            return i;
    return -1;
}
Student *UserDatabase::getStudent(int i)
{
    return (user+i);
}
void UserDatabase::sorta_num()
{
    int min;
    Student temp;
    for (int i=0; i<nElem-1; i++)
    {
        min = i;
        for (int j=i+1; j<nElem; j++)
            if(strcmp(user[min].getnum(),user[j].getnum())==1)
                min = j;
        if (min!=i)
        {
            temp = user[min];
            user[min] = user[i];
            user[i] = temp;
        }
    }
}
void UserDatabase::sorta_name()
{
    int i, j;
    Student p;
    for (i=1; i<nElem; i++)
    {
        p = user[i];
        for (j=i-1; j>=0&&(strcmp(user[j].getname(),p.getname())==1); j--)
            user[j+1] = user[j];
        user[j+1] = p;
    }
}
void UserDatabase::sorta_agpa()
{
    double agpa1, agpa2;
    Student temp;
    for (int i=1; i<nElem; i++)
        for (int j=0; j<nElem-i; j++)
        {
            user[j].getagpa(agpa1);
            user[j+1].getagpa(agpa2);
            if (agpa1>agpa2)
            {
                temp = user[j];
                user[j] = user[j+1];
                user[j+1] = temp;
            }
        }    
}
void UserDatabase::sort_num()
{
    int max;
    Student temp;
    for (int i=0; i<nElem-1; i++)
    {
        max = i;
        for (int j=i+1; j<nElem; j++)
            if(strcmp(user[max].getnum(),user[j].getnum())==-1)
                max = j;
        if (max!=i)
        {
            temp = user[max];
            user[max] = user[i];
            user[i] = temp;
        }
    }
}
void UserDatabase::sort_name()
{
    Student temp;
    sorta_name();
    for (int i=0; i<nElem-i-1; i++)
    {
        temp = user[i];
        user[i] = user[nElem-i-1];
        user[nElem-i-1] = temp;
    }
}
void UserDatabase::sort_agpa()
{
    double agpa1, agpa2;
    Student temp;
    for (int i=1; i<nElem; i++)
        for (int j=0; j<nElem-i; j++)
        {
            user[j].getagpa(agpa1);
            user[j+1].getagpa(agpa2);
            if (agpa1<agpa2)
            {
                temp = user[j];
                user[j] = user[j+1];
                user[j+1] = temp;
            }
        }    
}
void show_head(int);        //声明一下这个函数
void UserDatabase::disp()
{
    int i, j;
    for (i=0; i<nElem; i++)
    {
        if (i%10==0)
        {
            if(i) system("pause");
            show_head(6);
            
            cout << setw(N-5) << left << "学号" << setw(M-5) << left << "姓名";
            cout << "成绩1  ";
            cout << "成绩2  ";
            cout << "成绩3  ";
            cout << "绩点1   ";
            cout << "绩点2   ";
            cout << "绩点3  ";
            cout << "平均绩点";
            cout << endl;
        }
        user[i].disp();
    }
        
}
void UserDatabase::clear()
{
    nElem = 0;
}

void show_head(int i)
{
    system("cls");
    cout << "=======================================================================" << endl;
    cout << "                             ";
    switch (i)
    {
        case 1:    cout << "增加记录" << endl;        break;
        case 2: cout << "修改记录" << endl;        break;
        case 3: cout << "删除记录" << endl;        break;
        case 4: cout << "     查找" << endl;        break;
        case 5: cout << "     排序" << endl;        break;
        case 6: cout << "显示记录" << endl;    break;
        case 7: cout << "全删" << endl;        break;
        case 0: cout << "退出" << endl;        break;
        case 998: cout << "学生成绩管理系统" << endl; break;
    }
    cout << "=======================================================================" << endl;
}
int menu_select(bool flag=true)    //传的值是一个bool值,true用来显示主菜单,false 显示排序的菜单
{
    char *menu_main[]={
        "     1  -   增加记录",
        "     2  -   修改记录",
        "     3  -   删除记录",
        "     4  -   查找",
        "     5  -   排序",
        "     6  -   显示记录",
        "     7  -   全删",
        "     0  -   退出                    www.rvfu.me",
        NULL
    };
    char *menu_sort[]={
        "1 - 按学号(升序)",
        "2 - 按姓名(升序)",
        "3 - 按平均绩点(升序)",
        "4 - 按学号(降序)",
        "5 - 按姓名(降序)",
        "6 - 按平均绩点(降序)",
        NULL
    };
    int i, choice;
    do{
        system("cls");
        if (!flag)
            show_head(5);
        else show_head(998);
            if(flag)
                for (i=0; menu_main[i]; i++)
                    cout << "\t\t\t" << menu_main[i] << endl;
            else 
                for (i=0; menu_sort[i]; i++)
                    cout << "\t\t\t" << menu_sort[i] << endl;
                cout << "=======================================================================" << endl;
        cout << "输入选择: ";
        cin >> choice;
    }while(   ( flag&&(choice<0||choice>7) )  ||  ( !flag&&(choice<1||choice>6) )    );
    return choice;
}
void add_record(UserDatabase &usrdb)
{
    char num[N], name[M];
    int score[K];

    cout << "输入学号: ";
    cin >> num;
    if (usrdb.query(num)!=-1)
        cout << endl << "数据重复,插入失败" << endl << endl;
    else
    {
        cout << "输入姓名: ";
        cin >> name;
        cout << "输入成绩: ";
        for (int i=0; i<K; i++)
            cin >> score[i];
        usrdb.add_record(num,name,score);
        cout << endl << "插入成功" << endl << endl;
    }
}
void modify_record(UserDatabase &usrdb)
{
    Student *stuptr;
    char num[N];
    int score[K], i;
    cout << "输入学号: ";
    cin >> num;
    if ((i=usrdb.query(num))==-1)
        cout << endl << "数据不存在" << endl << endl;
    else
    {
        cout << endl << "原始记录: ";
        stuptr = usrdb.getStudent(i);
        stuptr->disp();
        cout << endl << "输入新成绩: ";
        for (int i=0; i<K; i++)
            cin >> score[i];
        usrdb.modify_record(stuptr,score);
        cout << endl << "修改成功" << endl << endl;
    }
}
void delete_record(UserDatabase &usrdb)
{
    Student *stuptr;
    char num[N], flag;
    int i;
    cout << "输入学号: ";
    cin >> num;
    if ((i=usrdb.query(num))==-1)
        cout << endl << "数据不存在" << endl << endl;
    else
    {
        cout << endl << "该条数据为: ";
        stuptr = usrdb.getStudent(i);
        stuptr->disp();
        cout << endl << "确认删除吗? y/n ";
        cin >> flag;
        if (flag=='y'|| flag=='Y')
        {
            usrdb.delete_record(stuptr);
            cout << endl <<"删除了该条数据" << endl << endl;
        }
        else
            cout << endl <<"取消了删除操作" << endl << endl;
    }
}
void query(UserDatabase &usrdb)
{
    Student *stuptr;
    char num[N];
    int i;
    cout << "输入学号: ";
    cin >> num;
    if ((i=usrdb.query(num))==-1)
        cout << endl << "数据不存在" << endl << endl;
    else
    {
        cout << endl << "该条数据为: ";
        stuptr = usrdb.getStudent(i);
        stuptr->disp();
        cout << endl;
    }
}
void sort(UserDatabase &usrdb)
{
    switch (menu_select(false))
    {
        case 1:usrdb.sorta_num();    break;
        case 2:usrdb.sorta_name();    break;
        case 3:usrdb.sorta_agpa();    break;
        case 4:usrdb.sort_num();    break;
        case 5:usrdb.sort_name();    break;
        case 6:usrdb.sort_agpa();    break;
    }
    cout << endl << ":)已经按指定要求排序" << endl << endl;
}
void disp(UserDatabase &usrdb)
{
    usrdb.disp();
}
void clear(UserDatabase &usrdb)
{
    char flag;
    cout << "确认删除吗? y/n ";
    cin >> flag;
    if (flag=='y'|| flag=='Y')
    {
        usrdb.clear();
        cout << endl << "完成操作" << endl << endl;
    }
    else
        cout << endl << "取消了操作" << endl << endl;
}
int main()
{
    UserDatabase usrdb;
    int select;
    char flag;

    while("欢迎大家来关注我的个人公众号瑞辅笔记,我的网站主页是suruifu.com")
    {
        switch(select=menu_select())
        {
            
            case 1: show_head(1);    add_record(usrdb);        system("pause"); break;
            case 2: show_head(2);    modify_record(usrdb);    system("pause"); break;
            case 3: show_head(3);    delete_record(usrdb);    system("pause"); break;
            case 4: show_head(4);    query(usrdb);            system("pause"); break;
            case 5:                    sort(usrdb);            system("pause"); break;
            case 6: show_head(6);    disp(usrdb);            system("pause"); break;
            case 7: show_head(7);    clear(usrdb);            system("pause"); break;
            case 0: show_head(0);    cout << "Are you sure ? y/n : ";
                    cin >> flag;
                    if (flag!='y'&& flag!='Y') continue;
        }
        if (select==0) break;
    }
    return 0;

昨天和大佬一起去看了Frozen 2,电影秋季配色很美,画面精致。看完电影后有些思考,下面涉及剧透。

关于音乐

我比较喜欢的Kristoff的Lost in the woods和Iduna的All is found。

  • Lost in the woods故意搞出了90年代经典歌曲mv的感觉,悄咪咪致敬了queen,听起来有westlife和take
    that的感觉,由于表演过于浮夸魔性,我在电影院笑出了声。
  • All is found是根据凯尔特民谣改编的摇篮曲,有淡淡的忧伤和漂泊的感觉,非常适合薄雾或飘雨的灰黄色秋天。

关于主题

我很喜欢的一个概念是water has memory。魔力之源的阿塔霍兰是一座冰川,这块冰承载着所有的历史,自然真正的魔法力量正是出自时间。就像我们的力量是由我们的过去经历赋予一样。

Frozen虽然把冰雪皇后的童话故事改得面目全非,但是在主题思想却传承了童话,是不断寻找并打开被冰封住的内心。第一部是Elsa从隐藏自我到自我释放,最终在妹妹的爱下开始自我接纳的过程,第二部则是Elsa重新发现自我价值,明确生命位置,找到归属感的过程。第一部是冰封住自己的所有想法最终自我和解,第二部是冰封住自己的真正理想到找到自己的归宿和想要的生活。

一些思考

历史并非表象,就像做科研一样。父母是真理道路上前仆后继的无畏先驱,Elsa是寻求真相不断探索的求知者,Anna是将想法付诸行动,改变现实的实践者。

Kristoff虽然话少却相当感人,当Anna遇到危险的时候,I am here,what do you need? my love is not fragile,整个人物一下就立起来了,虽然他一直被吐槽工具人,但是真爱如狗,在别人眼里的狗,在他自己眼里就是幸福和快乐,但是my love is not fragile还是太酷了!

不知道为什么Frozen 2总感觉像权力的游戏,冰川就像绿先知一样知道所有的过去,也因为时间和历史而产生力量;北方人就像自由民一样,追随自然;知道的历史并非表象,自然与社会的关系,在北欧到底流传着怎样的古老传说呢?

女权思想?

Elsa 最后选择离开了国家,和北方人一起生活在魔法森林中,看起来是一个不错的结局。可以说是她自己主动选择了这种回归自然的生活,但也可以说她是被彻底排挤出了原来的社会。在这个社会,人们对比自身强大的力量感到畏惧。当需要力量保护时,他们将力量奉为神灵降世;当不需要帮助时,他们就冷眼相待。

而这种冷眼相待就是福柯所谓的凝视,人在他人的凝视中凝视自己,正因如此Elsa才在影片开始的幸福生活中隐隐约约地感受到了自己的异类感和不安感,缺乏归属感,从而想去追寻呼唤自己的,仿佛是同类的声音。而Anna没有Elsa的力量,不会被那样凝视,所以她感到满足和幸福,可以在这里找到归宿。影评说,Elsa最终回归了生命和自然,这代表回归母系,追求多元平等共生,利益共同,相互促进。因为多元共生,人们不再要求标准化,所以就不会再有凝视,而是和森林精灵协作,所以Elsa找到了归属感。

而女王则代表了在父权社会的体制中,父权追求绝对控制和权力,是非你死即我亡的对立,因此,祖父才会因不了解北方人与森林精灵的关系,从而产生恐惧,想要灭异族。由Anna改变父权制追求绝对控制思想影响下的历史错误,从而更好地改变了父权社会的状态。让Elsa留在北方,让Anna成为女王,两姐妹各归其一,是对不同价值观的接受和认同,也象征着自然与社会要共生下去。

Olaf从始至终一直在探寻永恒,在成长过程中什么都在变,何物是永恒?现阶段的我认为是利益。利益的存在就会有自私行为,由于自身力量不够,人类就需要和他人合作,从而产生利他行为,从根本上讲,还是包裹着利他主义外壳的利己行为。在这一点上,女权更强调共存即合作,父权更强调占领资源从而更好利己。在我看来只是所站角度不同而已,因为在高贵的人本位下,只有人与人的平等,从来没有万物平等。

When Xia was a little boy, he was so vulnerable and his place was always in a jumble that nobody played with him.

One day after he saw the steam vanished in the air he find it amazing. After asking the teacher way, the teacher goaded him and he started his thought about scientific research. Several years later, he went to NUAA. NUAA is renowned for its canteen for its hygiene and yummy food.

When in his tenth year in NUAA, he got some money. It's so timely that with it Xia invented an AC which can boil water. Every time in his course, he starts with preaching his invention and then get down to business. For us, its just like a convention.

在南航四年的时间里面,有件事情是值得吹逼的,就是我的C++考了100分。在这里分享C++课程设计文件给大家,仅供大家参考。

点击这里下载课程设计报告

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <cstring>
using namespace std;

class Book
{
    char bookNo[20], bookName[20];
    int Num;
public:
    Book(char *nop =NULL, char *nap =NULL, int n =0)
    {
        if(nop)strcpy(bookNo, nop);
        if(nap)strcpy(bookName, nap);
        Num = n;
    }
    void Show()
    {
        cout << left << setw(20) << bookNo << left << setw(20) << bookName << left << setw(20) << Num << endl;
    }
    void Print(ofstream &out)
    {
        out << left << setw(20) << bookNo << left << setw(20) << bookName << left << setw(20) << Num << endl;
    }
    void setInfo(char *nop, char *nap, int n)
    {
        strcpy(bookNo, nop);
        strcpy(bookName, nap);
        Num = n;
    }
    void setNum(int n)
    {
        Num = n;
    }
    int getNum()
    {
        return Num;
    }
    friend class bookList;
};
class bookList
{
    Book *Books;
    int curLen, maxLen;
public:
    bookList(int len =20)
    {
        maxLen = len;
        curLen = 0;
        Books = new Book[maxLen];
    }
    ~bookList()
    {
        delete []Books;
    }
    void appendBook(char *nop, char *nap, int n)
    {
        if(curLen == maxLen)
        {
            Book *newBooks = new Book[maxLen+10];
            for(int i=0; i<curLen; i++)
                *(newBooks+i)=*(Books+i);        //简单的浅拷贝
            delete []Books;
            Books = newBooks;
            maxLen += 10;
        }
        getBooks(curLen++).setInfo(nop, nap, n);
    }
    int isIn(char *bkNo)
    {
        for (int i=0; i<curLen; i++)
        {
            if(strcmp(getBooks(i).bookNo,bkNo)==0) return i;
        }
        return -1;
    }
    Book & getBooks(int i)
    {
        return *(Books+i);
    }
    void deleteBook(char *bkNo)
    {
            for (int i=isIn(bkNo); i<curLen-1; i++)
             *(Books+i) = *(Books +i +1);    //curLen 控制长度,最后一个不用管,有新数据时会将其覆盖
            curLen--;
    }
    void sortBooks()
    {
        int min;
        Book temp;

        for (int i=0; i<curLen-1; i++)
        {
            min = i;
            for (int j=i+1; j<curLen; j++)
                if(strcmp(getBooks(min).bookNo, getBooks(j).bookNo)==1) min = j;
            if (min != i)
            {
                temp = getBooks(min);
                getBooks(min) = getBooks(i);
                getBooks(i) = temp;
            }
        }
        cout << "按书号的升序排列了图书" << endl;
    }
    void showAll()
    {
        for (int i =0; i<curLen; i++)
            getBooks(i).Show();
    }
    int curBookLen()
    {
        return curLen;
    }
    void setCurBookLen(int len)
    {
        curLen = len;
    }
    void initBookList()
    {
        readFromFile("bookdata.txt");
    }
    void readFromFile(char *filename)
    {
        int len;
        char bkNo[20],bkName[20];
        int Num;
        ifstream infile(filename);
        infile >> len;
        for (int i=0; i<len; i++)
        {
            infile >> bkNo >> bkName >> Num;
            appendBook(bkNo, bkName, Num);
        }
        infile.close();
        cout << "从文件插入了" << len << "条记录" << endl;
    }
    void writeToFile(char *filename)
    {
        ofstream outfile(filename);
        outfile << curLen << endl;
        for (int i=0; i<curLen; i++)
            getBooks(i).Print(outfile);
        outfile.close();
        cout << "向文件输出了" << curLen << "条记录" << endl;
    }
};
void appendRecord(bookList &booksObj)
{
    char bkNo[20], bkName[20];
    int Num;

    cout << "    请输入新增书籍的书号、书名和数量:  ";
    cin >> bkNo >> bkName >> Num;
    booksObj.appendBook(bkNo, bkName, Num);
}

void delRecord(bookList &booksObj)
{
    char bkNo[20];
    cout << "    请输入您要删除的书号:  ";
    cin >> bkNo;
    if (booksObj.isIn(bkNo) >-1) booksObj.deleteBook(bkNo);
    else cout << "您要删除的书不存在" << endl;
}

void showAll(bookList &booksObj)
{
    booksObj.showAll();
}

void query(bookList &booksObj)
{
    char bkNo[20];
    int i;

    cout << "请输入书号:  ";
    cin >> bkNo;
    if ((i=booksObj.isIn(bkNo))>-1)
    {
        cout << "该书为";
        booksObj.getBooks(booksObj.isIn(bkNo)).Show();
    }
    else
        cout << "没有该图书!" << endl;
}

void addBooks(bookList &booksObj)
{
    int i,Num, number;
    char bkNo[20];

    cout << "请输入您要入库的书的书号和数量:  ";
    cin  >> bkNo >> number;
    if((i=booksObj.isIn(bkNo)) > -1)
    {
        Num = booksObj.getBooks(i).getNum();
        booksObj.getBooks(i).setNum(Num+number);
    }
    else
    {
        cout << "该书不存在,请增加一条记录" << endl;
        appendRecord(booksObj);
    }
}

void sellBooks(bookList &booksObj)
{
    int i, Num, sell;
    char bkNo[20];

    cout << "请输入您要销售书的书号、数量:  " << endl;
    cin >> bkNo >> sell;

    if((i=booksObj.isIn(bkNo)) > -1)
    {
        Num = booksObj.getBooks(i).getNum();
        if(Num<sell) cout << "库存不足" << endl;
        else
        {
            booksObj.getBooks(i).setNum(Num-sell);
            cout << "销售了" << sell << "本书" << endl;
        }
    }
    else     cout << "该书不存在,请增加一条记录" << endl;
}

void appendFromTxtFile(bookList &booksObj)
{
    char filename[20];

    cout << "请输入文件名: ";
    cin >> filename;
    booksObj.readFromFile(filename);
}

void writeToTxtFile(bookList booksObj)
{
    char filename[20];

    cout << "请输入文件名:  ";
    cin >> filename;
    booksObj.writeToFile(filename);
}

void sortByNo(bookList &booksObj)
{
    booksObj.sortBooks();
}

void deleteAll(bookList &booksObj)
{
    booksObj.setCurBookLen(0);
}

char Quit(bookList &booksObj)
{
    char flag;

    cout << "Are you sure to quit? input y or n  :";
    cin >> flag;
    if(flag == 'y') booksObj.writeToFile("bookdata.txt");
    return flag;
}

int menu_select()
{
    char *menu[11] = {
        "1.    追加图书记录",
        "2.    删除图书记录",
        "3.    查询所有图书记录",
        "4.    查询图书",
        "5.    图书入库",
        "6.    图书销售",
        "7.    批量导入图书",
        "8.    导出图书记录",
        "9.    按书号排序",
        "10.   删除全部图书记录",
        "0.    退出"
    };
    int choice;
    do{
        system("cls");
        cout << "                                图书库存管理系统" << endl << endl;
        cout << "                       =================================" << endl;
        for(int i=0; i<11; i++)
            cout << "                             " << menu[i] << endl;
        cout << "                       =================================" << endl;
        cout << "请输入选择: ";
        cin >> choice;
    }while(choice<0 || choice>10);
    return choice;
}

int main()
{
    bookList booksObj;
    int sel;
    booksObj.initBookList();

    for (;;)
    {
        switch(sel=menu_select())
        {
            case 1:appendRecord(booksObj);system("pause");break;
            case 2:delRecord(booksObj);system("pause");break;
            case 3:showAll(booksObj);system("pause");break;
            case 4:query(booksObj);system("pause");break;
            case 5:addBooks(booksObj);system("pause");break;
            case 6:sellBooks(booksObj);system("pause");break;
            case 7:appendFromTxtFile(booksObj);system("pause");break;
            case 8:writeToTxtFile(booksObj);system("pause");break;
            case 9:sortByNo(booksObj);system("pause");break;
            case 10:deleteAll(booksObj);system("pause");break;
            case 0:
                if(Quit(booksObj) != 'y') continue;
        }
        if(sel == 0) break;
    }
    return 0;
}