類的簡介-----外文翻譯.doc
約13頁DOC格式手機打開展開
類的簡介-----外文翻譯,the only remaining feature we need to understand before solving our bookstore problem is how to write a data structure to represent our transaction data. in c++...
內(nèi)容介紹
此文檔由會員 wanli1988go 發(fā)布
The only remaining feature we need to understand before solving our bookstore problem is how to write a data structure to represent our transaction data. In C++ we define our own data structure by defining a class. The class mechanism is one of the most important features in C++. In fact, a primary focus of the design of C++ is to make it possible to define class types that behave as naturally as the built-in types themselves. The library types that we've seen already, such as istream and ostream, are all defined as classesthat is,they are not strictly speaking part of the language.
Complete understanding of the class mechanism requires mastering a lot of information. Fortunately, it is possible to use a class that someone else has written without knowing how to define a class ourselves. In this section, we'll describe a simple class that we canuse in solving our bookstore problem. We'll implement this class in the subsequent chapters as we learn more about types,expressions, statements, and functionsall of which are used in defining classes.
To use a class we need to know three things:
What is its name?
Where is it defined?
What operations does it support?
For our bookstore problem, we'll assume that the class is named Sales_item and that it is defined in a header named Sales_item.h.
解決書店問題之前,還需要弄明白如何編寫數(shù)據(jù)結(jié)構(gòu)來表示交易數(shù)據(jù)。C++ 中我們通過定義類來定義自己的數(shù)據(jù)結(jié)構(gòu)。類機制是 C++ 中最重要的特征之一。事實上,C++ 設(shè)計的主要焦點就是使所定義的類類型的行為可以像內(nèi)置類型一樣自然。我們前面已看到的像 istream 和 ostream 這樣的庫類型,都是定義為類的,也就是說,它們嚴(yán)格說來不是語言的一部分。
完全理解類機制需要掌握很多內(nèi)容。所幸我們可以使用他人寫的類而無需掌握如何定義自己的類。在這一節(jié),我們將描述一個用于解決書店問題的簡單類。當(dāng)我們學(xué)習(xí)了更多關(guān)于類型、表達式、語句和函數(shù)的知識(所有這些在類定義中都將用到)后,將會在后面的章節(jié)實現(xiàn)這個類。
使用類時我們需要回答三個問題:
類的名字是什么?
它在哪里定義?
它支持什么操作?
對于書店問題,我們假定類命名為 Sales_item 且類定義在命名為 Sales_item.h 的頭文件中。
Sales_item 類
Sales_item 類的目的是存儲 ISBN 并保存該書的銷售冊數(shù)、銷售收入和平均售價。我們不關(guān)心如何存儲或計算這些數(shù)
Complete understanding of the class mechanism requires mastering a lot of information. Fortunately, it is possible to use a class that someone else has written without knowing how to define a class ourselves. In this section, we'll describe a simple class that we canuse in solving our bookstore problem. We'll implement this class in the subsequent chapters as we learn more about types,expressions, statements, and functionsall of which are used in defining classes.
To use a class we need to know three things:
What is its name?
Where is it defined?
What operations does it support?
For our bookstore problem, we'll assume that the class is named Sales_item and that it is defined in a header named Sales_item.h.
解決書店問題之前,還需要弄明白如何編寫數(shù)據(jù)結(jié)構(gòu)來表示交易數(shù)據(jù)。C++ 中我們通過定義類來定義自己的數(shù)據(jù)結(jié)構(gòu)。類機制是 C++ 中最重要的特征之一。事實上,C++ 設(shè)計的主要焦點就是使所定義的類類型的行為可以像內(nèi)置類型一樣自然。我們前面已看到的像 istream 和 ostream 這樣的庫類型,都是定義為類的,也就是說,它們嚴(yán)格說來不是語言的一部分。
完全理解類機制需要掌握很多內(nèi)容。所幸我們可以使用他人寫的類而無需掌握如何定義自己的類。在這一節(jié),我們將描述一個用于解決書店問題的簡單類。當(dāng)我們學(xué)習(xí)了更多關(guān)于類型、表達式、語句和函數(shù)的知識(所有這些在類定義中都將用到)后,將會在后面的章節(jié)實現(xiàn)這個類。
使用類時我們需要回答三個問題:
類的名字是什么?
它在哪里定義?
它支持什么操作?
對于書店問題,我們假定類命名為 Sales_item 且類定義在命名為 Sales_item.h 的頭文件中。
Sales_item 類
Sales_item 類的目的是存儲 ISBN 并保存該書的銷售冊數(shù)、銷售收入和平均售價。我們不關(guān)心如何存儲或計算這些數(shù)