1.box����Դ��
2.定义一个Box(盒子)类,盒盒源管理系统源码行数在该类定义中包括数据成员: length(长),width(宽)和height(
box����Դ��
import java.util.Scanner;
public class Box
{
private int a,b,c;
public Box(int a,int b,int c)
{
this.a=a;
this.b=b;
this.c=c;
}
public int getVol()
{
return a*b*c;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("输入第一个的长宽高:");
System.out.println("长");
int a;
a=sc.nextInt();
System.out.println("宽");
int b;
b=sc.nextInt();
System.out.println("高");
int c;
c=sc.nextInt();
Box b1=new Box(a,b,c);
System.out.println("输入第二个的长宽高:");
System.out.println("长");
a=sc.nextInt();
System.out.println("宽");
b=sc.nextInt();
System.out.println("高");
c=sc.nextInt();
Box b2=new Box(a,b,c);
System.out.println("输入第三个的长宽高:");
System.out.println("长");
a=sc.nextInt();
System.out.println("宽");
b=sc.nextInt();
System.out.println("高");
c=sc.nextInt();
Box b3=new Box(a,b,c);
System.out.println("三个的体积分别为:");
System.out.println(b1.getVol());
System.out.println(b2.getVol());
System.out.println(b3.getVol());
}
}
定义一个Box(盒子)类,在该类定义中包括数据成员: length(长),width(宽)和height(
#include <iostream>
using namespace std;
class Box {
float length, width, height;
public:
Box(float l, float w, float h);
float GetVolume() const;
};
Box::Box(float l = 1, float w = 1, float h = 1)
: length(l), width(w), height(h) { }
float Box::GetVolume() const {
return height * width * length;
}
int main()
{
Box b1, b2(2, 3, 4);
float v1, v2;
v1 = b1.GetVolume();
v2 = b2.GetVolume();
if (v1>v2)
cout << v1 << " " << v2 << endl;
else
cout << v2 << " " << v1 << endl;
return 0;
}