Absolute C++ (4th Edition) part 4

Absolute C++ (4th Edition) part 4. 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. . | Console Input Output 3i If price has the value the output might be The price is or it might be The price is or it might be output in the following notation which was explained in the subsection entitled Literals The price is It is extremely unlikely that the output will be the following however even though this is the format that makes the most sense The price is To ensure that the output is in the form you want your program should contain some sort of instructions that tell the computer how to output the numbers. There is a magic formula that you can insert in your program to cause numbers magic that contain a decimal point such as numbers of type double to be output in everyday foroiuta notation with the exact number of digits after the decimal point that you specify. If you want two digits after the decimal point use the following magic formula ios fixed ios showpoint 2 If you insert the preceding three statements in your program then any cout statements outputting that follow these statements will output values of any floating-point type in ordinary money notation with exactly two digits after the decimal point. For example suppose the fol- amounts lowing cout statement appears somewhere after this magic formula and suppose the value of price is . cout The price is price endl The output will then be as follows The price is You may use any other nonnegative whole number in place of 2 to specify a different number of digits after the decimal point. You can even use a variable of type int in place of the 2. We will explain this magic formula in detail in Chapter 12. For now you should think of this magic formula as one long instruction that tells the computer how you want it to output numbers that contain a decimal point. 32 C Basics If you wish to change the number of digits after the decimal point so that different values in your program are output with different numbers of digits

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
463    18    1    24-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.