TAILIEUCHUNG - Computer Programming for Teens phần 7

Việc bổ sung điều hành (+) đã được lập trình để thêm hai dây cũng như hai con số. Chúng ta nói rằng nhà điều hành này đã được quá tải để làm điều này hoạt động bổ sung. Điều đó có nghĩa là ngôn ngữ có hai được xây dựng trong các chức năng cho việc bổ sung đăng ký làm việc cho số điện thoại được thêm vào và | The String as an Array 191 myWord 0 h myWord 1 e myWord 2 I myWord 3 I myWord 4 o name 0 J name 1 a name 2 m name 3 e name 4 s greeting O h greeting 1 e greeting I greeting 3 I greeting 4 o greeting 5 J greeting 6 a greeting 7 m greeting 8 e greeting 9 s Figure Each of the strings is viewed as an array and the array greeting is seen as a composite of the other two strings. If we want to add an intervening space we need to explicitly add it as in this example greeting myWord name The addition operator has been programmed to add two strings as well as two numbers. We say that this operator has been overloaded to do this additional operation. That means the language has two built-in functions for the addition sign one that works for numbers being added and another that works for strings or characters being added. When the types of the arguments on either side of the sign are read the appropriate function for the sign is executed. As you advance in your programming skills you can learn how to write your own overloaded operators. Remember that the computer will know which function to use it will use the one that corresponds to the data types that match it. See Figure . The workload that the plus sign normally has is to add two numbers. To overload it is to add another job to its workload that of concatenation. 192 Chapter 11 All About Strings Choose Regular Addition Function 12 hello James Choose Other Addition Function helloJames Figure A plus sign is shown with arguments on either side of it. Depending on the arguments present the appropriate function will be used. Here is another example of concatenation String sentence My name is John. Notice that I added a space before each word so that the string will look good when it is printed. cout sentence endl My name is John. String Functions In this section we will use some of the typical string functions in C length substring and find. length is a useful function because it tells you how long your string is.

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.