Click here to load reader
Upload
steffi
View
109
Download
0
Embed Size (px)
DESCRIPTION
第二章 C++ 语言基础. 面向对象程序设计. 本章内容提要. C++ 的概述 C++ 程序的基本要素 C++ 数据类型 变量的作用域与存储类型 控制语句 函数 编译预处理指令. 本章内容提要(第 1 节). 1 、主要特点; 2 、 C++ 程序与 C 程序; 3 、 C++ 的扩充; 4 、在 VC 下编制 C++ 程序;. C++ 的概述 C++ 程序的基本要素 C++ 数据类型 变量的作用域与存储类型 控制语句 函数 编译预处理指令. 本章内容提要(第 2 节). C++ 的概述 C++ 程序的基本要素 C++ 数据类型 - PowerPoint PPT Presentation
Citation preview
C++
C++C++C++
1C++C++C++12C++C3C++4VCC++
2C++C++C++1234
3C++C++C++12const345678typedef
4C++C++C++1234
5C++C++C++123
6C++C++C++1234
7C++C++C++1#include2#define3
C++C++
C++C++ C++CCC++CC++C++Visual C++C++ BuilderBorland C++IBMVisualAge C++
C++CC++
C++C++ C/*C: simple.c */#include void main(void){printf( Hello World !\n ) ; /**/}
C++CC++
C++C++ C++// C++simple.cpp#include void main(void){cout
C++CC++
C++C++ 1.C++C2.CCC++CPP3.C/**/ C++// 4.Cstdio.hC++iostream.h
CC++?C++
C++C++ cc++cc++c++c+c++cCC++C++
C++C++
C++C++ C++ main()
C++
C++C++ #include void main(){int math, chem, phy, ave;
coutmath>>chem>>phy;ave=(math+chem+phy)/3.0+0.5;
if (ave>=90)cout
C++C++
C++C++ ,\{}///**/
C++CC++
C++C++ 1CC++C++
: int Max(int a, int b) {}; //C++,C int Max(a, b) //C++C int a; int b; {}
C++CC++
C++C++ 2C{}C++
3C++newdeleteCmalloc()free()
C++CC++
C++C++ 4C++C5C++iostream.hCstdio>>
C++
C++C++ #include
void main(void){ cout
Visual C++C++
Visual C++C++
Visual C++C++
Visual C++C++
Visual C++C++
Visual C++C++
C++
C++C++ 1C++
2Hello worldMFC
3C++()
C++
C++C++ #include using namespace std;void main(){std::cout
iostreamiostream.hC++
C++C++ #include using namespace std; C++ #include C,. iostream98C++iostream.hVC7DevC++.h) .
cout, cin, cerr , clogC++
C++C++ cout;cin ;cerr ; clog ; cerrcoutcerrcoutcerrcoutendl cerrclog cout
C:\>test.exe > a.txtC++
C++C++ #include int main(){ cout
\nendlC++
C++C++ \nendliostreamendl C++ cout
I/O #include 1) a)setprecision(n) 6 b)setprecision(n)+setiosflags(ios::fixed) c)setprecision(n)+setiosflags(ios::scientific) 2)setw(n) 3) dec() octhex4) setfill(')+setw(n) 5) setiosflags(ios::left) setiosflags(ios::right) () 6) setiosflags(ios::showpoint) setiosflags(ios::showpos) C++
C++C++
C++ C++C++
C++
C++
C++
C++
C++ GetPersonCounts() get_person_counts()xysumlengthAreaMyfunm_xPosCPersonperson1
C++C++CC++C++
C++
C++ autoboolbreakcasecharclassconstcontinuedefaultdeletedodoubleelseenumexternfalsefloatforfriendgotoifinlineintlongnewoperatorprivateprotectedpublicreturnshortsignedsizeofstaticstructswitchtemplatethistruetrytypedefunionunsignedusingvirtualvoidwhile
constC++
C++
C++
[=] [=]
int x; float radius=123.56f; int x, y=100;C++
C++
C++
C++1int a=12;a += a - = a*a; //a2642:x>y?x:u>v?u:v x>y?x:(u>v?u:v)3unary ++++a;C++
C++
C++
int i=3; int b=(++i)+(++i)+(++i);VC16TC3015C++
C++
C++
C++C++ 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=123C++C++
C++
int iIndex = 0;C++C++
C++
int iIndex; iIndex = 0;
constconstconstconst const int size=20;constC++C++
C++
[]
C++C++
C++
[]
C++C++C++C++
C++
float grade[3]={90.0, 75.0, 85.0};
0int a[2][3]={2, 4, 6};
C++C++
C++
C++?\0\0C++\0C++C++
C++
char s[ ]="Hello";s[0]=Hs[1]=es[2]=ls[3]=ls[4]=os[5]=\0 65C++C++
C++
\\""Please enter \"good\""Please enter "good"
char* ps="Hello";C++C++
C++
C++//c++#include #include
using namespace std;void main(){string str="I am a student.";
cout
C++C++
C++
struct { . . . }struct Staff {intID;charname[20];bool sex;float salary; }; C++C++
C++
Staff emp1;Staff emp2= {110105, "LiMing", true, 3809.80 };
emp1=emp2;emp1.ID=110108;strcpy(emp1.name, "WangPing");
Staff *pEmp = &emp1;pEmp->sex = false;C++C++
C++
4#include struct student { char name[20];int score[4];int average;};
void main(void){student stu; int i, sum=0;coutstu.name;cout
C++C++
C++
enumC++C++
C++
enum { } enum Color{ Red, Green, Blue };Color MyColor ; MyColor = Green;C++1021enum Color{Red = -1, Green, Blue =3};C++C++
C++
typedeftypedef typedef
typedefC++C++
C++
typedef typedef int INTEGER;typedef unsigned char BYTE;typedef struct tagDate {int year;int month;int day;} DATE;
INTEGER() intINTEGER i ;C++C++
C++
int a=2, b=3;int c=2ab;
char mych; mych=A;
mainC++C++
C++
nnn
C++C++C++C++
(main)C++C++C++
void Myfun(int x){int y=3; {int z=x+y; . . . }int k; . . .}C++C++C++
. . . int x=1; static double y=1.0;
void Myfun(){. . . }. . . C++C++C++
void main(){int a=20;int a=10;}void main(){int a=20;{int a=10;}}
()(static)C++C++C++
register ()staticC++C++C++
newdeleteC++C++C++
autoregisterexternstatic
auto int a ; // astatic float b, c ; // bcC++C++C++
autoregisterautoregisterexternstaticexternstaticautoexternC++C++C++
C++C++C++
staticC++C++C++
::C++::
int amount=123; void main(){int amount=456;cout
C++C++C++
Cmalloc()free()C++newdelete
new p = new [size] ;
C++C++C++
newint* pNum=new int;float* px=new float;char* pBuffer=new char[256];int* pa=new int[100];pi=new int(555); // pi = new int[555]C++C++C++
deletenew//int *p = new int;delete p ;//int *p = new int[5];delete [ ] pa ;C++C++C++
C++ C++C++C++
if
if()elseC++C++C++
if ifelse if. . . . . . else ifelseC++C++C++
C++C++C++
if (ave>=90){cout
switchswitch{ case break. . . . . . case break default}C++C++C++
switchswitch
C++C++C++
forwhiledo-whileC++C++C++
forfor
2132forC++C++C++
char ch;int off = 'A'-'a';do {ch = cin.get();
if(ch>='a' && ch
if() {}else {}C++C++C++
for(;;) {}do {}while();while() {}
reference& & = C++C++C++
& =
intActualIntint &OtherInt = ActualIntC++C++C++
void main(void){int i=10;int &r=i; r++;cout
C++C++C++
void swap(int& x, int& y){int temp=x;x=y;y=temp;}
void main(){int a=20, b=40;swap(a, b);cout
C++C++C++C++
(){}C++C++C++
sum()xyint Sum(int x , int y){int temp;temp=x+y;return temp;}C++C++C++
int Sum(int x, int y) {return x+y;}void main(){int a=2, b=3;int c = Sum(a, b);}C++C++C++
------------------------C++C++C++
C++C++C++
constconst
C++
C++C++C++
staticexternC++C++C++
C++
void MyFun(int val=10){cout
// void fun1(int w, int x=1, int y=1, int z=1)
// void fun2(int w=1, int x=2, int y=3, int z)
// void fun3(int w=1, int x=2, int y, int z=3)
C++C++C++
void fun1(int w, int x=1, int y=1, int z=1)// fun1(10, 3, 1, 1)fun1(10, 3)// fun1(10, 3, 5, 1)fun1(10, 3, 5) // fun1(10, , 5)C++C++C++
C++inlineC++C++C++
inlineC++C++C++
sum()
inline int sum(int x , int y){return x+y;}C++C++C++
#C++C++C++C++
#include#defineC++C++C++
#include
#include #include ""C++C++C++
#include
#include #include ""C++C++C++
#define
#define C++C++C++
#define
#define MAX(a , b) ( (a)>(b) ? (a):(b) ) main(){cout
C++C++C++
#define MUL(a,b) a*bc=MUL(1+2, 3+4); //?constC++C++C++
#undef C++C++C++
C++if#if#ifdef#ifndef#else#endifC++C++C++
#if [#else] #endif,,#ifdef [#else] #endif,,#ifndef [#else] #endif,,C++C++C++
#define USER 11
void main(){#if USER>10cout
#define USER
void main(){#ifdef USERcout
#define USER
void main(){#ifndef USERcout
#include int MAX=100;
main(){int a=0;#if MAX>99cout
#ifdef C++C++C++
float x double
const float EPS = 0.00001;if ((x >= - EPS) && (x =
F9F5watch
F10F11
//ct //pArr//pMax, pMinvoid GetMaxMinVal(int ct, int *pArr, int *pMax, int *pMin);
2-432-442-462-532-602-672-712-772-792-802-812-83
1void Int2Str(int n, char *pArr);
(23)456( )/()/( )/( )/() 718,4 800 ---1130 200---530 600----930 800 ---1130 200---530