c++问题 急求答案!!
设计一个立方体类Box,它能计算立方体的体积和表面积,创建两个立方体类对象box1box2,其中对象box1被带参初始化,另一个对象box2调用拷贝构造函数初始化box1...
设计一个立方体类Box,它能计算立方体的体积和表面积,创建两个立方体类对象box1box2,其中对象box1被带参初始化,另一个对象box2调用拷贝构造函数初始化box1=box2,输出两个对象的体积和表面积。
展开
展开全部
#include "iostream"
#include <stdlib.h>
#include <stdio.h>
using namespace std;
class Cube
{
private: double d1,d2,d3;
public: Cube(double length, double width, double height)
{
d1=length;
d2=width;
d3=height;
}
public: double Area()
{
return (d1*d2+d1*d3+d2*d3)*2;
}
public: double Volume()
{
return d1*d2*d3;
}
};
int main()
{
double l,w,h;
printf("Input(length width height):");
scanf("%lf%lf%lf",&l,&w,&h);
printf("Implement cube1...\n");
Cube cube1(l,w,h);
printf("Copy cube1 to cube2...\n");
Cube cube2=cube1;
printf("The area of cube1 is:%lf\n",cube1.Area());
printf("The volumn of cube1 is:%lf\n",cube1.Volume());
printf("The area of cube2 is:%lf\n",cube2.Area());
printf("The volumn of cube2 is:%lf\n",cube2.Volume());
system("PAUSE");
return 0;
}
#include <stdlib.h>
#include <stdio.h>
using namespace std;
class Cube
{
private: double d1,d2,d3;
public: Cube(double length, double width, double height)
{
d1=length;
d2=width;
d3=height;
}
public: double Area()
{
return (d1*d2+d1*d3+d2*d3)*2;
}
public: double Volume()
{
return d1*d2*d3;
}
};
int main()
{
double l,w,h;
printf("Input(length width height):");
scanf("%lf%lf%lf",&l,&w,&h);
printf("Implement cube1...\n");
Cube cube1(l,w,h);
printf("Copy cube1 to cube2...\n");
Cube cube2=cube1;
printf("The area of cube1 is:%lf\n",cube1.Area());
printf("The volumn of cube1 is:%lf\n",cube1.Volume());
printf("The area of cube2 is:%lf\n",cube2.Area());
printf("The volumn of cube2 is:%lf\n",cube2.Volume());
system("PAUSE");
return 0;
}
展开全部
//直接写的,没编译,没排版
#include<iostream>
using namespace std;
class Box{
long bianchang;
public:
Box(int a){
bianchang=a;
}
long getVol(){
return bianchang*bianchang*bianchang;
}
long getArea(){
return 6*bianchang*bianchang;
}
};
int main(){
long a;
cin>>a;
Box box1=Box(a);
Box box2=box1;
cout<<"体积"<<box1.getVol()<<" 表面积"<<box1.getArea()<<endl;
cout<<"体积"<<box2.getVol()<<" 表面积"<<box2.getArea()<<endl;
}
#include<iostream>
using namespace std;
class Box{
long bianchang;
public:
Box(int a){
bianchang=a;
}
long getVol(){
return bianchang*bianchang*bianchang;
}
long getArea(){
return 6*bianchang*bianchang;
}
};
int main(){
long a;
cin>>a;
Box box1=Box(a);
Box box2=box1;
cout<<"体积"<<box1.getVol()<<" 表面积"<<box1.getArea()<<endl;
cout<<"体积"<<box2.getVol()<<" 表面积"<<box2.getArea()<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询