自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(106)
  • 收藏
  • 关注

原创 C++primer plus第六版课后编程练习答案14.1

#include #include using namespace std;template class Pair{ private: T1 a; T2 b; public: T1 &first(); T2 &second(); T1 first()const{return a;} T2 second()const{return b;} void s

2015-12-21 14:58:44 802

原创 C++primer plus第六版课后编程练习答案13.4

#include #include //我懒得用char*了 using namespace std; class Port{ protected: //懒得用方法了,就直接保护吧 string brand; //string style;//不需要style,因为派生出来的就是style int bottles; public:

2015-12-03 17:25:53 460

原创 C++primer plus第六版课后编程练习答案13.3

#ifndef DMA_H_#define DMA_H_#include class DMA{private: char *label; int rating;protected: void setlab(const char *c); void dellab(); void setrat(const int n); char *getlab()const{return

2015-12-03 17:23:52 647

转载 C++primer plus第六版课后编程练习答案13.1

#include #include using namespace std;class Cd{private: char performers[50]; char label[20]; int selections; double playtime;public: char *perfor(){return performers;}; char *lab(){return

2015-12-03 17:18:22 522

原创 C++primer plus第六版课后编程练习答案13.2

#ifndef CD_H_#define CD_H_struct StrAndLen{ char *ch; int len;};//base classclass Cd{//represents a CD diskprivate: StrAndLen performers; StrAndLen label; int selections;//number of sele

2015-12-03 17:06:28 498

原创 C++primer plus第六版课后编程练习答案12.5与12.6

bank是第五题的实现,bank1是第六题的实现#ifndef QUEUE_H_#define QUEUE_H_class Customer{private: int arrive; int processtime;public: Customer(){arrive=processtime=0;} void set(int when); int when()const{re

2015-12-03 16:58:04 501

转载 C++primer plus第六版课后编程练习答案12.4

#include using namespace std;typedef unsigned long Item;class Stack{private: enum{MAX=10}; Item *pitems; int size; int top;public: Stack(int n=MAX) { pitems=new Item[MAX]; top=0;//从0开始

2015-12-03 16:56:28 356

转载 C++primer plus第六版课后编程练习答案12.3

#include using namespace std;class Stock{private: char *company; int shares; double share_val; double total_val; void set_tot(){total_val=shares*share_val;};public: Stock(){ company=new ch

2015-12-03 16:54:57 433

转载 C++primer plus第六版课后编程练习答案12.2

string2.cpp#include #include #include using namespace std;static int num_string;//不是在h头文件中只能在这里static const int CINLIM=80;//在头文件中只能定义const常量class String{private: //char *str; string str;//改

2015-12-03 16:51:25 345

转载 C++primer plus第六版课后编程练习答案12.1

#ifndef COW_h_#define COW_h_class Cow{private: char name[20]; char *hobby; double weight;public: Cow(); Cow(const char *nm,const char *ho,double wt); Cow(const Cow &c); ~Cow(); Cow &operat

2015-12-03 16:47:32 271

原创 C++primer plus第六版课后编程练习答案11.7

头文件#ifndef COMPLEX0_H_#define CONPLEX0_H_#includeclass complex{private: double real; double imaginary;public: complex(){real=imaginary=0;} complex(double r,double i); complex operator+(

2015-12-01 17:59:47 318

原创 c++转换函数和类的自动转换

c++类中的转换函数的作用是将对象转换为其他类型,如doubleStonewt wolfe(285.7);double host=wolfe;Stonewt::operator double()const{return (pounds);}而类的自动转换是将其他类型转换为类的类型Stonewt incognito=275等价于Stonew

2015-12-01 17:56:06 282

原创 C++primer plus第六版课后编程练习答案11.5和11.6

这两道题是第6题包含第5题,所以第5题我就没写了,下面是第6题的答案头文件#ifndef STONEWt_H_#define STONEWt_H_#includeclass Stonewt{private: enum{Lbs_per_stn=14}; int stone; double pds_left; double pounds; int state;publi

2015-12-01 17:25:19 650

转载 C++primer plus第六版课后编程练习答案11.4

#ifndef MYTIME_h_#define MYTIME_h_#include //为了方便我全部写成inline函数了class Time{private: int hours; int minutes;public: Time(){ hours=minutes=0; }; Time(int h,int m=0){ hours=h; minutes=m;

2015-11-30 16:59:59 320

转载 C++primer plus第六版课后编程练习答案11.3

之前的类都是都是和11.1一样的#include #include #include #include //#include #include "vector.h"using namespace std;using namespace VECTOR;void main113(){ int MaxStep=-999; int MinStep=999; int sumS=0;

2015-11-30 16:46:35 334

转载 C++primer plus第六版课后编程练习答案11.2

下面几道题都和第一题类型差不多,我就没写了,放了别人写的#ifndef VECTOR112_H_#define VECTOR112_H_#include namespace VECTOR112{ //class Vector112; //std::ostream&operator<<(std::ostream &os,const Vector112 &v); class Vec

2015-11-30 16:42:51 343

原创 C++primer plus第六版课后编程练习答案11.1

头文件#ifndef VECTOR_H_//避免头文件的重定义,如果XX没有被定义#define VECTOR_H_//就定义XX,删除可使#ifndef与#endif之间的代码不执行#includenamespace VECTOR//用来区分名字相同的变量和函数{ class Vector { public: enum Mode{RECT,POL};//Mode枚举名,R

2015-11-30 16:28:27 460

原创 C++primer plus第六版课后编程练习答案10.8

头文件#ifndef LISt_H_#define LIST_H_#includeusing namespace std;static const int max=10;template class List{ T t[max]; int n;public: List(){n=0;} void add(T a); bool isFull(); bool isEm

2015-11-30 16:13:36 381

原创 C++primer plus第六版课后编程练习答案10.7

头文件#ifndef PLORG_H_#define PLORG_H_const int limit=19;class plorg{private: char name[limit]; int CI;public: plorg(const char *str="Plorga"); void setCI(int n); void showplorg()const;};

2015-11-30 16:11:04 632

原创 C++primer plus第六版课后编程练习答案10.6

头文件#ifndef MOVE_H_#define MOVE_H_/*class T{ int a; int b;};*/class Move{private: double x; double y;public: Move(double a=0,double b=0); void showmove()const; Move add(const Move &

2015-11-30 16:05:17 523

原创 C++primer plus第六版课后编程练习答案10.5

头文件#ifndef STACK_H_#define STACK_H_#includeusing namespace std;struct customer{ char fullname[35]; double payment;};typedef customer Item;class Stack{ Item item[10]; double payment;

2015-11-30 16:00:57 394

原创 C++primer plus第六版课后编程练习答案10.4

头文件#ifndef SALES_H_#define SALES_H_namespace SALES{ static const int QUARTERA=4; class Sales { double sales[QUARTERA]; double average; double max; double min; int m; public: Sales

2015-11-30 15:55:58 362

原创 C++primer plus第六版课后编程练习答案10.3

头文件#ifndef GOLF_H_#define GOLF_H_static const int len = 40;class golf{ char fullname[len]; int handicap;public: golf(){} golf(const char *name,int hc); int setgolf(golf &g); void sethan

2015-11-30 15:37:15 422

原创 C++primer plus第六版课后编程练习答案10.2

头文件#ifndef PERSON_H_#define PERSON_H_#include#includeusing namespace std;class Person{private:// static const int LIMIT = 25;//vc++6.0太旧了,无法支撑这个操作,在新一点的版本上是可以的 enum{LIMIT=12}; string lname

2015-11-30 15:34:33 403

原创 C++primer plus第六版课后编程练习答案10.1

头文件#ifndef BANKACCOUNT_H_#define BANKACCOUNT_H_#includeusing namespace std;class bankaccount{ string name; string account; double money;public: bankaccount(string name,string account,dou

2015-11-30 15:32:05 469

原创 C++primer plus第六版课后编程练习答案9.4

头文件#ifndef SALES_H_#define SALES_H_namespace SALES{ const int QUARTERS=4; struct Sales { double sales[QUARTERS]; double average; double max; double min; }; void setSales(Sales &s,

2015-11-29 17:21:04 599

原创 C++primer plus第六版课后编程练习答案9.3

#include#include#includeusing namespace std;const int BUF = 512;char buffer[BUF];struct chaff{ char dross[20]; int slag;};void setchaff(chaff &c,const char *str,int n);void showchaff(

2015-11-29 17:17:45 394

原创 C++primer plus第六版课后编程练习答案9.2

#include#includeusing namespace std;void strcount(const string str);int main(){ string input; cout<<"Enter a line:\n"; getline(cin,input); while(cin) { if(""==input) break; strco

2015-11-29 17:14:27 318

原创 C++primer plus第六版课后编程练习答案9.1

#ifndef GOLF_H_#define GOLF_H_const int Len=40;struct golf{ char fullname[Len]; int handicap;};void setgolf(golf &g,const char *name,int hc);int setgolf(golf &g);void handicap(golf &g,in

2015-11-29 17:06:14 489

原创 C++primer plus第六版课后编程练习答案8.7

#include#include#include//#include#includeusing namespace std;struct debts{ char name[50]; double amount;};templatevoid ShowArray(T arr[],int n);templatevoid ShowArray(T *arr[],int n)

2015-11-28 15:12:05 390

原创 C++primer plus第六版课后编程练习答案8.6

#include#include#include//#include#includeusing namespace std;templateT max5(T t[]);void m8_5();templateT maxn(T t[],int n);//曾经的错误T maxn(const T t[],int n);template (char *c[],int n);/

2015-11-28 14:58:04 423

原创 C++primer plus第六版课后编程练习答案8.5

#include#include#include//#include#includeusing namespace std;templateT max5(T t[]);templateT max5(T t[]){ T temp=t[0]; for(int i=0;i<5;i++) { if(temp<t[i]) temp=t[i]; } retur

2015-11-28 14:52:41 268

原创 C++primer plus第六版课后编程练习答案8.4

#include#include#include//#include#includeusing namespace std;struct stringy{ char *str; int ct;};void set(stringy &s,const char *n);void show(const char *c,int n=1);void show(const st

2015-11-28 14:45:11 430

原创 C++primer plus第六版课后编程练习答案8.3

#include#include#include//#include#includeusing namespace std;void strupper(string &s);void strupper(string &s){ for(int i=0;i<s.size();i++) s[i]=toupper(s[i]); cout<<s<<endl;}void

2015-11-28 14:41:51 381

原创 C++primer plus第六版课后编程练习答案8.2

#include#include#include//#include#includeusing namespace std;struct CandyBar{ char name[50]; double weight; int heat;};void initial(CandyBar &c,char *n="Millennium Munch",double w=2.85

2015-11-28 14:38:59 445

原创 C++primer plus第六版课后编程练习答案8.1

#include#include#include//#include#includeusing namespace std;int hcount=1;void showstr(char *str,int n=0);void showstr(char *str,int n){ if(n!=0) { for(int i=0;i<hcount;i++) cout<<str

2015-11-28 14:37:51 396

原创 C++primer plus第六版课后编程练习答案7.10

#include#include#include   using namespace std;double calculate(double x,double y,double (*pf)(double,double));double add(double x,double y);double sub(double x,double y);double mul(double x,

2015-11-27 17:36:02 275

原创 C++primer plus第六版课后编程练习答案7.9

#include#include#include   using namespace std;const int SLEN=30;struct student{ char fullname[SLEN]; char hobby[SLEN]; int opplevel;};int getinfo(student pa[],int n);void display1(stud

2015-11-27 17:23:08 259

原创 C++primer plus第六版课后编程练习答案7.8

#include#include#include   using namespace std;const int Seasons=4;const char *Snames[Seasons]={"Spring","Summer","Fall","Winter"};struct expense{ double expenses[Seasons];};void fill(dou

2015-11-27 17:20:24 472

原创 C++primer plus第六版课后编程练习答案7.7

#include#include#include   using namespace std;double *fill_array(double ar[],int size){ double temp; int i; double *p=ar; for(i=0;i<size;i++) { cout<<"Enter value #"<<i+1<<":"; cin>>t

2015-11-27 17:08:48 475

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除