Tải bản đầy đủ

ngôn ngữ lập trình c++

C++
PROGRAMMING
LANGUAGE
Written by: Phu PHAN
Phone: 0905.566.500


Machine Language
● Only language computer directly understands
● Defined by hardware design
○ Machine-dependent
● Generally consist of strings of numbers
○ Ultimately 0s and 1s
● Instruct computers to perform elementary operations
○ One at a time
● Cumbersome for humans
● Example:
1300042774
1400593419
1200274027



Assembly language
● English-like abbreviations representing elementary
computer operations
● Clearer to humans
● Incomprehensible to computers
○ Translator programs (assemblers)
■ Convert to machine language
● Example:
LOAD BASEPAY
ADD
OVERPAY
STORE GROSSPAY


High-level languages
● Similar to everyday English, use common mathematical
notations
● Single statements accomplish substantial tasks
○ Assembly language requires many instructions to
accomplish simple tasks
● Translator programs (compilers)
○ Convert to machine language
● Interpreter programs
○ Directly execute high-level language programs
● Example:
grossPay = basePay + overTimePay


C Language
● Evolved from two other programming languages
○ BCPL and B
■ “Typeless” languages
● Dennis Ritchie (Bell Laboratories)
○ Added data typing, other features
● Development language of UNIX
● Hardware independent
○ Portable programs
● 1989: ANSI standard
● 1990: ANSI and ISO standard published
○ ANSI/ISO 9899: 1990


C++ Language
● Extension of C
● Early 1980s: Bjarne Stroustrup (Bell Laboratories)
● Provides capabilities for object-oriented programming
○ Objects: reusable software components
■ Model items in real world
○ Object-oriented programs
■ Easy to understand, correct and modify
● Hybrid language
○ C-like style
○ Object-oriented style
○ Both


Java Language
● 1991: Sun Microsystems
○ Green project

● 1995: Sun Microsystems
○ Formally announced Java at trade show






Web pages with dynamic and interactive content
Develop large-scale enterprise applications
Enhance functionality of web servers
Provide applications for consumer devices
○ Cell phones, pagers, personal digital assistants, …


History of Programming Languages


Local Environment
● Text Editor
○ Windows: Notepad, Notepad++, Sublime Text…
○ MacOS: TextEdit, Sublime Text…
● C++ Compiler
○ Windows: Dev C++, MS Visual Studio…
○ MacOS: XCode...


Basic Syntax
• Object
• Class
• Methods
• Instance Variables


C++ Program Structure
#include
using namespace std;
// main() is where program execution begins.
int main() {
cout << "Hello World"; // prints Hello World
return 0;
}


Compile and Execute
● Text Editor
● C++ Compiler


Semicolons and Blocks
• Semicolons
• Blocks


Identifiers
mohd

zara

myname50

abc

move_name

_temp j

a23b9

a_123
retVal


Keywords
asm

else

new

this

auto

enum

operator

throw

bool

explicit

private

true

break

export

protected

try

case

extern

public

typedef

catch

false

register

typeid


Whitespace
Int age;

Fruit = apples + oranges;


Comments
/* This is a comment */

// This is a comment


Printing a Line of Text


Exercises
1. Deploy a program by Compiler IDE
2. Write a program to print: Your Name, Gender, Birthday
3. Write a application print:
*
**
***
****
*****


Homework
1. Write this text: \T\H\I\S\I\S\A\”PENCIL”
2. Research: Write a C++ program to declare two integer. It
then prints these values on the screen.


Data Types
Type

Keyword

Boolean

bool

Character

char

Integer

int

Floating point

float

Double floating point

double


Data Types
● signed
● unsigned
● short
● long


typedef Declarations
typedef type newname;
typedef int feet;
feet distance;


Enumerated Types
enum enum-name { list of names } var-list;
enum color { red, green, blue } c;
c = blue;
enum color { red, green = 5, blue };


Variable Types
• bool
• char
• int
• float
• double
• void
• wchar_t


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×

×