TAILIEUCHUNG - Object Oriented Programming (19)

CSC241: Object Oriented Programming. Lecture No 21. 1 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. 2 Today’s Lecture.•. Friend function. – example program: Distance class. – Friend function for functional notation.•. Friend classes.•. static functions. 3 Distance Distance { Distance. private: Distance::operator +. int feet; float inches; ( Distance d2 ) const {. public: int f = feet + ;. Distance() : feet(0),. inches() float i = inches +. {} ;. Distance (float fltfeet) { if(i >= ) {. feet = fltfeet; i -= ;. inches = 12*(fltfeet-feet); } f++;. Distance(int ft, float in) : }. feet(ft), inches(in) { } When. returnsuch constructor. Distance(f,i);. void showdist() const exists,. } following. { cout = ). i -= ; f friend function Overloaded. return Distance(f,i); () operator took two.} argument 7 friends for Functional Distance { float Distance::square() {. private: float fltfeet = feet +. int feet; inches/12;. float inches; float feetsqrd = fltfeet *. public: fltfeet;. Distance() : feet(0), return feetsqrd;. main() {. inches() }. Distance dist(3, );. {}. float sqft;. Distance(int ft, float in) :. sqft = ();. feet(ft), inches(in) { }. cout << “\nDistance = “;. void showdist() const. ();. { cout << feet << “ : ” <<.

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.