首页 > 其他 > 详细

26)多文件形式编写类步骤

时间:2018-01-03 12:59:12      阅读:465      评论:0      收藏:0      [点我收藏+]

1)所用的C++编译器:VIsual  statio  2012

2)然后 点开你现在建的工程的上面-->添加--->新建项目--->添加-->类

    (1)

          技术分享图片

        (2)然后

            技术分享图片

 

         (3)然后

    技术分享图片

            (4)然后

          技术分享图片

 

         (5)然后     

    技术分享图片

          (6)然后

技术分享图片

 

 

            (7)  然后,在你的工程里面,就有了 文件:
            

                技术分享图片

 里面的代码:

 1 //这个是circle.h的文件内容
 2 #pragma once
 3 class circle
 4 {
 5 public:
 6         //设置半径
 7     void setR(double r);
 8     double getR();
 9         //得到面积
10     double get_area();
11         //得到周长
12     double get_bith();
13 private:
14     double m_r;
15     double m_area;
16     double m_girth;
17 
18 };
 1 //这个是circle.h的内容
 2 #include "circle.h"
 3 void circle::setR(double r)
 4     {
 5         circle::m_r=r;
 6     }
 7     double circle::getR()
 8     {
 9         return circle::m_r;
10     }
11         //得到面积
12     double circle::get_area()
13     {
14        m_area=m_r*m_r*m_r; 

return circle::m_area; 15 } 16 //得到周长 17 double circle::get_bith() 18 { 19 m_girth=m_r+m_r+m_r;

return circle::m_girth; 20 }
 1 //然后  我的  源.cpp  文件代码
 2 #include<iostream>
 3 #include"circle.h"
 4 using namespace std;
 5 int main()
 6 {
 7     circle circle;
 8     circle.setR(10.0);
 9     int a=circle.get_area();
10     int b=circle.get_bith();
11     cout<<a<<endl;
12     cout<<b<<endl;
13     
14 }

  最后结果展示:

技术分享图片

 

26)多文件形式编写类步骤

原文:https://www.cnblogs.com/xiaoyoucai/p/8183029.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!