【11.6】c++ primer plus 课后编程答案
来源:互联网 发布:手机网络劫持 编辑:程序博客网 时间:2024/06/06 21:42
C++ PRIMER PLUS 课后答案
使用IDE为window7系统下的VS2010
/*user.h*/#ifndef USERSH_H_#define USERSH_H_#include <string>#include <cmath>using std::ostream;using std::istream;class Ston{private: static const int lbs_per_sto=14; int stone; double pounds; double pds_left;public: Ston(); Ston(doublelbs); Ston(intstn,double lbs); ~Ston(){}; Ston& operator = (const Ston & p); friend ostream & operator << (ostream & os, const Ston & p); friend istream & operator >> (istream & is, Ston & p); friend bool operator < (const Ston & p1,const Ston & p2); friend bool operator <= (const Ston & p1,const Ston & p2); friend bool operator >= (const Ston & p1,const Ston & p2); friend bool operator > (const Ston & p1,const Ston & p2); friend bool operator == (const Ston & p1,const Ston & p2); friend bool operator != (const Ston & p1,const Ston & p2);}; #endif
/*userfucntion.cpp*/#include "usersh.h"#include <iostream>using std::cout;using std::cin;using std::ostream;using std::istream; Ston::Ston(int stn,double lbs){ stone=stn; pds_left=lbs; pounds=stn*lbs_per_sto+lbs;} Ston::Ston(){ stone=pounds=pds_left=0.0;} Ston::Ston(double lbs){ stone=int(lbs)/lbs_per_sto; pds_left=int(lbs)%lbs_per_sto+lbs-int(lbs); pounds=lbs;} bool operator < (const Ston & p1,const Ston & p2) { if (p1.pounds<p2.pounds) return true; else return false; } bool operator <= (const Ston & p1,const Ston & p2) { if(p1.pounds <= p2.pounds) return true; else return false; } bool operator >= (const Ston & p1,const Ston & p2) { if(p1.pounds >= p2.pounds) return true; else return false; } bool operator > (const Ston & p1,const Ston & p2) { return (p2<p1); } bool operator == (const Ston & p1,const Ston & p2) { if(p1.pounds==p2.pounds) return true; else return false; } bool operator != (const Ston & p1,const Ston & p2) { if(p1.pounds!=p2.pounds) return true; else return false; } Ston & Ston::operator = (const Ston & p) ////这里会出问题! { pounds=p.pounds; pds_left=p.pds_left; stone=p.stone; return *this; } ostream & operator << (ostream &os,const Ston & p) { os <<"pounds:"<<p.pounds<<'\n'; return os; } istream & operator >> (istream &is, Ston & p) { cout<<"please input pounds:"; is >> p.pounds; return is; }
/*main*/#include <iostream>#include <Windows.h>#include "usersh.h"#include <string>using namespace std; int main(){ const int max=6; int more_11_num=0; Ston Ponds_11(11.0); Ston Ponds[max]={Ston(5.1),Ston(6.1),Ston(12.3)}; Ston Max_pound =Ponds[0]; Ston Min_pound =Ponds[0]; for(int i=3;i<max;i++) cin>>Ponds[i]; for(int i=0;i<max;i++) { if(Max_pound < Ponds[i]) Max_pound= Ponds[i]; if(Min_pound > Ponds[i]) Min_pound= Ponds[i]; if(Ponds[i] >= Ponds_11) more_11_num++; } cout<<"thisis pounds list:"<<endl; for(int i=0;i<max;i++) { cout<<"NO."<<i+1<<':'<<Ponds[i]<<endl; } cout<<"the min pounds :"<<Min_pound<<endl; cout<<"the max pounds :"<<Max_pound<<endl; cout<<"the bigger than 11.0 pounds num is :"<<more_11_num<<endl; system("pause"); return 0;}
阅读全文
0 0
- C++primer plus第六版课后编程题答案11.6
- 【11.6】c++ primer plus 课后编程答案
- C++PRIMER PLUS第六版课后编程答案 4.1-4.5
- C++PRIMER PLUS第六版课后编程答案 4.6-4.10
- C++PRIMER PLUS第六版课后编程答案 5.1-5.5
- C++PRIMER PLUS第六版课后编程答案 5.6-510
- C++primer plus第六版课后编程题答案 6.1
- C++primer plus第六版课后编程题答案 6.2
- C++primer plus第六版课后编程题答案 6.3
- C++primer plus第六版课后编程题答案 6.4
- C++primer plus第六版课后编程题答案 6.5
- C++primer plus第六版课后编程题答案 6.6
- C++primer plus第六版课后编程题答案 6.7
- C++primer plus第六版课后编程题答案 6.8
- C++primer plus第六版课后编程题答案 6.9
- C++primer plus第六版课后编程题答案7.1
- C++primer plus第六版课后编程题答案7.2
- C++primer plus第六版课后编程题答案7.3
- 【11.3】c++ primer plus 课后编程答案
- sklearn包中的分析算法对 数据进行处理
- android RecyclerView自适应高度的LayoutManager
- 在Centos7 云服务器上配置远程数据库
- 106-多播地址
- 【11.6】c++ primer plus 课后编程答案
- Android AOP之字节码插桩
- 浅谈md5加密
- 实现生产者-消费者模式
- 最大子数组II
- 【11.7】c++ primer plus 课后编程答案
- hdu 4004
- Java实现-最大子数组1
- mysql 主键自增 但是报主键重复的异常问题探究- Duplicate entry