C++
This presentation is the property of its rightful owner.
Sponsored Links
1 / 158

C++ 是一门混合型面向对象程序设计语言,它兼容了 C 语言并弥补了其缺陷,增加了面身对象的能力。其中,改造后的 C 语言是面向对象部分的基础。 PowerPoint PPT Presentation


  • 85 Views
  • Uploaded on
  • Presentation posted in: General

C++ 是一门混合型面向对象程序设计语言,它兼容了 C 语言并弥补了其缺陷,增加了面身对象的能力。其中,改造后的 C 语言是面向对象部分的基础。. 概述. 一般语法的改进 指针和引用 函数的改进 类和对象 构造函数和析构函数. C++ 语言是一种高级程序设计语言,它的开发过程与其他高级语言程序开发过程类似,一般要经过四个步骤:. 2.1 C++ 程序的开发过程. 编辑. 编译. 链接. 执行. 编辑

Download Presentation

C++ 是一门混合型面向对象程序设计语言,它兼容了 C 语言并弥补了其缺陷,增加了面身对象的能力。其中,改造后的 C 语言是面向对象部分的基础。

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


C c c

C++CC


2 1 c

C++

2.1 C++


2 1 c1

C++Borland C++, Visual C++, Turbo C++ C++.CPP

C++OBJ

2.1 C++


2 1 c2

.obj.lib.exe

2.1 C++


2 1 c3

2.1 C++


2 1 c4

C++

1

2

3

4

2.1 C++


2 1 c5

C++

1.

C++C++

2.

#C++

2.1 C++


Include

#include#include

#include <>

#include ""

Include#include

2.1 C++

#include


Include1

#include

C++h#include

2.1 C++

#include


Define

2.1 C++

#define

  • C++#define

    #define <> <>


C c c

2.1 C++

#define MAXLENGTH 100

. . . . . .

int nArray[MAXLENGTH];

for(int i=0; i< MAXLENGTH; i++)

. . . . . .

MAXLENGTH100


C c c

2.1 C++

#define

#define <>(12n) <()>

#define MAX(a , b) ( (a)>(b) ? (a):(b) )

main()

{

cout<<MAX(10 , 11)<<endl;

}


C c c

2.1 C++

const

#undef <>


2 1 c6

3.

1

float a, b, c;

sum

int sum = 0;

2.1 C++


2 1 c7

2

3

C++9 ~

2.1 C++


2 1 c8

if ~ else

for ~

while ~

do ~ while

continue

break(switch)

switch

goto

return

2.1 C++


2 1 c9

4

{}

if ( a>b )

{ c = a - b;

d = c * a;

}

else

{ c = a + b;

d = c * b;

}

2.1 C++


C c c

C

2.2

C

C++


C c c

C

/*C: simple.c */

#include <stdio.h>

void main(void)

{

printf( " Hello World !\n " ) ; //

}

C++


C c c

C++

// C++simple.cpp

#include <iostream.h>

void main(void)

{

cout<<" Hello World !\n "; //

}

Hello World !


C c c

2.2


C c c

2.2

C++

int Bval = 1024;

string project = " BeiJing2008";

int Bval( 1024 );

string project("BeiJing2008 " );

ival 1024 project BeiJing2008


C c c

2.2


C c c

2.2

C

C++


C c c

2.2

int x;

float y;

y=(float)x;

  • C

  • ()

int i=int(1.35);


C c c

2.2

enum traffic {red,green,yellow};

struct student{

int num;

char name[20];};

traffic Light;

student stu1;

!structenum


C c c

  • structureID


C c c

struct <> {

<> <1>

<> <2>

. . . . . .

<> <n>

}


C c c

struct staffer {

intID;

charname[20];

bool sex;

float salary;

};

<> <>

. . .


C c c

staffer

staffer employee1;

staffer employee1= {110105, "LiMing", 1, 3809.80 };


C c c

  • .

    <>.<>

    . . .


C c c

employee1=employee2;//

employee1.ID=110108;//

strcpy(employee1.name, "WangPing"); //

->

<> -> <>

. . .


C c c

->

staffer* pStaff=&employee1; //

pStaff ->ID=110115; //

strcpy(pStaff ->name, "WangPing"); //

4

#include <iostream.h>

struct student{//

charname[20];

intscore[4];

intaverage;

};


C c c

void main(void)

{

student stu;//

int i, sum=0;

cout<<"Enter name:";

cin>>stu.name;//

cout<<"Enter four scores :";

for(i=0; i<4; i++)

cin>>stu.score[i];// 4

for(i=0; i<4; i++)

sum+=stu.score[i];//

stu.average=sum/4;

cout<<"The average score of "<<stu.name

<<" is:"<<stu.average<<'\n'; //

}


C c c

  • enum

  • enum <> { <1><2>

    <n> }

  • C++1021


C c c

  • enum Color{Red, Green, Blue};

  • [enum]Color MyColor ;

  • MyColor = Green;

  • enum Color{Red = -1, Green, Blue =3};


Typedef

typedef

typedef

typedef

typedef <> <>

intfloatchar

typedef


C c c

typedef int INTEGER;

typedef unsigned char BYTE;

typedef struct tagDate {

int year;

int month;

int day;

} DATE;

INTEGER() int

INTEGER i ;


C c c

2.3

  • C++C++

  • charintfloatdoublevoid

  • C++

  • voidsignedunsignedshortlong


C c c

()

char

8

int

32

float

32

double

64

void

0

unsigned [int]

16

short [int]

16

long [int]

32

C++


C c c

int num, total;

float v, r, h;

int a=3; // int a(3);

char c=A;

long lx=12345678;

unsigned int nWidth;

( )

float x=123.56;

int i=(int)x;// i=123


C c c

2.3

C++ has a set of fundamental types corresponding to the most common basic storage units of a computer and the most common ways of using them to hold data:

  • A Boolean type (bool)

  • Character types (such as char)

  • Integer types (such as int)

  • Floating point types (such as float)

Bjarne Stroustrup AT&T Labs


C c c

2.3

In addition, a user can define

Enumeration types for representing specific sets of values (enum)

There also is a type, void, used to signify the absence of information

Bjarne Stroustrup AT&T Labs


C c c

2.3

From these types, we can construct other types:

  • Pointer types (such as int *)

  • Array types (such as char [])

  • Reference types (such as double &)

  • Data structures and classes

For most applications, one could simply use boolfor logical values, charfor characters, intfor integer values, and doublefor floating point values. The remaining fundamental types are variations for optimizations and special needs that are best ignored until such needs arise.

Bjarne Stroustrup AT&T Labs


C c c

2.3

  • Specifiers

Specifiers modify the meanings of the basic built-in types and expand them to a much larger set. There are four specifiers: long, short, signed, and unsigned.

long and short modify the maximum and minimum values that a data type will hold. A plain int must be at least the size of a short. The size hierarchy for integral types is: shortint, int, longint.

The size hierarchy for floating point numbers is: float, double, and longdouble. Long float is not a legal type. There are no short floating-point

Thinking in C++


C c c

2.3

  • Specifiers

The signed and unsigned specifiers tell the compiler how to use the sign bit with integral types and characters (floating-point numbers always contain a sign). An unsigned number does not keep track of the sign and thus has an extra bit available, so it can store positive numbers twice as large as the positive numbers that can be stored in a signed number. signed is the default and is only necessary with char; char may or may not default to signed. By specifying signedchar, you force the sign bit to be used.

Thinking in C++


C c c

<> <>[]

<> <>[] []

. . .


Float score 30 score 30 float int array 12 4 array 12 4 int

float score[30]; // score30floatint Array[12][4]; // Array124int

<>[]

<>[] []


C c c

  • 01score[0]score[1]score[29]

  • C++C++


C c c

  • float grade[3]={90.0, 75.0, 85.0};

  • int a[2][3]={2, 4, 6, 8, 10, 12}; //

    int a[2][3]={{2, 4, 6},{8, 10, 12}};//

    246a[0]a[0][0]a[0][1]a[0][2]


C c c

  • 0

    int a[2][3]={2, 4, 6};

  • float grade[ ] = {90.0, 75.0, 85.0};

    int a[ ][3] = {{2, 4, 6},{8, 10, 12}};


C c c

10


C c c

#include <iostream.h>

void main()

{

int i;

float score[10];

cout<<"Please enter 10 scores: ";

for(i=0; i<10; i++)

cin>>score[i];//

cout<<"The scores in reverse order are: ";

for(i=9; i>=0; i--)

cout<<score[i]<<' ';//

cout<<'\n';

}


C c c

2.3

  • (Pointer)

<> * <>

*

int* pointer ;

int *pointer ; //


C c c

  • *

  • *

  • *


C c c

#include <iostream.h>

void main()

{

int a, b, *pa, *pb;

a=10; b=20;

pa=&a; pb=&b;

cout<<*pa<<','<<*pb<<'\n';

pa=&b; pb=&a;cout<<*pa<<','<<*pb<<'\n';

*pa=100; *pb=200;cout<<a<<','<<b<<'\n';

}

// paapbb

// pabpba

// ba


C c c

1020

2010

200100

int a, b;

int *pa=&a, *pb=&b;


C c c


C c c

int a[ ]={2, 4, 6, 8, 10};


C c c

#include <iostream.h>

void main()

{

int a[ ]={2, 4, 6, 8, 10};

int* pa=a;// pa=&a[0]

int result=0;

for(int i=0; i<5; i++)

{

result+=*pa; //

pa++;//

}

cout<<"result="<<result<<'\n';

}


C c c

2.3

  • (Pointer&Reference)

<>* <>;

<>& <>=<>;


C c c

int int1;

int &rint=int1;

2.3

  • (Reference)


C c c

.

&:

& =;

:int b;

int &a=b;

abbababab


C c c

int ival = 1024;

int &refVal = ival;

refVal += 2;

2.3

  • (Reference)

All operations on the reference are actually applied to the object to which the reference refers, including the address-of operator. For example:

adds 2 to ival, the object referred to by refVal.

C++ Primer


C c c

2.3

  • (Reference)

#include<iostream.h>

void main()

{

int num=50;

int& ref=num;

ref+=10;

cout<<"num="<<num<<endl;

cout<<"ref="<<ref<<endl;

num+=40;

cout<<"num="<<num<<endl;

cout<<"ref="<<ref<<endl;

}


C c c

1&

2

3

4


C c c

2.3

  • (Reference)

#include<iostream.h>

void main()

{

int num;

int& ref=num;

num=5;

cout<<"num="<<num<<endl;

cout<<"ref="<<ref<<endl;

cout<<"&num="<<&num<<endl;

cout<<"&ref="<<&ref<<endl;

}


C c c

int ival = 1024;

// ok: refVal is a reference to ival

int &refVal = ival;

// error: a reference must be //initializedto an object

int &refVal2;

2.3

  • (Reference)


C c c

int &a[5];

int &*p; //

int *a;

int *&p=a;

int b;

p=&b;

2.3

  • (Reference)


C c c

5)


C c c

6)

int num=50;

int &ref=num;

int *p=&ref;

7)

int num=50;

int &ref1=num;

int &ref2=ref1;

ref2=100;

2.10


C c c

8)

2.10

void swap(int & rx,int & ry)

{

int temp=rx;

rx=ry;

ry=temp;

}


C c c

2.3

  • (Reference)

#include<iostream>

using namespace std;

void swap(int & x,int & y);

void main()

{

int x=5,y=6;

cout<<"before swap,x:"<<x<<",y:"<<y<<endl;

swap(x,y);

cout<<"after swap,x:"<<x<<",y:"<<y;

}


C c c

9) ,

int *p=null;

int num=10;

int &ref=null; //

int &ref=num;

2.10


C c c

10)

: P27 2.82.9

2.10


C c c

2.3

  • +-*/%++()=+=->&&<<=newdelete


C c c

1

.->

::

*

&

newdelete

!

++--

( )

sizeof

3

*/%

4

+-

2.3

22


C c c

5

<<=>>=

6

==!=

7

&&

9

? :

11

10

,

=+=-=*=/=

2.3

8

| |


X y area pi radius radius a b x y

x+yarea=PI*radius*radius(a>b) && (x<=y)


C c c

1

#include <iostream.h>

void main()

{

char x,y;

int n;

x='a';

y='b';

n=x<y;

cout<<n<<endl;

n=y==x+1;

cout<<n<<endl;

n=(x<y)&&(y==x+1)+5;

cout<<n<<endl;

}


C c c

2

#include <iostream.h>

void main()

{

int x,y;

x=3;

y=6;

x+=3;

y*=x;

cout<<"x="<<x<<" y="<<y<<endl;

}


C c c

3

#include <iostream.h>

void main()

{

int a=0,m=3,n=9,k=15,b=5,c=9;

a-=!b||++m>n||c++;

cout<<"\ta="<<a<<"\tb="<<b<<"\tc="<<c<<endl;

cout<<"\tm="<<m<<"\tn="<<n<<"\tk="<<k<<endl;

}


C c c

4

#include <iostream.h>

void main()

{

int x,y,n;

x=y=1;

n=--x&&++y;

cout<<" n="<<n<<" x="<<x<<" y="<<y<<endl;

n=(--x)||(++y);

cout<<" n="<<n<<endl;

cout<<" x="<<x<<" y="<<y<<endl;

}


C c c

5

#include <iostream.h>

void main()

{

int a=1,b=3,c=2,x;

x=(a++,b+=a,c=b+2);

cout<<"x="<<x<<endl;

}


Const

C

#define PI 3.1415926

C++,const

const float PI =3.1415926;

const


C c c

1const

2

3int

4C++

5


C c c

1

const char * pc=abcd;

2

char *const pc=abcd;

pc

pc[3]=x;

pc=dfasdfa


C c c

const char * const pc=abcd;

pc


String

C++string

string


C c c

(::)


C c c

#include <iostream>

using namespace std;

float a=2.4;//

void main()

{

int a=8;//

cout<<a<<endl;

}


C c c

#include <iostream>

using namespace std;

float a=2.4;//

void main()

{

int a=8;//

cout<<a<<endl;

cout<<::a<<endl;

}


C c c

C++namespace


C c c

namespace ns1

{

float a, b, c;

fun1(){.}

}

::

ns1::a ;

ns1::fun1();


C c c

namespace ns1

{

namespace ns2

{

class matrix{}

}

}

matrixn1::n2::matrix


C c c

using

using ns1::ns2::martix

martix,

using namespace

using namespace std

c++std++include


C c c

(Dynamic memory allocation)

2.4

  • newdelete


C c c

(Dynamic memory allocation)

2.4

C

malloc(), calloc()free().

C++


C c c

2.4.1 newdelete

  • new

    = new

    = new [ ]

  • delete

    delete

    delete [ ]

    new


C c c

2.4.1 newdelete

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;


C c c

2.4.1 newdelete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;


C c c

p1

2.4.1 newdelete

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p2


4 5 1 new delete

p1

p2

2.4.1 newdelete

4.5.1 new delete

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p3


4 5 1 new delete1

p1

p2

2.4.1 newdelete

4.5.1 new delete

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p3

p4


4 5 1 new delete2

p2

p1

2.4.1 newdelete

4.5.1 new delete

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p3

p4


4 5 1 new delete3

p2

2.4.1 newdelete

4.5.1 new delete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p3

p4


4 5 1 new delete4

p2

2.4.1 newdelete

4.5.1 new delete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p3

p4


C c c

2.4.1 newdelete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p2

p3

p4


C c c

2.4.1 newdelete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p2

p3

p4


C c c

2.4.1 newdelete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p2

p3

p4


C c c

2.4.1 newdelete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p2

p3

p4


C c c

2.4.1 newdelete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p2

p3

p4


C c c

2.4.1 newdelete

p1

int * p1 = new int ;

char * p2 = new char ;

float * p3 = new float ;

int * p4 = new int [4] ;

delete p1 ;

delete p2 ;

delete p3 ;

delete [] p4 ;

p2

p3

p4


C c c

2.4.1 newdelete

new

#include<iostream.h>

void main()

{ int * p = NULL ;

p = new int ( 89 ) ;//

if ( p == NULL )

{ cout << "allocation failure\n"; return ; }

cout << *p ;

delete p ;

}


C c c

p

2.4.1 newdelete

new

#include<iostream.h>

void main()

{ int * p = NULL ;

p = new int ( 89 ) ;//

if ( p == NULL )

{ cout << "allocation failure\n"; return ; }

cout << *p ;

delete p ;

}


C c c

2.4.1 newdelete

new

p

#include<iostream.h>

void main()

{ int * p = NULL ;

p = new int ( 89 ) ;//

if ( p == NULL )

{ cout << "allocation failure\n"; return ; }

cout << *p ;

delete p ;

}

89


C c c

p

89

new

#include<iostream.h>

void main()

{ int * p = NULL ;

p = new int ( 89 ) ;//

if ( p == NULL )

{ cout << "allocation failure\n"; return ; }

cout << *p ;

delete p ;

}


C c c

p

89

2.4.1 newdelete

new

#include<iostream.h>

void main()

{ int * p = NULL ;

p = new int ( 89 ) ;//

if ( p == NULL )

{ cout << "allocation failure\n"; return ; }

cout << *p ;

delete p ;

}

89


C c c

89

2.4.1 newdelete

new

p

#include<iostream.h>

void main()

{ int * p = NULL ;

p = new int ( 89 ) ;//

if ( p == NULL )

{ cout << "allocation failure\n"; return ; }

cout << *p ;

delete p ;

}

89


C c c

2.4.1 newdelete

new

p

#include<iostream.h>

void main()

{ int * p = NULL ;

p = new int ( 89 ) ;//

if ( p == NULL )

{ cout << "allocation failure\n"; return ; }

cout << *p ;

delete p ;

}

89

89


C c c

2.4.1 newdelete

new

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

p

t

2.4.1 newdelete

new

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

t

2.4.1 newdelete

p

new

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

t

2.4.1 newdelete

p

new

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

|


C c c

i

10

t

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

|


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

|


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 |


C c c

i

10

t

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 |


C c c

i

10

t

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 103 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 103 104 105 106 107 108 109 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 103 104 105 106 107 108 109 |


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation failure\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 103 104 105 106 107 108 109

|


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 103 104 105 106 107 108 109

|


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

100 101 102 103 104 105 106 107 108 109

|


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

i

p


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

10

t

2.4.1 newdelete

p

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}


C c c

i

10

p

2.4.1 newdelete

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

for ( i = 0 ; i < 10 ; i++ )

{ cout << *p << " " ;

p++;

}


C c c

i

10

p

2.4.1 newdelete

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

for ( i = 0 ; i < 10 ; i++ )

{ cout << *p << " " ;

p++;

}

for ( i = 0 ; i < 10 ; p ++ )

cout << *p << " " ;


4 5 1 new delete5

i

10

p

2.4.1 newdelete

4.5.1 new delete

new

100

101

102

103

104

105

106

107

108

109

#include<iostream.h>

void main()

{ int * p = NULL , * t ; int i ;

p = new int [10] ;

if ( p == NULL )

{ cout << "allocation faiulre\n" ; return ; }

for ( i = 0 ; i < 10 ; i ++ )

p[i] = 100 + i ;

cout << endl ;

for ( t = p ; t < p+10 ; t ++ )

cout << *t << " " ;

cout << endl ;

delete [] p ;

}

for ( i = 0 ; i < 10 ; i++ )

{ cout << *p << " " ;

p++;

}


C c c

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

2.4.2 newdelete

( a + b ) 0 = 1

( a + b ) 1 = 1a + 1b

( a + b ) 2 = 1a2 + 2ab + 1b2

( a + b ) 3 = 1a3 +3a2b +3ab2 +1b3

( a + b ) 4 = 1a4 + 4a3b + 6a2b2 + 4ab3 + 1b4


C c c

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

2.4.2 newdelete

  • n n +1

  • n n -1

    F0 = 1

    Fn+1 = 1

    Fi = Fi-1 + Fi


C c c

  • 1

  • 220


C c c

  • 3100

  • 4153135333

  • 5110006

  • 612n


  • Login