YXTS122 2016-02-19 10:22 采纳率: 100%

# 这道编程题怎么做？本人小白。

• 写回答

#### 5条回答默认 最新

• threenewbee 2016-02-20 03:15
关注
`````` #include <iostream>
using namespace std;

class Stonewt
{
private:
int stone;
double pounds;
public:
Stonewt()
{
stone = 0;
pounds = 0.0;
}
Stonewt(double lbs)
{
stone = (int)lbs / 14;
pounds = lbs - ((int)lbs / 14 * 14);
}
Stonewt(int stn, double lbs)
{
stone = stn + (int)lbs / 14;
pounds = lbs - ((int)lbs / 14 * 14);
}
void show()
{
cout << stone << "stn " << pounds << "lbs." << endl;
}
bool operator > (const Stonewt &s)
{
if (stone == s.stone)
return pounds > s.pounds;
else
return stone > s.stone;
}
bool operator < (const Stonewt &s)
{
if (stone == s.stone)
return pounds < s.pounds;
else
return stone < s.stone;
}
bool operator == (const Stonewt &s)
{
if (stone == s.stone)
return pounds == s.pounds;
else
return false;
}
bool operator >= (const Stonewt &s)
{
return *this > s || *this == s;
}
bool operator <= (const Stonewt &s)
{
return *this < s || *this == s;
}
bool operator != (const Stonewt &s)
{
return !(*this == s);
}
};

int main()
{
Stonewt arr[6] = { Stonewt(28.5), Stonewt(50.1), Stonewt(1, 2.1) };
arr[3] = Stonewt(1, 20.0);
arr[4] = Stonewt(12, 0.4);
arr[5] = Stonewt(12, 0.6);
Stonewt max = arr[0];
Stonewt min = arr[0];
int n = 0;
Stonewt c = Stonewt(11, 0.0);
for (int i = 0; i < 6; i++)
{
arr[i].show();
if (arr[i] > max) max = arr[i];
if (arr[i] < min) min = arr[i];
if (arr[i] >= c) n++;
}
cout << "max "; max.show();
cout << "mix "; min.show();
cout << "> 11 stone: " << n << endl;
return 0;
}
``````
本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

#### 悬赏问题

• ¥15 springmvc redis主从
• ¥15 C++ 中std无法跨lib或dll的问题解决方案
• ¥15 单片机烧录软件stcISP检测不到串口，各种方法都试过了，就是没有，如何解决？
• ¥15 idea中的数据库驱动和druid驱动问题
• ¥15 Arcgis Pro python中如何读取geojson文件
• ¥50 关于uniapp高德地图当前定位点方向的修正问题
• ¥15 Arcgis Pro python中如何读取geojson文件
• ¥15 求一段C语言或C++语言写的CRC-32校验程序
• ¥15 电脑端如何获取非本机的摄像头高清图片