题解 | #设计立方体类#
设计立方体类
https://www.nowcoder.com/practice/0f02d35dcd564f0a87865d604eccbe18
#include<iostream>
template<typename T>
class Cube
{
public:
T getArea(T length, T width, T height)
{
std::cout << length << " " << width << " " << height << " " ;
auto it = 2 * (length * width + length * height + width * height);
return it;
}
T getVolume( T length, T width, T height)
{
//std::cout << length << " " << width << " " << height << " " << std::endl;
auto it = length * width * height;
return it;
}
};
int main(void)
{
Cube<int> get;
int a, b, c;
std::cin >> a;
std::cin >> b;
std::cin >> c;
std::cout << get.getArea(a, b, c) << " " << get.getVolume(a, b, c) << std::endl;
return 0;
}
template<typename T>
class Cube
{
public:
T getArea(T length, T width, T height)
{
std::cout << length << " " << width << " " << height << " " ;
auto it = 2 * (length * width + length * height + width * height);
return it;
}
T getVolume( T length, T width, T height)
{
//std::cout << length << " " << width << " " << height << " " << std::endl;
auto it = length * width * height;
return it;
}
};
int main(void)
{
Cube<int> get;
int a, b, c;
std::cin >> a;
std::cin >> b;
std::cin >> c;
std::cout << get.getArea(a, b, c) << " " << get.getVolume(a, b, c) << std::endl;
return 0;
}