①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;
}