Tải bản đầy đủ (.pdf) (122 trang)

Giới thiệu môn học ngôn ngữ lập trình c

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (15.02 MB, 122 trang )

C++ language
Từ Trung Hiếu


overview




the mixed language
the superset of C
the subset of Visual C++


principles
C program elements
are functions and variables

C++ program elements
are objects


comments



line comment
block comment


operators










bitwise: & ^ | ~ >> <<
arithmetic: + - * / %
relational: > >= < <= == !=
logical: && || !
conditional: ?:
comma: ,
selector: * & -> . []


control statements





condition: if, switch
loop: for, while, do..while
jump: goto, return, break, continue
block: {}


common functions





string: strcpy, strcat, strlen, strcmp
math: cos, sin, pow, sqrt, exp, log, rand
file: fopen, fclose, feof, fseek, ftell


comon libraries








string : both C and C++
memory : both C and C++
stdlib : both C and C++
stdio : both C and C++
conio : both C and C++
math: both C and C++
iostream: native to C++


native to C++







the pointer this
the type reference
the concept class
the keyword friend
levels of hidding


Object Oriented Programming
with C++
Từ Trung Hiếu


prerequisites



C language
Using Internet Services (search, email)


tools


One of these







Microsoft Visual C++
Turbo C++
Borland C++

Other tools




mspaint
ie
WinRAR


Using Turbo C++







starting the tools
create a new file
save the file
compile the file

run the file
and see the result


Using Microsoft Visual C++







project is a collections of file
start the tool
project
create a new project
create a file
compile the file
insert / delete files from project


references


Microsoft MSDN with keywords






C language reference
C++ language references

Turbo C++ Help


recommended books




Phạm Văn Ất - C++ và lập trình
hướng đối tượng
Nguyễn Cẩn - Tự học ngơn ngữ lập
trình C++


recommended links


google search






keyword: object oriented programming
keyword: c++ programming
filetype: pdf, ppt, all


some recommended links


class declaration
Từ Trung Hiếu


contents







structure with member functions
inline and external definitions
standalone and member functions
declaration vs definition
levels of hidding
interface vs implementation


contents (1)








constructor
destructor
the pointer this
array of objects (initials)
dynamic object: new, delete, *, ->
array of dynamic objects: new / delete


From c struct to c++ struct
• Function as member
struct SinhVien {

char Ten[50];
int NamSinh;
double dk1, dk2;
int Tuoi() { NamSinh - getCurYear(); }
double DTB() { return (dk1+dk2)/2; }
};


From c++ struct to c++ class
class SinhVien {
private:
char Ten[50];
int ns;
double dk1, dk2;
public:
int Tuoi() { ns - getCurYear(); }

double DTB() { return (dk1+dk2)/2; }
};


standalone and member
functions






standalone functions belong to no class,
eg cos, sin, printf, scanf,
member functions belong to a specific
class, eg
the definition of member functions has
a LITTLE different from that of
standalone ones


the syntax
class Name {
data-member declarations;
member-function declaration;
member-function definitions;
};


declaration vs definition





declaration tells the existence, the type
or the prototypes of the object
definition gives the meaning or the
semantics of the objects


×