65,176
社区成员




using namespace std;
class Rectangle
{
public:
void Input();
void Count();
void Output();
private:
float length;
float width;
float height;
float volume;
}
Function.cpp
#include<iostream>
#include"Rectangle.h"
void Rectangle::Input()
{
cout <<"请输入长方体的长:"<<endl;
cin >>length;
cout <<"请输入长方体的宽:"<<endl;
cin >>width;
cout <<"请输入长方体的高:"<<endl;
cin >>height;
}
void Rectangle::Count()
{
volume=length*width*height;
}
void Rectangle::Output()
{
cout <<"该长方体的体积为"<<volume<<endl;
}
main.cpp
#include<iostream>
#include"Rectangle.h"
int main()
{
Rectangle rec1,rec2,rec3;
rec1.Input();
rec1.Count();
rec1.Output();
rec2.Input();
rec2.Count();
rec2.Output();
rec3.Input();
rec3.Count();
rec3.Output();
cout <<"OVER!"<<endl;
return 0;
}