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;
}
``````
本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

悬赏问题

• ¥20 python求解八元一次不定方程，无数解中随机输出几组即可（相关搜索：用python）
• ¥50 libreoffice导出PPTX到PDF中的错误换行问题
• ¥15 python实现网页视频下载
• ¥15 如何通过深度图获得物体的完整、正确点云？
• ¥15 找一本C#4.5参考大全电子书
• ¥15 有没有操作系统适用白丁的经典的书籍，如何解决？(标签-学习)
• ¥15 Catia V5 R20 64位 安装过程中选择orbix配置创建套接字失败
• ¥100 C51单片机设计交通灯时出现的问题
• ¥15 R语言爬虫的时候元素和园代码不一样怎么解决呀
• ¥15 SQL删除添加数据后序号不连续问题。