untitled

Similar documents
untitled

新版 明解C++入門編

FY.DOC

c_cpp

untitled

CC213

untitled

新版 明解C言語入門編

untitled

C/C++程序设计 - 字符串与格式化输入/输出

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

新・解きながら学ぶJava

untitled

C

新・解きながら学ぶC言語

新・明解C言語入門編『索引』

C/C++ - 文件IO

extend

_汪_文前新ok[3.1].doc

提问袁小兵:

Microsoft Word - 01.DOC

C 1

第3章.doc

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

02

全国计算机技术与软件专业技术资格(水平)考试

Chapter12 Derived Classes

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

C C

CC213

nooog

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

C/C++ - 字符串与字符串函数

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

Microsoft Word - 第3章.doc

CHAPTER 1

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

個 人 的 手, 拉 著 瞎 子 的 手 把 他 帶 往 村 外 的 時 候, 對 於 瞎 子 來 講, 那 個 人 的 手 和 耶 穌 的 手 有 沒 有 區 別? 沒 有! 為 什 麼 沒 有 區 別? 因 為 對 於 一 個 瞎 子 來 說, 手 和 耳 朵 就 是 他 接 觸 世 界, 瞭

untitled

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

untitled

untitled

IO

C/C++ - 函数

《大话设计模式》第一章

Microsoft Word - ch04三校.doc

Ps22Pdf

ebook39-5

第一章 章标题-F2 上空24,下空24

华恒家庭网关方案

C/C++语言 - C/C++数据

Chapter 9: Objects and Classes

概述

C/C++ - 字符输入输出和字符确认

ebook15-10

C/C++ 语言 - 循环

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

第2章 递归与分治策略

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

A.doc

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

untitled

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

C/C++语言 - 运算符、表达式和语句

Microsoft Word cppFinalSolution.doc

CHAPTER VC#

51 C 51 isp 10 C PCB C C C C KEIL

2

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

untitled

プログラムの設計と実現II

,,,,,,,,,, ( http: \ \ www. ncre. cn,, ) 30,,,,,,,, C : C : : 19 : : : /16 : : 96 : : : ISBN 7

untitled

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

C/C++ - 数组与指针

untitled

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

C++ 程式設計

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

C/C++ - 结构体、共用体、枚举体

Strings

Microsoft Word - CIN-DLL.doc

Strings

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

untitled

3.1 num = 3 ch = 'C' 2

[剑指offer] 面试题43:n个骰子的点数(Java),[剑指offer] 面试题42: 翻转单词顺序 VS左旋转字符串(Java),[剑指offer] 面试题41:和为s的两个数字VS和为s的连续序列

Microsoft Word - CPE考生使用手冊 docx

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B






Transcription:

3 C++ 3.1 3.2 3.3 3.4 new delete 3.5 this 3.6 3.7

3.1

3.1 class struct union struct union C class C++ C++

3.1 3.1 #include <alloc.h> struct STRING { typedef char *CHARPTR; // CHARPTR s; // int strlen( ); // STRING(CHARPTR); // ~STRING( ); // }; int STRING::strlen( ) // :: { for(int k =0; s[k]!=0; k++); return k; }

3.1 STRING::STRING(char *t) // :: { for(int k =0; t[k]!=0; k++); s=(char *)malloc(k+1); for(k=0; (s[k]=t[k])!=0; k++); } STRING::~STRING( ) { free(s); }// :: struct STRING x("simple"); void main( ){ STRING y("complex"), *z=&y; int m=y.strlen( ); m=z->strlen( ); }

3.1., ->,.*, ->*, :: ::

3.1 exit exit main abort abort main return return void main( ){ ; if (error) return; ;} abort exit

3.1 Unix, Windows

3.1 3.3 #include <string.h> #include <alloc.h> #include <iostream.h> struct STRING{ char *s; STRING(char *); ~STRING( ); }; STRING::STRING(char *t){ s=(char *)malloc(strlen(t)+1); strcpy(s,t); cout<<"construct: "<<s; }

3.1 STRING::~STRING( ){ if(s==0) return; // s1 cout<<"deconstruct: "<<s; free(s); s=0; // } void main(void){ STRING s1("string varible 1\n"); STRING s2("string varible 2\n"); STRING("Constant\n"); cout<< "RETURN\n"; }

3.1

3.1

3.2 private: C protected: C public: ( C )

3.2 class private struct union public( C )

3.2 3.4 FEMALE class FEMALE{ // private int age; // public: // public typedef char *NAME;// protected: // protected NAME nickname;// NAME getnickname( ); public: // public NAME name; // };

3.2

3.3 inline 2 ( ) ( ) ( )

3.3 3.7 class COMPLEX{ double r, v; public: COMPLEX(double rp, double vp){ r=rp; v=vp; } // inline double getr( ); //inline double getv( ); }; inline double COMPLEX::getv( ){return v; } // void main(void){ COMPLEX c(3, 4); double r=c.getr( ); //getr double v=c.getv( ); // } inline double COMPLEX::getr( ){ return r; } //

3.3 3.8 #include <iostream.h> struct{// ( ) random int x; int random( ) { return x=(23*x+19)%101; } }r={1}; void main(void){ for(int i=0; i<8; i++)cout<<r.random( )<<"\n"; }

3.3 C++ C static #include <iostream.h> static union { int x, y, z; }; int y=5; // : y void main(void){ x=3; cout<<y; // 3} static int x; static int &y=x; static int &z=x; X,y,z

3.3 3.10

3.3 class struct union <long: char, short, int, enum

3.3 3.11 #include <iostream.h> enum ALPHA{a, b, c, d}; class SWITCH{// 28 4 int power:3; int water:5; int gas:5; int oil:6; int start:1; int alarm:3; ALPHA stop:1; int manual:4; };

3.3 union STATE{// 9 2 int speed:9;// speed unsigned run:2; }; void main(void){ cout<<"the size of int is "<<sizeof(int)<<" bytes\n"; cout<<"the size of SWITCH is "<<sizeof(switch)<<" bytes\n"; cout<<"the size of STATE is "<<sizeof(state)<<" bytes\n"; }

3.4 new delete malloc new free delete malloc 0 new malloc free delete free new malloc delete free

3.4 new delete new < > int *p=new int; int *q=new int[20]; delete < > delete p; delete [ ]< > delete [ ]q; delete < >

3.4 new delete 3.12 #include <alloc.h> #include <process.h> class ARRAY{ //class private int *a, r, c; // a r c private public: // public ARRAY(int x, int y); // public ~ARRAY( ); }; ARRAY::ARRAY(int x, int y){ a=new int[(r=x)*(c=y)];// malloc int }

3.4 new delete ARRAY::~ARRAY( ){ //a int if(a){ delete []a; a=0;}// free, delete a } ARRAY x(3, 5); void main(void) { int error=0; ARRAY y(3, 5), *p; p=new ARRAY(5, 7); // malloc ARRAY delete p; // free ARRAY }

3.4 new delete p a r.c=35 p a=null r=5 r=0 c=7 c=0 (a) p=new ARRAY(5,7) (b) p=(array*)malloc(sizeof(array)) p p r.c=35 (c) delete p (d) free (p)

3.4 new delete 3.13 new int (*)[10][20]=int[x][10][20] #include <iostream.h> class A{ //A int i; public: A(int x) { i=x; } // A(int x) A( ) A( ) { i=0; } // };

3.4 new delete void main(void){ int x(3); // int x=3 int *m=new int(5); // m=new int; *m=5 int *n=new int[x]; int (*p)[10]=new int[x][10]; int (*q)[10][20]=new int[x][10][20]; A *r=new A(5); // A(int) A *s=new A[x]; // A( ) A (*t)[10]=new A[x][10]; // A( ) A (*u)[10][20]=new A[x][10][20]; // A( ) } //delete m,n,p,q,r,s,t,u

3.4 new delete new 3.14 STRING STRING x ("Hello!"); x. ~STRING ( ); new (&x) STRING ("The World");

3.5 this this this const this++ this= *this const volatile

3.5 this 3.15 #include <iostream.h> class TREE{ int value; TREE *left, *right; public: TREE (int); ~TREE( ); TREE *find(int); }; TREE::TREE(int value){ // this this->value=value; // TREE::value=value left=right=0; //C++ NULL 0 }

3.5 this TREE::~TREE( ){//this if(left) { delete left; left=0; } if(right) { delete right; right=0; } } TREE* TREE::find(int v){ //this if(v==value) return this; //this if(v<value) //, this=left return left!=0?left->find(v):0; return right!=0?right->find(v):0; // }

3.6 new {} C

3.6 3.16 class A{ int a; public: A(int x) { a=x;} A( ){ a=0; } }; class B{ const int b; // int c, &d, e, f; //b,d,g,h A g, h; // b, c, d, e, f, g, h public: // B h h A( ) B(int y): d(c), c(y), g(y),b(y), e(y){ c+=y; f=y; }//f y }; void main(void){ int x(5); //int x=5 int x(5) A a(x), y=5; //A y=5 A y(5) B b(7), z=(7,8); //B z=(7,8) B z(8) }

3.6 3.18 class A{// ( ) int a; public: A( ); // A(int x); // A(int x, int y); // }; class B{ int b; } //

3.6 void main(void){ A a[6]={3,(4,5),a(6),a(7,8),a( )};// A *b=new A[4]; // B c, *d=new B[4]; // C++ delete [ ]b; delete [ ]d; }

3.7 X sizeof(x) X MOV EAX, X X 4

3.7 3.19 #include <iostream.h> struct MESSAGE{ char flag; // int size; // char buff[255];// long sum; // }; void main(void) { cout<<"size of single word is "<<sizeof(int); cout<<"size of double word is "<<sizeof(long); cout<<"\nsize of Message is: "<<sizeof(message); }

3.7 sizeof(int)=2, sizeof(long)=4: sizeof(message)=1+2+255+4=302 size( ) MESSAGE 0 flag 1 size sizeof(int) size buff sizeof(char) buff 259 1 sum 4 sizeof(message)=1+1+2+255+1+4=304