Absolute C++ (4th Edition) part 13

Absolute C++ (4th Edition) part 13. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | 122 Function Basics Display A Global Named Constant part 1 of 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Computes the area of a circle and the volume of a sphere. Uses the same radius for both calculations. include iostream include cmath using namespace std const double PI double area double radius Returns the area of a circle with the specified radius. double volume double radius Returns the volume of a sphere with the specified radius. int main double radiusOfBoth areaOfCircle volumeOfSphere cout Enter a radius to use for both a circle n and a sphere in inches cin radiusOfBoth areaOfCircle area radiusOfBoth volumeOfSphere volume radiusOfBoth cout Radius radiusOfBoth inches n Area of circle areaOfCircle square inches n Volume of sphere volumeOfSphere cubic inches n return 0 double area double radius return PI pow radius 2 double volume double radius return PI pow radius 3 Scope Rules 123 Display A Global Named Constant part 2 of 2 Sample Dialogue Enter a radius to use for both a circle and a sphere in inches 2 Radius 2 inches Area of circle square inches Volume of sphere cubic inches Placing all named constant declarations at the start of your program can aid readability even if the named constant is used by only one function. If the named constant might need to be changed in a future version of your program it will be easier to find if it is at the beginning of your program. For example placing the constant declaration for the sales tax rate at the beginning of an accounting program will make it easy to revise the program should the tax rate change. It is possible to declare ordinary variables without the const modifier as global global variables which are accessible to all function definitions in the file. This is done simi- variable lar to the way it is done for global named constants except that the modifier const is not used in the variable declaration. However there .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
476    17    1    27-11-2024
Đã 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.