- 博客(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
850
原创 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
490
原创 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
702
转载 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
548
原创 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
519
原创 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
560
转载 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
376
转载 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
462
转载 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
373
转载 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
296
原创 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
341
原创 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
309
原创 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
677
转载 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
341
转载 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
372
转载 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
389
原创 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
480
原创 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
425
原创 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
653
原创 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
569
原创 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
432
原创 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
400
原创 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
446
原创 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
447
原创 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
500
原创 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
634
原创 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
431
原创 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
337
原创 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
543
原创 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
415
原创 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
446
原创 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
300
原创 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
472
原创 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
410
原创 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
477
原创 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
427
原创 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
308
原创 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
298
原创 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
498
原创 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
519
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人