ผลต่างระหว่างรุ่นของ "Adt lab/classes"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
(หน้าที่ถูกสร้างด้วย ': ''This is part of Adt lab'' == Classes in C++ == === Dog class === === Simple counter class === == ADT: Integer set == === I...')
 
 
(ไม่แสดง 12 รุ่นระหว่างกลางโดยผู้ใช้คนเดียวกัน)
แถว 1: แถว 1:
 
: ''This is part of [[Adt lab]]''
 
: ''This is part of [[Adt lab]]''
 +
 +
C++ is a class-based object-oriented programming language.  Every object in C++ must be an instance of some class.  If you are familiar with OOP in Java, most ideas should be familiar; you may need to learn a few new terminologies.  There are one main difference: in C++ you have freedom to use an object as a value-typed variable; in Java, every object is a reference variable.  We will look at these basic idea this week.
 +
 +
== On-line resources ==
 +
 +
* [https://en.wikibooks.org/wiki/C%2B%2B_Programming C++ Programming] on wikibooks: [https://en.wikibooks.org/wiki/C%2B%2B_Programming/Classes classes section]
 +
* [http://www.cplusplus.com/doc/tutorial/ Tutorial] from cplusplus.com
 +
 +
* [http://www.horstmann.com/ccj2/ccjapp3.html Moving from Java to C++]
 +
* [http://cs.brown.edu/courses/cs123/docs/java_to_cpp.shtml Java to C++ Transition Tutorial]
  
 
== Classes in C++ ==
 
== Classes in C++ ==
 +
 +
=== Review of basic terminologies ===
 +
 +
'''Classes''' are user-defined types.  An '''object''' is an instance of a class.  A class can contain many members: '''data members''', '''member functions''', constants.  (Note that in C++, we do not call member functions as ''methods''.)  Members can have access labels: '''public''', '''protected''', '''private'''.  Some member can be '''static''' member, i.e., it is a member that is shared among all objects in the class.
  
 
=== Dog class ===
 
=== Dog class ===
แถว 8: แถว 22:
  
 
== ADT: Integer set ==
 
== ADT: Integer set ==
 +
 +
In this section, we will implement simple integer set ADT based on arrays.  The implementation has many limitations, though.
  
 
=== Interface ===
 
=== Interface ===
 +
 +
<source lang="cpp">
 +
class IntegerSet
 +
{
 +
public:
 +
  IntegerSet();
 +
 +
  void add(int x);
 +
  bool contains(int x);
 +
  void remove(int x);
 +
};
 +
</source>
  
 
=== Implementation ===
 
=== Implementation ===
  
== Copy constructors ==
+
== IntegerSet with set_union and set_difference ==
 +
<source lang="cpp">
 +
class IntegerSet
 +
{
 +
public:
 +
  IntegerSet();
 +
 
 +
  void add(int x);
 +
  bool contains(int x);
 +
  void remove(int x);
 +
 
 +
  bool is_equal(const IntegerSet& s);
 +
 
 +
  IntegerSet set_union(const IntegerSet& s);
 +
  IntegerSet set_difference(const IntegerSet& s);
 +
};
 +
 
 +
</source>
 +
 
 +
== Integer set ADT: implementation with flexible arrays ==
 +
 
 +
=== Copy constructors ===

รุ่นแก้ไขปัจจุบันเมื่อ 00:02, 4 กันยายน 2558

This is part of Adt lab

C++ is a class-based object-oriented programming language. Every object in C++ must be an instance of some class. If you are familiar with OOP in Java, most ideas should be familiar; you may need to learn a few new terminologies. There are one main difference: in C++ you have freedom to use an object as a value-typed variable; in Java, every object is a reference variable. We will look at these basic idea this week.

On-line resources

Classes in C++

Review of basic terminologies

Classes are user-defined types. An object is an instance of a class. A class can contain many members: data members, member functions, constants. (Note that in C++, we do not call member functions as methods.) Members can have access labels: public, protected, private. Some member can be static member, i.e., it is a member that is shared among all objects in the class.

Dog class

Simple counter class

ADT: Integer set

In this section, we will implement simple integer set ADT based on arrays. The implementation has many limitations, though.

Interface

class IntegerSet
{
public:
  IntegerSet();

  void add(int x);
  bool contains(int x);
  void remove(int x);
};

Implementation

IntegerSet with set_union and set_difference

class IntegerSet
{
public:
  IntegerSet();

  void add(int x);
  bool contains(int x);
  void remove(int x);

  bool is_equal(const IntegerSet& s);
  
  IntegerSet set_union(const IntegerSet& s);
  IntegerSet set_difference(const IntegerSet& s);
};

Integer set ADT: implementation with flexible arrays

Copy constructors