Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Object oriented programming - Lecture no 21

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

After you have read and studied this chapter, you should be able to: Perform linear and binary search algorithms on small arrays, determine whether a linear or binary search is more effective for a given situation, perform selection and bubble sort algorithms, describe the heapsort algorithm and show how its performance is superior to the other two algorithms, apply basic sorting algorithms to sort an array of objects. | CSC241: Object Oriented Programming Lecture No 21 Previous Lecture Polymorphism Example program person class Virtual destructor base class destructor is virtual, derived class destructor also become virtual Friend functions can access private member of a class Today’s Lecture Friend function example program: Distance class Friend function for functional notation Friend classes static functions Distance Example class Distance { private: int feet; float inches; public: Distance() : feet(0), inches(0.0) { } Distance (float fltfeet) { feet = fltfeet; inches = 12*(fltfeet-feet); } Distance(int ft, float in) : feet(ft), inches(in) { } void showdist() const { cout = 12.0) { i -= 12.0; f++; } return Distance(f,i); } When such constructor exists, following statements are allowed d3 = 15.5; d3 = d1 + 10.0; . | CSC241: Object Oriented Programming Lecture No 21 Previous Lecture Polymorphism Example program person class Virtual destructor base class destructor is virtual, derived class destructor also become virtual Friend functions can access private member of a class Today’s Lecture Friend function example program: Distance class Friend function for functional notation Friend classes static functions Distance Example class Distance { private: int feet; float inches; public: Distance() : feet(0), inches(0.0) { } Distance (float fltfeet) { feet = fltfeet; inches = 12*(fltfeet-feet); } Distance(int ft, float in) : feet(ft), inches(in) { } void showdist() const { cout = 12.0) { i -= 12.0; f++; } return Distance(f,i); } When such constructor exists, following statements are allowed d3 = 15.5; d3 = d1 + 10.0; Cont. d3 = 10.5; 10.5 is passed to one argument constructor, 10.5 is converted into Distance object d3 = nameless object of Distance; d3 = d1 + 9.75; 9.75 is converted into Distance object by calling one argument constructor Then operator + function is invoked by d1 object d3 = 6.5 + d1; d3 = Distance(6.5) + d1; Note When a float value pass as argument to function Definition: void function (Distance d1) { } Call : function (10.75); One argument constructor is called Distance(float) Convert float value i.e. 10.75 into Distance object Call : function (Distance (10.75)) function (Nameless Distance object) d3 = 10.75 + d1; Neither float value 10.75 invoke operator + function Nor operator knows to convert float to Distance Distance Example – Friend function class Distance { . . . friend Distance operator + ( Distance, Distance ) const; }; Distance Distance::operator + (Distance d1, Distance d2) const { int f = d1.feet + d2.feet; float i = d1.inches + d2.inches; if(i >= 12.0) i -= 12.0; f .

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.