zoukankan      html  css  js  c++  java
  • 26)多文件形式编写类步骤

    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 }

      最后结果展示:

  • 相关阅读:
    Python接口测试实战5(下)
    Python接口测试实战4(上)
    Python接口测试实战3(下)- unittest测试框架
    Python接口测试实战3(上)- Python操作数据库
    Python接口测试实战2
    Python接口测试实战1(下)- 接口测试工具的使用
    Python接口测试实战1(上)- 接口测试理论
    python+request+Excel做接口自动化测试
    Android软件测试Monkey测试工具
    Python循环语句
  • 原文地址:https://www.cnblogs.com/xiaoyoucai/p/8183029.html
Copyright © 2011-2022 走看看