m0_60901238 2021-09-15 16:51 采纳率: 81.5%
浏览 64
已结题

定义类News,其中包括五个私有变量

img


请问这个用C++怎么写呢?定义类之后那个get(),set()函数怎么写呢?

  • 写回答

1条回答 默认 最新

  • L_qingting 2021-09-15 17:11
    关注
    
    class News {
    public:
        News(int newsid, std::string newstitle, std::string newscontent, std::string newsauthor, bool isavailable)
        {
            this->newsid = newsid;
            this->newstitle = newstitle;
            this->newscontent = newscontent;
            this->newsauthor = newsauthor;
            this->isavailable = isavailable;
        }
        void set_newsid(int newsid)
        {
            this->newsid = newsid;
        }
        int get_newsid()
        {
            return newsid;
        }
    
        void set_newstitle(std::string newstitle)
        {
            this->newstitle = newstitle;
        }
        std::string get_newstitle()
        {
            return newstitle;
        }
    
        void set_newscontent(std::string newscontent)
        {
            this->newscontent = newscontent;
        }
        std::string get_newscontent()
        {
            return newscontent;
        }
    
        void set_newsauthor(int newsid)
        {
            this->newsauthor = newsauthor;
        }
        std::string get_newsauthor()
        {
            return newsauthor;
        }
    
        void set_isavailable(bool isavailable)
        {
            this->isavailable = isavailable;
        }
        
        bool get_isavailable()
        {
            return isavailable;
        }
    
    private:
        int newsid;
        std::string newstitle;
        std::string newscontent;
        std::string newsauthor;
        bool isavailable;
    };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月23日
  • 已采纳回答 9月15日
  • 创建了问题 9月15日

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了