TAILIEUCHUNG - C++ for Mathematicians An Introduction for Students and Professionals phần 9

một dòng tại một thời điểm, và phá vỡ những đường dây vào các từ riêng lẻ. C + + có hai cách để xử lý các dữ liệu nhân vật: mảng các giá trị char và trong các đối tượng có kiểu string. Các mảng char là một di sản của C + + 's gốc rễ trong ngôn ngữ lập trình C. | C Reference 393 Constants and the keyword const If a variable is declared with a given value and the program never changes that value then the variable should be declared const. For example in a program that uses the Golden Mean we would have this const phi i. sqrt 5. 2. . Arguments to procedures that are not modified by the procedure should be declared const. For example suppose we create a procedure to calculate the sum of the elements in a set of integers. Because such a procedure does not modify the set we declare it such as this long sum const set long S . A third use of the keyword const is to certify that a method does not change the object on which it is invoked. For example if we are creating a LineSegment class a method that reports the length of the segment would not modify the segment. In the header file say we would find this class LineSegment private variables to specify the segment public constructors etc. double length const and in the program file say we find this double LineSegment length const calculate and return the length Arrays If the size of an array can be determined before the program is run it may be declared like this int alpha 20 . However if the size of an array is unknown until the program is running use a dynamically sized array like this int n cout Enter array size cin n int alpha alpha new int n . delete alpha Remember that every array allocated with new should be released with a delete . 394 C for Mathematicians Operations Here we describe the behavior of C s fundamental operations. Remember however that classes can override these meanings . the operator does input when used with cin but its fundamental use is to shift bits . Assignment The statement a b takes the value held in the variable b and places that value in the variable a. Assignment statements can be combined. The statement a b c is equivalent to a b c and the effect is to take the value in c and store that value in

TỪ KHÓA LIÊN QUAN
Đã 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.