Lecture Object oriented programming - Lecture No 11

13 22 0
Lecture Object oriented programming - Lecture No 11

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

This chapter present some background information on computers and programming languages in this optional chapter, provide a brief history of computers from the early days to present and describe the components found in today’s computers. This chapter also present a brief history of programming languages from low-level machine languages to today’s objectoriented languages.

CSC241: Object Oriented Programming Lecture No 11 Previous Lecture • Overloading binary operator – – – – • +, – and = operator for ThreeD class < operator for distance class += operator for distance class Subscript operator for Safe array class • Two functions to get and set value • One function, return by reference • Overloaded [ ] operator, return by reference Data conversion Today’s Lecture • • Data conversion – one-argument constructor – conversion function Overloading stream operators – Stream insertion – Stream extraction Data Conversion • The = operator will assign a value from one variable to another, instatements like intvar1 = intvar2; where intvar1 and intvar2 are integer variables • Also, = assigns the value of one user-defined object to another, provided they are of the same type, in statements like dist3 = dist1 + dist2; where the result of the addition, is assigned to another object of type Distance, dist3 • dist4 = dist3; Cont • • • Thus, assignments between types, whether they are basic types or user-defined types, are handled by the compiler with no effort on our part, provided that the same data type is used on both sides of the equal sign what happens when the variables on different sides of the = are of different types? For example: – dist2 = 7.55; Distance class class Distance { private: int feet; float inches; public: Distance() : feet(0), inches(0.0) {} Distance(int ft, float in) : feet(ft), inches(in) {} void getdist() { cout > feet; cout > inches; } void showdist() const { cout

Ngày đăng: 20/09/2020, 13:24

Mục lục

  • Slide 1

  • Previous Lecture

  • Today’s Lecture

  • Data Conversion

  • Cont.

  • Distance class

  • Conversions Between Objects and Basic Types

  • Conversions Between Objects of Different Classes

  • Cont.

  • Example program 01: km to miles

  • Cont.

  • Overloading Stream Insertion and Stream Extraction

  • Slide 13

Tài liệu cùng người dùng

Tài liệu liên quan