摘要: List.h#ifndef LIST_H_#define LIST_H_template struct Node{ T num; struct Node *next;};template class List{ static const int MAX=10;private: //T t[MAX]; //int top; Node *front; Node *rear; int qsize; Node *now;public: //List(int m); List(); ~List();//构造函数有new ,必须显示析构 void add(const T &t); bool isE 阅读全文
posted @ 2014-04-14 20:41 天下纵横C++ 阅读(274) 评论(0) 推荐(0) 编辑
摘要: Plorg.cpp#include #include using namespace std;//这次把声明和实现都放在cpp里面class Plorg{ const static int MAX=19;private: char name[MAX]; //string name; int CI;public: Plorg(const char *n="Plorga"):CI(50)//,int c=50)//:name("Plorga")如何设定初始值?如果name为string就可以这样做 { //原来还设定了CI初始值为50? strcpy(nam 阅读全文
posted @ 2014-04-14 18:59 天下纵横C++ 阅读(264) 评论(0) 推荐(0) 编辑
摘要: MOVE.h#ifndef MOVE_H_#define MOVE_H_using namespace std;//为了方便,我就直接把实现代码写到头文件了class Move{ private: double x; double y;public: Move(double a=0,double b=0):x(a),y(b){}; void showmove()const{ cout#include "MOVE.h"using namespace std;void main106(){ Move m(1.5,2.3); Move m1(2.1,4.5); Move m3(1 阅读全文
posted @ 2014-04-14 18:30 天下纵横C++ 阅读(310) 评论(0) 推荐(0) 编辑
摘要: 一般这种错误都是由于你写的头文件缺少";"导致的例如你写了#ifndef MOVE_H_#define MOVE_H_using namespace std;//为了方便,我就直接把实现代码写到头文件了class Move{ private: double x; double y;public: Move(double a=0,double b=0):x(a),y(b){}; void showmove()const{ cout<<"x="<<x<<" y="<<y<<end 阅读全文
posted @ 2014-04-14 18:26 天下纵横C++ 阅读(861) 评论(0) 推荐(0) 编辑
摘要: Stack.h#ifndef STACK_H_#define STACK_H_struct customer{ char fullname[35]; double payment;};typedef customer Item;class Stack{private: enum{MAX=10}; Item items[MAX]; int top;public: Stack(); bool isEmpty()const; bool isFull()const; bool push(const Item &item); bool pop(Item &item);};#endif S 阅读全文
posted @ 2014-04-14 17:51 天下纵横C++ 阅读(301) 评论(0) 推荐(0) 编辑
摘要: SALES.h#ifndef SALES_H_#define SALES_H_ //测试这一句的作用namespace SALES{ class Sales{ const static int QUARTERS=4; private: double sales[QUARTERS]; double average; double max; double min; public: Sales(const double ar[],int n); Sales(); void showS(int n){ for(int i=0;i#include "SALES.h"using nam 阅读全文
posted @ 2014-04-14 17:13 天下纵横C++ 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 来源:网络 作者:未知虽然很多程序员都熟悉名字空间的概念,但他们常常都是被动地使用名字空间。也就是说他们使用的是第三方定义的成员(如标准库的类和函数),而不是在名字空间中声明自己的类和函数。本文拟讨论如何在名字空间中声明自己的类和函数,以及如何在程序中使用它们。名字空间是一个范畴,它包含类声明,函数声明,常量声明和模板声明等名字空间成员。例如:namespace proj_alpha{//下面是名字空间proj_alpha的成员class Spy {/*..*/};void encrypt (char *msg);const int MAX_SPIES = 8;}在上面的例子中,类Spy在一个 阅读全文
posted @ 2014-04-14 17:10 天下纵横C++ 阅读(1008) 评论(0) 推荐(0) 编辑
摘要: golf.h#ifndef _GOLF_H_#define GOLF_H_class Golf{ const static int LEN=40;private: char fillname[LEN]; int handicap;public: Golf(const char *name,int hc); Golf(); void sethandicap(int hc){handicap=hc;}; void show();};#endifgolf.cpp#include #include "golf.h"#include using namespace std;Golf: 阅读全文
posted @ 2014-04-14 16:07 天下纵横C++ 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 大师级经典的著作,要字斟句酌的去读,去理解。以前在看K&R的The C Programming Language(SecondEdition)第1.5节的字符输入/输出,被getchar()和EOF所迷惑了。可能主要还是由于没有搞清楚getchar()的工作原理和EOF的用法。因此,感觉很有必要总结一下,不然,很多琐碎的知识点长时间过后就会淡忘的,只有写下来才是最好的方法。其实,getchar()最典型的程序也就几行代码而已。本人所用的环境是DebianGNU/Linux,在其他系统下也一样。一、 getchar的两点总结:1.getchar是以行为单位进行存取的。当用getchar进 阅读全文
posted @ 2014-04-13 22:32 天下纵横C++ 阅读(429) 评论(0) 推荐(0) 编辑
摘要: if you not hard;it will be sad! 阅读全文
posted @ 2014-04-13 21:06 天下纵横C++ 阅读(127) 评论(0) 推荐(0) 编辑