摘要: 大师级经典的著作,要字斟句酌的去读,去理解。以前在看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++ 阅读(471) 评论(0) 推荐(0)
摘要: if you not hard;it will be sad! 阅读全文
posted @ 2014-04-13 21:06 天下纵横C++ 阅读(149) 评论(0) 推荐(0)
摘要: 忘发了,补上8.7#include using namespace std;template T SumArray(T arr[],int n){ T sum=0; for(int i=0;iT SumArray(T *arr[],int n)//arr是指向指针数组的指针{ T sum=0; for(int i=0;i<n;i++) sum+=*arr[i]; //arr[i]是一个指针,+*之后才是其中的数值; return sum;};struct debts{ char name[20]; double amount;};void main87(){ int things[6.. 阅读全文
posted @ 2014-04-13 20:32 天下纵横C++ 阅读(154) 评论(0) 推荐(0)
摘要: 8.4发现忘记发上来了,现在补上。8.4#include#include //出问题时,使用的是cstring,但换成string一样出问题using namespace std;struct stringy{ char *str; int ct;};void set(stringy &beany,const char t[]);void show(const stringy &beany,int count=0);void show(const char t[],int count=0);void main84(){ stringy beany; char testing[] 阅读全文
posted @ 2014-04-13 20:31 天下纵横C++ 阅读(153) 评论(0) 推荐(0)
摘要: Person.h#ifndef Person_H_#define Person_H_#include using namespace std;class Person{private: static const int LIMIT=25; string lname; char fname[LIMIT];public: Person(){lname="default";fname[0]='\0';} Person(const string &ln,const char *fn="Heyyou"); ~Person(); void s 阅读全文
posted @ 2014-04-13 20:25 天下纵横C++ 阅读(193) 评论(0) 推荐(0)
摘要: bank.h#ifndef bank_H_#define bank_H_#include using namespace std;class Bank{ private: string name; string account; double money; void setIn(double in){money+=in;}; void setOut(double out){money-=out;}; double getMoney(){return money;}; public: Bank(string n,string a,double m); ~Bank(); //vo... 阅读全文
posted @ 2014-04-13 19:40 天下纵横C++ 阅读(350) 评论(0) 推荐(0)
摘要: SALES.h#ifndef SALES_H_namespace SALES{ const int QUARTERS=4; struct Sales{ double sales[QUARTERS]; double average; double max; double min; }; void setSales(Sales &s,const double ar[],int n); void setSales(Sales &s); void showSales(const Sales &s);} #endifSALES.cpp#include "SALES.h& 阅读全文
posted @ 2014-04-13 14:12 天下纵横C++ 阅读(297) 评论(0) 推荐(0)
摘要: //9.3这道题比较少见,我之前在百度都找不到我就发题目上来吧/*下面是一个结构声明:struct chaff{ char dross[20]; int slag;} 编写一个程序,使用定位new运算符将一个包含两个这种结构的数组放在一个缓冲区内。然后,给结构的成员赋值(对于char数组,使用strcpy()),并使用一个循环来显示内容,一种方法是像程序清单9.10那样将一个静态数组用作缓冲区,另一种方法是使用常规的new运算符来分配缓冲区。*/#include#include #include using namespace std;struct chaff{ char dross[20]; 阅读全文
posted @ 2014-04-13 12:28 天下纵横C++ 阅读(261) 评论(0) 推荐(0)
摘要: 投给了金山,感觉信心真心一般般啊。毕竟学C++有点晚,数据结构又忘得差不多了。所以还是赶紧看完这本《C++ primer plus》大作,然后突击一下数据结构,看下17号的笔试结果如何把。恩,加油! 阅读全文
posted @ 2014-04-13 12:08 天下纵横C++ 阅读(97) 评论(0) 推荐(0)