TAILIEUCHUNG - Absolute C++ (4th Edition) part 31

Absolute C++ (4th Edition) part 31. 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. . | 304 Operator Overloading Friends and References Display Operator Overloading part 1 of 5 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 35 36 37 38 39 include iostreom include cstdllb lnclude cmath using namespace std Class for amounts of money in . currency class Money public Money Money double amount Money int theDollars int theCents Money int theDollars double getAmount const int getDollars const int getCents const void input Reads the dollar sign as well as the amount number. void output const private int dollars A negative amount is represented as negative dollars and int cents negative cents. Negative is represented as -4 and -50. int dollarspart double amount const This s a unary operator and is int centspart double amount const discussed in the subsection int round double number const Overloading Unary Operators. const Money operator const Money amountl const Money amount2 const Money operator - const Money amountl const Money amount2 bool operator const Money amountl const Money amount2 const Money operator - const Money amount --------- int main For an explanation of a const on a Money yourAmount myAmount 10 9 re rmti ypesee thesuiisection cout Enter an amount of money Refamingbyc nst Vafae. cout Your amount is cout endl cout My amount is cout endl Basic Operator Overloading 305 Display Operator Overloading part 2 of 5 40 41 42 43 if yourAmount myAmount cout We have the same amounts. n else cout One of us is richer. n 44 45 46 Money ourAmount yourAmount myAmount cout cout equals cout endl 47 Money diffAmount yourAmount - myAmount 48 cout - 49 cout equals cout endl 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 return 0- Nofe that we need to use accessor and mutator functions. I const Money operator const Money .

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