Tải bản đầy đủ (.pdf) (10 trang)

Lecture Data structures and other objects using C++ - Chapter 2: Object-oriented programming - Trường Đại học Công nghiệp Thực phẩm Tp. Hồ Chí Minh

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (624.34 KB, 10 trang )

<span class='text_page_counter'>(1)</span><div class='page_container' data-page=1></div>
<span class='text_page_counter'>(2)</span><div class='page_container' data-page=2>

What is this Object ?



There is no real 


There is no real 


answer to the question, 


answer to the question, 


but we’ll call it a 


but we’ll call it a 


“thinking cap”.


“thinking cap”.


The plan is to describe 


The plan is to describe 


a thinking cap by 


a thinking cap by 


telling you what 


telling you what 


actions can be done to 



actions can be done to 


it.


</div>
<span class='text_page_counter'>(3)</span><div class='page_container' data-page=3>

Using the Object’s Slots



You may put a piece of 


You may put a piece of 


paper in each of the two 


paper in each of the two 


slots (green and red), with a 


slots (green and red), with a 


sentence written on each.


sentence written on each.


You may push the green 


You may push the green 


button and the thinking cap 


button and the thinking cap 



will speak the sentence 


will speak the sentence 


from the green slot’s paper.


from the green slot’s paper.


And same for the red 


And same for the red 


button.


</div>
<span class='text_page_counter'>(4)</span><div class='page_container' data-page=4></div>
<span class='text_page_counter'>(5)</span><div class='page_container' data-page=5>

Example



</div>
<span class='text_page_counter'>(6)</span><div class='page_container' data-page=6>

Example



</div>
<span class='text_page_counter'>(7)</span><div class='page_container' data-page=7>

Thinking Cap Implementation



We can implement the 


We can implement the 


thinking cap using a 


thinking cap using a 


data type called a 



data type called a 


class


class.<sub>.</sub>


class thinking_cap 


</div>
<span class='text_page_counter'>(8)</span><div class='page_container' data-page=8>

Thinking Cap Implementation


The class will have 
The class will have 
two components called 
two components called 
green_string


green_string and <sub> and </sub>


red_string


red_string.  These .  These 


</div>
<span class='text_page_counter'>(9)</span><div class='page_container' data-page=9>

Thinking Cap Implementation



The two components 


The two components 


will be 



will be private private 
member variables


</div>
<span class='text_page_counter'>(10)</span><div class='page_container' data-page=10>

Thinking Cap Implementation



In a class, the 


In a class, the 


functions which 


functions which 


manipulate the class 


manipulate the class 


are also listed.


are also listed.


class thinking_cap 
{


public:
      . . .
private:


     char green_string[50];


     char red_string[50];
};


Prototypes for the 
thinking cap 


functions go here,
after the word 


</div>

<!--links-->

×