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

giao trinh tin hoc 9385

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 (195.25 KB, 7 trang )


Chapter 1 – Introduction to C++
Programming
Outline
1. History of C and C++
2. C++ Standard Library
3. Basics of a Typical C++ Environment
4. Introduction to C++ Programming
5. A Simple Program: Printing a Line of Text
6. Another Simple Program: Adding Two Integers
7. Arithmetic
8. Decision Making: Equality and Relational Operators
9. Introduction to Object Technology

 2003 Prentice Hall, Inc. All rights reserved.

1


2

History of C and C++
• History of C
– 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

 2003 Prentice Hall, Inc. All rights reserved.


3

History of C and C++
• History of C++





Extension of C
Early 1980s: Bjarne Stroustrup (Bell Laboratories)
“Spruces up” C
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
 2003 Prentice Hall, Inc. All rights reserved.


4

C++ Standard Library
• C++ programs
– Built from pieces called classes and functions

• C++ standard library
– Rich collections of existing classes and functions

• “Building block approach” to creating programs
– “Software reuse”

 2003 Prentice Hall, Inc. All rights reserved.


String Manipulation Functions of the Stringhandling Library
• Determining string lengths
– size_t strlen( const char *s )
• Returns number of characters in string
– Terminating null character not included in length

 2003 Prentice Hall, Inc. All rights reserved.

47



2
3
5
6
8
10
12
13
14
16
17
18
19
20
21
23
25

48

// Using strlen.
#include <iostream>
using std::cout;
using std::endl;
#include <cstring> // prototype for strlen
int main() {
char *string1 = "abcdefghijklmnopqrstuvwxyz";
char *string2 = "four";
char *string3 = "Boston";

cout << "The length of \"" << string1
<< "\" is " << strlen( string1 )
<< "\nThe length of \"" << string2
<< "\" is " << strlen( string2 )
<< "\nThe length of \"" << string3
<< "\" is " << strlen( string3 ) << endl;
return 0; // indicates successful termination
} // end main

The length of "abcdefghijklmnopqrstuvwxyz" is 26
The length of "four" is 4
The length of "Boston" is 6

 2003 Prentice Hall, Inc.
All rights reserved.



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

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