zoukankan      html  css  js  c++  java
  • 类外定义成员函数实例

    ①volume.h

     
    #include <iostream>
    using namespace std;
     
    class volume
    {
    public:
    double length;
    double width;
    double height;
    double countvolume();
    void setarg();
    void display();
    };
     
     
     
    ②volume.cpp
     
    #include"stdafx.h"
    #include<iostream>
    #include"volume.h"
    using namespace std;
     
    double volume::countvolume()
    {
    double y=(length*width*height);
    return y;
    }
     
    void volume::display()
    {
    double y=volume::countvolume();
    cout<<"The Volume is "<<y<<endl;
    }
     
    void volume::setarg()
    {
    cout<<"Please Enter length , width , heigth "<<endl;
    cin>>length>>width>>height;
    cout<<endl;
    }
     
     
    ③main函数
     
     
    #include "stdafx.h"
    #include<iostream>
    #include"volume.h"
    using namespace std;
     
     
    int _tmain(int argc, _TCHAR* argv[])
    {
    volume v1;
    v1.setarg();
    v1.countvolume();
    v1.display();
    return 0;
    }
  • 相关阅读:
    JSP数据交互(一)
    response.setHeader()用法
    Vue初步认识
    Socket初步了解
    DOM4j的修改删除方式
    多线程
    ArrayList和Vector区别
    集合框架(一)
    深入C#数据类型
    深入.NET框架
  • 原文地址:https://www.cnblogs.com/humanchan/p/3020868.html
Copyright © 2011-2022 走看看