c++primer plus 清单11.16,11.17 , 11.18.

首先清单11.16
#ifndef STONEWTY_H_
#define STONEWTY_H_
class Stonewt
{
private:
enum{Lbs_per_stn=14};
int stone;
double pds_left;
double pounds;
public:Stonewt(double lbs);
Stonewt(int stn,double lbs);
Stonewt();
~Stonewt();
void show_lbs()const;
void show_stn()const;
};
#endif // !1
其次11.17
#include “stdafx.h”
#include “vector.h”
#include
using std::cout;
Stonewt::Stonewt(double lbs)
{
stone = int(lbs) / Lbs_per_stn;
pds_left = int(lbs) % Lbs_per_stn + lbs - int(lbs);
pounds = lbs;
}

Stonewt::Stonewt(int stn, double lbs)
{
stone = stn;
pds_left = lbs;
pounds = stn*Lbs_per_stn + lbs;
}

Stonewt::Stonewt()
{
stone = pounds = pds_left = 0;
}

Stonewt::~Stonewt()
{
}

void Stonewt::show_lbs() const
{
cout << stone << “stone” <<pds_left<<“pounds \n”;
}

void Stonewt::show_stn() const
{
cout << pounds << “pounds\n”;
}

最后11.18
// 11月21.cpp: 定义控制台应用程序的入口点。
//

#include “stdafx.h”
#include
#include
#include
#include"vector.h"
void display(const Stonewt&st, int n);
int main()
{
using namespace std;
Stonewt incognito = 275;
Stonewt wolfe(285.7);
Stonewt taft(21, 8);

cout << "The celebrity weighted";
incognito.show_stn();
cout << "The detective weighted";
wolfe.show_stn();
cout << "The President weighted";
taft.show_lbs();
incognito = 276.8; 
taft = 325;
cout << "After dinner ,the celebrity weighted";
taft.show_stn();
cout << "After dinner ,the President weighted";
taft.show_lbs();
display(taft,2);
cout << "The wrestler weighted even more .\n";
display(422, 2);
cout << "No stone left unearned\n";
cin.get();
return 0;

}

void display(const Stonewt & st, int n)
{
for (int i = 0;i<n;++i)
{
std::cout << “Wow!”;
st.show_lbs();
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值