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 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口