zoukankan      html  css  js  c++  java
  • 关于“C++语言程序设计”书的一个类

    class book
    {
        char* title;
        int num_pages;
        int cur_page;
    public:
        book(const char* theTitle, int pages) :num_pages(pages)
        {
            title = new char[strlen(theTitle) + 1];
            strcpy(title, theTitle);
            int x = strlen(title);
            cout << endl << "书名:" << title << endl << "总页数 :" << num_pages;
        }
        ~book()
        {
            delete[] title;
        }
        bool isClased()const{ return cur_page == 0; }
        bool idOpen()const{ return !isClased(); }
        int numOfpage()const{ return num_pages; }
        int currentPage()const{ return cur_page; }
        void openAtPage(int page_no)
        {
            cout << endl;
            if (page_no<1||page_no>num_pages)
            {
                cout << "没有" << page_no << "页";
            }
            else
            {
                cur_page = page_no;
                cout << title << "打开到" << cur_page << "页";
            }
        }
        void openAtPrevPage(){ openAtPage(cur_page - 1); }
        void openAtNextPage(){ openAtPage(cur_page + 1); }
        void close()
        {
            if (isClased())
            {
                cout << "书是合着呢" << endl;
            }
            else{ cur_page = 0; cout << "书已经合上了" << endl; }
        }
    };


    int _tmain()
    {
        book iBook("C++语言程序设计 ", 299);
        iBook.openAtPage(50);
        iBook.openAtNextPage();
        iBook.openAtNextPage();
        iBook.openAtPrevPage();
        iBook.close();
        cout << "当前页:" << iBook.currentPage() << endl;
        return 0;
    }

  • 相关阅读:
    2月4日学习日志
    2月3日学习日志
    2月2日学习日志
    2月1日学习日志
    Result Maps collection already contains value for ***
    mapreduce入门程序之---wordcount
    利用Git上传项目到github以及遇到的问题
    看100篇架构设计的文章,不如重构一次代码
    面试中的微服务架构
    分布式架构中数据一致性常见的几个问题
  • 原文地址:https://www.cnblogs.com/huninglei/p/5444008.html
Copyright © 2011-2022 走看看