Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Absolute C++ (4th Edition) part 28. 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. . | Constructors 273 Display 7.2 Bank Account Class part5 of 5 161 return static_cast int amount 162 163 Uses cmath 164 int BankAccount centsPart double amount 165 166 double doubleCents amount 100 167 int intCents round fabs doubleCents 100 can misbehave on negatives 168 if amount 0 169 intCents -intCents These could be regular functions rather than member functions 170 return intCents but as member functions we were able to make them private. 171 172 Uses cmath if this does not seem clear see 173 int BankAccount round double number the discussion of round in 174 Chapter 3 Section 3.2. 175 return static_cast int floor number 0.5 176 177 double BankAccount fraction double percent 178 179 return percent 100.0 180 Sample Dialogue accountl initialized as follows Account balance 1345.52 Rate 2.3 account2 initialized as follows Account balance 0.00 Rate 0 accountl reset to the following Account balance 999.99 Rate 5.5 Enter new data for account 2 Enter account balance 100.00 Enter interest rate NO percent sign 10 account2 reset to the following Account balance 100 Rate 10 In one year account2 will grow to Account balance 110 Rate 10 274 Constructors and Other Tools Self-Test Exercises 3. The function BankAccount input in Display 7.2 reads the balance of the account as a value of type double. When the value is stored in the computer s memory in binary form this can create a slight error. It would normally not be noticed and the function is good enough for the demonstration class BankAccount. Spending too much time on numerical analysis would detract from the message at hand. Still this input function is not good enough for banking. Rewrite the function BankAccount input so it reads an amount such as 78.96 as the int 76 and the three char values . 9 and 6 . You can assume the user always enters two digits for the cents in an amount such as 99.00 instead of just 99 and nothing more. Hint The following formula will convert a digit to the corresponding int value such as 6 to 6 .