Читаем Справочное руководство по C++ полностью

 int* p = new int;

 cout ‹‹ "sizeof(int) = " ‹‹ sizeof(int) "\n";

}

<p>b2_3_6a.cxx</p>

#include ‹stream.hxx›

extern int strlen(char*);

char alpha[] = "abcdefghijklmnopqrstuvwxyz";

main ()

{

 int sz = strlen(alpha);

for (int i=0; i‹sz; i++) {

 char ch = alpha[i];

 cout ‹‹ "'" ‹‹ chr(ch) ‹‹ "'"

  ‹‹ " = " ‹‹ ch

  ‹‹ " = 0" ‹‹ oct(ch)

  ‹‹ " = 0x" ‹‹ hex(ch) ‹‹ "\n";

 }

}

<p>b2_3_6b.cxx</p>

#include ‹stream.hxx›

char v[2][5] = {

 'a', 'b', 'c', 'd', 'e',

 '0', '1', '2', '3', '4'

};

main() {

 for (int i = 0; i‹2; i++) {

  for (int j = 0; j ‹5; j++)

   cout ‹‹ "v[" ‹‹ i ‹‹ "][" ‹‹ j

    ‹‹ "]=" ‹‹ chr(v[i][j]) ‹‹ " ";

  cout ‹‹ "\n";

 }

}

<p>b2_3_7.cxx</p>

#include ‹stream.hxx›

main()

{

 char cv[10];

 int iv[10];

 char* pc = cv;

 int* pi = iv;

 cout ‹‹ "char* " ‹‹ long(pc+1)-long(pc) ‹‹ "\n";

 cout ‹‹ "int* " ‹‹ long(pi+1)-long(pi) ‹‹ "\n";

}

<p>b2_3__10.cxx</p>

#include ‹stream.hxx›

struct pair {

 char* name;

 int val;

};

extern int strlen(char*);

extern int strcpy(char*, char*);

extern int strcmp(char*, char*);

const large = 1024;

static pair vec[large];

pair* find(char* p)

{

 for (int i=0; vec[i].name; i++)

  if (strcmp(p,vec[i].name)==0) return &vec[i];

 if (i == large) return &vec[large-1];

 return &vec[i];

}

int& value(char* p)

{

 pair* res = find(p);

 if (res-›name == 0) {

  res-›name = new char[strlen(p)+1];

  strcpy(res-›name,p);

  res-›val = 0;

 }

 return res-›val;

}

const MAX = 256;

main ()

{

 char buf [MAX];

 while (cin››buf) value(buf)++;

 for (int i=0; vec[i].name; i++)

  cout ‹‹ vec[i].name ‹‹ ":" ‹‹ vec[i].val ‹‹ "\n";

}

<p>b3_1all.cxx</p>

#include ‹xstream.hxx›

#include ‹ctype.h›

enum token_value {

 NAME, NUMBER, END,

 PLUS = '+', MINUS = '-', MUL='*', DIV='/',

 PRINT=';', ASSIGN='=', LP='(', RP=')'

};

token_value curr_tok;

struct name {

 char* string;

 name* next;

 double value;

};

const TBLSZ = 23;

name* table[TBLSZ];

int no_of_errors;

double error(char* s) {

 cerr ‹‹ "error: " ‹‹ s ‹‹ "\n";

 no_of_errors++;

 return 1;

}

extern int strlen(const char*);

extern int strcmp(const char*, const char*);

extern char* strcpy(char*, const char*);

name* look(char* p, int ins = 0)

{

 int ii= 0;

 char *pp = p;

 while (*pp) ii = ii‹‹1 ^ *pp++;

 if (ii ‹ 0) ii = -ii;

 ii %= TBLSZ;

 for (name* n=table [ii]; n; n=n-›next)

  if (strcmp(p,n-›string) == 0) return n;

 if (ins == 0) error("name not found");

 name* nn = new name;

 nn-›string = new char[strlen(p) + 1];

 strcpy(nn-›string,p);

 nn-›value = 1;

 nn-›next = table[ii];

 table[ii] = nn;

 return nn;

}

inline name* insert(char* s) { return look (s,1); }

token_value get_token();

double term();

double expr()

{

 double left = term();

 for (;;)

  switch (curr_tok) {

  case PLUS:

   get_token();

   left += term();

   break;

  case MINUS:

   get_token();

   left -= term();

   break;

Перейти на страницу:

Похожие книги

C++ Primer Plus
C++ Primer Plus

C++ Primer Plus is a carefully crafted, complete tutorial on one of the most significant and widely used programming languages today. An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages.The sixth edition of C++ Primer Plus has been updated and expanded to cover the latest developments in C++, including a detailed look at the new C++11 standard.Author and educator Stephen Prata has created an introduction to C++ that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C++ language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.In C++ Primer Plus, you'll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:• A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard• Complete, integrated discussion of both basic C language and additional C++ features• Clear guidance about when and why to use a feature• Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time• Hundreds of practical sample programs• Review questions and programming exercises at the end of each chapter to test your understanding• Coverage of generic C++ gives you the greatest possible flexibility• Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces

Стивен Прата

Программирование, программы, базы данных
Adobe Flash. Создание аркад, головоломок и других игр с помощью ActionScript
Adobe Flash. Создание аркад, головоломок и других игр с помощью ActionScript

Данная книга посвящена программированию игр с помощью ActionScript. Здесь вы найдете подробные указания, необходимые для создания самых разных игр – аркад, головоломок, загадок и даже игровых автоматов. В тексте приведены исходные коды программ и детальные, доступно изложенные инструкции. Базовые принципы программирования ActionScript рассматриваются на примере игр, однако вы без труда сможете применить полученные знания и для разработки неигровых проектов, таких как Web-дизайн и реклама. Рекомендации Гэри Розенцвейга помогут вам не только придумывать занимательные игры и размещать их на Web-сайте, но и оптимизировать скорость их работы, а также защищать свои творения от несанкционированного копирования. Представленный в книге код несложно изменить для использования в других программах.Книга предназначена для широкого круга читателей – создателей анимационных роликов, художников-оформителей, программистов и разработчиков Web-сайтов. Издание может также выступать в качестве практического пособия по изучению ActionScript.

Гэри Розенцвейг

Программирование, программы, базы данных / Программирование / Книги по IT