Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC212 Data Structure - Section BC

Similar presentations


Presentation on theme: "CSC212 Data Structure - Section BC"— Presentation transcript:

1 CSC212 Data Structure - Section BC
Lecture 2 ADT and C++ Classes (I) Instructor: Zhigang Zhu Department of Computer Science City College of New York

2 CSC212 Data Structure - Section BC
Lecture 2 ADT and C++ Classes (I) Instructor: Zhigang Zhu Department of Computer Science City College of New York

3 Outline A Review of C++ Classes (Lecture 2) OOP, ADTs and Classes
Class Definition, Implementation and Use Constructors and Value Semantics More on Classes (Lecture 3) Namespace and Documentation Classes and Parameters Operator Overloading

4 Object Oriented Programming
Chapter 2 introduces Object Oriented Programming. OOP is the typical approach to programming which supports the creation of new data types and operations to manipulate those types. This lecture gives a review of C++ Classes and introduces ADTs. This lecture is an introduction to classes, telling what classes are and how they are implemented in C++. The introduction is basic, not covering constructors or operators that are covered in the text. The best time for this lecture is just before students read Chapter 2--perhaps as early as the second day of class. Before this lecture, students should have a some understanding of 1. How an array of characters can be used as a string in C++ programming, and 2. The meaning of the strlen and strcpy functions from string.h.

5 C++ Classes and ADTs Class Abstract Date Types (ADTs)
Mechanism to create objects and member functions Support information hiding Abstract Date Types (ADTs) mathematical data type Class as an ADT that programmers can use without knowing how the member functions are implemented - i.e. with information hiding Information hiding by Data Encapsulation

6 A point ADT A data type to store and manipulate a single point on a plane Manipulations Initialize Retrieval Shift x 2 1 -1 - 2 y p1 This lecture will introduce you to object-oriented programming by using one example, a point class.

7 A point ADT A data type to store and manipulate a single point on a plane Manipulations Initialize Retrieval coordinates Shift x 2 1 -1 - 2 y p1 (-1, 0.8) This lecture will introduce you to object-oriented programming by using one example, a point class.

8 A point ADT A data type to store and manipulate a single point on a plane Manipulations Initialize Retrieval coordinates Shift 2 1 -1 - 2 y p1 x 0.8 This lecture will introduce you to object-oriented programming by using one example, a point class. -1.0

9 A point ADT A data type to store and manipulate a single point on a plane Manipulations Initialize Retrieval coordinates Shift by 2 1 -1 - 2 y p1 x p2 (1.3, -1.4) (0.3, -0.6)

10 Outline A Review of C++ Classes (Lecture 2) OOP, ADTs and Classes
Class Definition, Implementation and Use Constructors and Value Semantics More on Classes (Lecture 3) Namespace and Documentation Classes and Parameters Operator Overloading

11 x 2 1 -1 -2 y p point Definition We can implement the point object using a data type called a class. class point { . . . }; We will implement the thinking cap in C++ using a feature called a class. Don’t forget the semicolon at the end

12 x 2 1 -1 -2 y p point Definition The class will have two components called x and y. These components are the x and y coordinates of this point. Using a class permits two new features . . . class point { . . . double x; double y; }; Some of you may have used classes before in your programming. Others might have used “structs”, which are similar to classes. But a C++ class has two new features that are not available in ordinary struct types...

13 x 2 1 -1 -2 y p point Definition The two components will be private member variables. This ensures that nobody can directly access this information. The only access is through functions that we provide for the class. class point { . . . private: double x; double y; }; The first class feature is that class components are allowed to be private components. The advantage of private components is that they prevent certain programmers from accessing the components directly. Instead, programmers are forced to use only through the operations that we provide.

14 x 2 1 -1 -2 y p point Definition In a class, the functions which manipulate the class are also listed. class point { public: . . . private: double x; double y; }; In a class, the operations to manipulate the data are actually part of the class itself. A prototype for each function is placed as part of the class definition. Prototypes for the point functions go here, after the word public:

15 x 2 1 -1 -2 y p point Definition In a class, the functions which manipulate the class are also listed. class point { public: . . . private: double x; double y; }; In the jargon of OOP programmers, the class’s functions are called it’s member functions, to distinguish them from ordinary functions that are not part of a class. Prototypes for the point member functions go here

16 point Definition Our point has at least four member functions:
x 2 1 -1 -2 y p point Definition Our point has at least four member functions: class point { public: void initialize(double init_x, double init_y); void shift(double dx, double dy); double get_x() const; double get_y( ) const; private: double x; double y; }; The implementations of member functions do not normally appear within the class definition. We’ll see where they do appear later, but for now, let's just concentrate on this part of the class, which is called the class definition. Function bodies will be elsewhere.

17 functions will not change
x 2 1 -1 -2 y p point Definition The keyword const appears after two prototypes: class point { public: void initialize(double init_x, double init_y); void shift(double dx, double dy); double get_x( ) const; double get_y( ) const; private: double x; double y; }; This means that these functions will not change the data stored in a point ADT. One thing that you might have noticed in the definition is a keyword, const, which appears after two of my prototypes. This keyword means that these two functions will not change the data stored in a point ADT. In other words, when you do use these two functions, a point object remains “constant”.

18 x 2 1 -1 -2 y p Files for the point ADT The point class definition, which we have just seen, is placed with documentation in a file called point.h, outlined here. The implementations of the four member functions will be placed in a separate file called point.cxx, which we will examine in a few minutes. Documentation: (Preconditions and Postconditions) Class definition: point class definition which we have already seen Typically, a class definition is placed in a separate header file along with documentation that tells how to use the new class. The implementations of the member functions are placed in a separate file called the implementation file. At this point, I still haven't shown you exactly what those three implementations of member functions look like -- and I want to continue to postpone that. Instead, I will next show you an example program which uses this point class.

19 Outline A Review of C++ Classes (Lecture 2) OOP, ADTs and Classes
Class Definition, Implementation and Use Constructors and Value Semantics More on Classes (Lecture 3) Namespace and Documentation Classes and Parameters Operator Overloading

20 x 2 1 -1 -2 y p Using the point ADT A program that wants to use the point ADT must include the point.h header file (along with its other header inclusions). File pointmain1.cxx #include <iostream.h> #include <stdlib.h> #include “point.h" ... Any program that uses a class requires an include statement indicating the name of the header file that has the class definition. Note that we include only point.h, which is the header file, and do not include the implementation file.

21 x 2 1 -1 -2 y p Using the point ADT Just for illustration, the example program will declare two point variables named p1 and p2. #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1; point p2; After the include statement, we may declare and use variables of the point abstract data type. This example actually has two point variables, named p1 and p2.

22 x 2 1 -1 -2 y p Using the point ADT Just for illustration, the example program will declare two point objects named p1 and p2. #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1; point p2; In object-oriented terminology, we would call these two variables objects of the point class.

23 x 2 1 -1 -2 y p Using the point ADT The program starts by calling the initialize member function for p1. #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); This illustrates how we call one of the point functions for the p1 object.

24 x 2 1 -1 -2 y p Using the point ADT The program starts by activating the initialize member function for p1. #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1: point p2; p1.initialize(-1.0, 0.8); But, again, let's use the usual OOP terminology, so that instead of saying that we are calling a function we say that we are activating a member function. In particular, we are activating the initialize member function of the p1 object. (If you go to a cocktail party and tell your OOP friends that today you called a function for an object, they will laugh behind your back. It is better to impress them by saying that you activated a member function, even though it’s just jargon.)

25 x 2 1 -1 -2 y p Using the point ADT The member function activation consists of four parts, starting with the object name. int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); The complete activation consists of four parts, beginning with the object name. Name of the object

26 x 2 1 -1 -2 y p Using the point ADT The instance (object) name is followed by a period. int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); The object name is followed by a period. A Period

27 x 2 1 -1 -2 y p Using the point ADT After the period is the name of the member function that you are activating. int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); After the period is the name of the member function that you are activating. Name of the Function

28 x 2 1 -1 -2 y p Using the point ADT Finally, the arguments for the member function. In this example the first argument (x coordinate) and the second argument (y coordinate) int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); Arguments And finally there is the argument list. In the case of the initialize member function, there are two double arguments: x (which is given the actual value –1.0 in this example) and y (which is given the actual value 0.8 in this example).

29 A Quiz How would you activate p1's get_x member function ?
2 1 -1 -2 y p A Quiz How would you activate p1's get_x member function ? What would be the output of p1's get_x member function at this point in the program ? int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); Go ahead and write your answers before I move to the next slide.

30 A Quiz Notice that the get_x member function has no arguments.
2 1 -1 -2 y p A Quiz Notice that the get_x member function has no arguments. At this point, activating p1.get_x will return a double value -1.0. int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); cout << p1.get_x( ) <<endl; Remember that the get_x member function does not have any arguments, so the argument list is just a pair of parentheses.

31 A Quiz Trace through this program, and tell me the complete output.
x 2 1 -1 -2 y p A Quiz int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); cout << p1.get_x( ) << p1.get_y() << endl; p2.initialize(p1.get_x(), p1.get_y()); cout << p2.get_x( ) << p2.get_y() << endl; p2.shift(1.3, -1.4); . . . Trace through this program, and tell me the complete output. Here's a longer program. What is the complete output? Again, write your answers before I move to the next slide.

32 A Quiz -1.0 0.8 0.3 -0.6 int main( ) { point p1; point p2;
x 2 1 -1 -2 y p A Quiz int main( ) { point p1; point p2; p1.initialize(-1.0, 0.8); cout << p1.get_x( ) << p1.get_y() << endl; p2.initialize(p1.get_x(), p1.get_y()); cout << p2.get_x( ) << p2.get_y() << endl; p2.shift(1.3, -1.4); . . . The important thing to notice is that p1 and p2 are separate objects of the point class. Each has its own x and y coordinates. Or to throw one more piece of jargon at you: Each has its own x and y member variables. Member variables are the data portion of a class. The activation of p1.initialize fills in the x and y data for p1, and the activation of p2.initialize fills in the x and y data forp2. Once these member variables are filled in, we can activate the get_x and get_y member functions. For example, p1.get_x accesses the x member variable of p1, whereas p2.get_x accesses the x member variable of p2.

33 What you know about Objects
Class = Data + Member Functions. You know how to define a new class type, and place the definition in a header file. You know how to use the header file in a program which declares instances of the class type. You know how to activate member functions. But you still need to learn how to write the bodies of a class’s member functions. You now know quite a bit about OOP -- but the key missing piece is how to implement a class’s member functions.

34 Outline A Review of C++ Classes (Lecture 2) OOP, ADTs and Classes
Class Definition, Implementation and Use Constructors and Value Semantics More on Classes (Lecture 3) Namespace and Documentation Classes and Parameters Operator Overloading

35 x 2 1 -1 -2 y p point Implementation Remember that the member function’s bodies generally appear in a separate point.cxx file. class point { public: void initialize(double init_x, double init_y); void shift(double dx, double dy); double get_x( ) const; double get_y( ) const; private: double x; double y; }; You already know the location of these implementations: in a separate “implementation file” called point.cxx. Function bodies will be in .cxx file.

36 x 2 1 -1 -2 y p point Implementation We will look at the body of intialize, which must assign its two arguments to the two private member variables. class point { public: void initialize(double init_x, double init_y); void shift(double dx, double dy); double get_x( ) const; double get_y( ) const; private: double x; double y; }; We'll start by looking at the implementation of the initialize member function. The work which the function must accomplish is small: Copy the two arguments (init_x and init_y) to the two private member variables of the object (x and y).

37 x 2 1 -1 -2 y p point Implementation For the most part, the function’s body is no different than any other function body. void point::initialize(double init_x, double init_y) { x = init_x; y = init_y; } But the more interesting parts of this implementation are two special features that you need to know about. But there are two special features about a member function’s body . . .

38 x 2 1 -1 -2 y p point Implementation In the heading, the function's name is preceded by the class name and :: - otherwise C++ won't realize this is a class’s member function. void point::initialize(double init_x, double init_y) { x = init_x; y = init_y; } First of all, in the member function’s heading you must include the name of the class followed by two colons, as shown here. Otherwise, the C++ compiler will think that this is an ordinary function called initialize, rather than a member function of the point class.

39 x 2 1 -1 -2 y p point Implementation Within the body of the function, the class’s member variables and other member functions may all be accessed. void point::initialize(double init_x, double init_y) { x = init_x; y = init_y; } Within the body of the member function, we may access any of the members of the object. In this example, we are accessing both the x and the y member variables, by assigning values to these member variables.

40 x 2 1 -1 -2 y p point Implementation Within the body of the function, the class’s member variables and other member functions may all be accessed. But, whose member variables are these? Are they p1.x p1.y p2.x p2.y void point::initialize(double init_x, double init_y) { x = init_x; y = init_y; } The use of these member variables is a bit confusing. Which member variables are we talking about? P1.x and p1.y? Or are we referring to p2.x and p2.y? Or member variables of some other object? ?

41 x 2 1 -1 -2 y p point Implementation Within the body of the function, the class’s member variables and other member functions may all be accessed. If we activate p1.initialize: p1.x p1.y void point::initialize(double init_x, double init_y) { x = init_x; y = init_y; } The answer depends on which object has activated its member function. If p1.initialize is activated, then these two member variables will refer to p1.x and p1.y.

42 x 2 1 -1 -2 y p point Implementation Within the body of the function, the class’s member variables and other member functions may all be accessed. If we activate p2.initialize: p2.x p2.y void point::initialize(double init_x, double init_y) { x = init_x; y = init_y; } But if p2.initialize is activated, then these two member variables will refer to p2.x and p2.y.

43 x 2 1 -1 -2 y p point Implementation Here is the implementation of the get_x member function, which return the x coordinate: double point::get_x() const { return x; } Here's the implementation of the get_x member function.

44 x 2 1 -1 -2 y p point Implementation Here is the implementation of the get_x member function, which return the x coordinate: double point::get_x() const { return x; } The important thing to notice is how the member function’s implementation uses the x member variable of the object. If we activate p1.get_x, then the member function will use p1.x. And if we activate p2.get_x, then the member function will use p2.x. Note that we cannot use either p1.x or p2.x outside the member functions of point ADT since x is private! Notice how this member function implementation uses the member variable x of the point object.

45 x 2 1 -1 -2 y p point Implementation Member functions may activate other member functions void point::origin() { x = 0.0; y = 0.0; } On the other hand, member functions may activate other member functions as well as directly using the member variables Notice this member function implementation still directly assign the member variables x and y.

46 x 2 1 -1 -2 y p point Implementation Member functions may activate other member functions void point::origin() { initialize(0.0, 0.0); } Without object name On the other hand, member functions may activate other member functions as well as directly using the member variables Notice how this member function implementation uses the member function initialize.

47 A Common Pattern Often, one or more member functions will place data in the member variables... class point { public: void initialize(double init_x, double init_y); void shift(double dx, double dy); double get_x( ) const; double get_y( ) const; private: double x; double y; }; The member functions of the point are all simple, but they do illustrate a common pattern: Often some member functions (such as initialize shift) will place information in the private member variables, so that other const member functions (such as get_x and get_y) may access the information in those member variables. Initialize & shift get_x & get_y ...so that other member functions may use that data.

48 Summary of classes Classes have member variables and member functions. An object is a variable where the data type is a class. You should know how to declare a new class type, how to implement its member functions, how to use the class type. Frequently, the member functions of an class type place information in the member variables, or use information that's already in the member variables. Next we will see more features of OOP and classes. A quick summary This presentation has only introduced classes. You should read all of Chapter 2 to get a better understanding of classes. Pay particular attention to the notion of a constructor, which is a special member function that can automatically initialize the member variables of an object. Also pay attention to the more advanced features such as operator overloading with the Point class given in Chapter 2.

49 Assignments Reading: Programming assignment 1 - Due Wed, Sep. 13
Send to Reading: Chapter Programming assignment 1 - Due Wed, Sep. 13 Need all of chapter 2 to finish, but you can start doing it now Requirements and guidelines have been posted on the course web site: Note: output file in a text or PDF file C++ Installation Guide online Linux Users: See the assignment #1 guidelines Mac/Win Users: Check the course bulletin for some tips

50 Break

51 Outline A Review of C++ Classes (Lecture 2) OOP, ADTs and Classes
Class Definition, Implementation and Use Constructors and Value Semantics More on Classes (Lecture 3) Namespace and Documentation Classes and Parameters Operator Overloading

52 Constructors: point Initialization
x 2 1 -1 -2 y p Constructors: point Initialization The program starts by activating the initialize member function for p1. #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1: point p2; p1.initialize(-1.0, 0.8); But, again, let's use the usual OOP terminology, so that instead of saying that we are calling a function we say that we are activating a member function. In particular, we are activating the initialize member function of the p1 object. (If you go to a cocktail party and tell your OOP friends that today you called a function for an object, they will laugh behind your back. It is better to impress them by saying that you activated a member function, even though it’s just jargon.) First improvement: automatic initialization without activating the initialize function

53 Constructors: point Initialization
x 2 1 -1 -2 y p Constructors: point Initialization We can provide a normal member function initialize class point { public: void initialize(double init_x, double init_y); void shift(double dx, double dy); double get_x() const; double get_y( ) const; private: double x; double y; }; The implementations of member functions do not normally appear within the class definition. We’ll see where they do appear later, but for now, let's just concentrate on this part of the class, which is called the class definition.

54 Constructors: point Initialization
x 2 1 -1 -2 y p Constructors: point Initialization Or use a constructor that is automatically called class point { public: point(double init_x, double init_y); void shift(double dx, double dy); double get_x() const; double get_y( ) const; private: double x; double y; }; The implementations of member functions do not normally appear within the class definition. We’ll see where they do appear later, but for now, let's just concentrate on this part of the class, which is called the class definition. function name same as class name no return type, even no “void” !

55 Constructors: Implementation
x 2 1 -1 -2 y p Constructors: Implementation For the most part, the constructor is no different than any other member functions. void point::initialize(double init_x, double init_y) { x = init_x; y = init_y; } But the more interesting parts of this implementation are two special features that you need to know about. We only need to replace initialize with point

56 Constructors: Implementation
x 2 1 -1 -2 y p Constructors: Implementation For the most part, the constructor is no different than any other member functions. point::point(double init_x, double init_y) { x = init_x; y = init_y; } But the more interesting parts of this implementation are two special features that you need to know about. But there are three special features about constructor . . .

57 Constructors Constructor is a member function which
the name must be the same as the class name automatically called whenever a variable of the class is declared arguments must be given after the variable name (when declared in user file) A way to improve the initialize function by providing an initialization function that is guaranteed to be called

58 Constructors: point Initialization
x 2 1 -1 -2 y p Constructors: point Initialization Automatically called when declared. Parameters after the object names #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1: point p2; p1.initialize(-1.0, 0.8); But, again, let's use the usual OOP terminology, so that instead of saying that we are calling a function we say that we are activating a member function. In particular, we are activating the initialize member function of the p1 object. (If you go to a cocktail party and tell your OOP friends that today you called a function for an object, they will laugh behind your back. It is better to impress them by saying that you activated a member function, even though it’s just jargon.) First improvement: automatic initialization without explicitly activating an initialize function

59 Constructors: point Initialization
x 2 1 -1 -2 y p Constructors: point Initialization Automatically called when declared. Parameters after the object names #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1(-1.0, 0.8): point p2(0.3, 0.6); But, again, let's use the usual OOP terminology, so that instead of saying that we are calling a function we say that we are activating a member function. In particular, we are activating the initialize member function of the p1 object. (If you go to a cocktail party and tell your OOP friends that today you called a function for an object, they will laugh behind your back. It is better to impress them by saying that you activated a member function, even though it’s just jargon.) First improvement: automatic initialization without explicitly activating an initialize function

60 Default Constructors Automatically called when declared.
x 2 1 -1 -2 y p Default Constructors Automatically called when declared. Parameters after the object names #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1(-1.0, 0.8): point p2(0.3, 0.6); But, again, let's use the usual OOP terminology, so that instead of saying that we are calling a function we say that we are activating a member function. In particular, we are activating the initialize member function of the p1 object. (If you go to a cocktail party and tell your OOP friends that today you called a function for an object, they will laugh behind your back. It is better to impress them by saying that you activated a member function, even though it’s just jargon.) Sometime we want to define an object with no parameters…

61 Default Constructors Automatically called when declared.
x 2 1 -1 -2 y p Default Constructors Automatically called when declared. NO parameters after the object name p2 #include <iostream.h> #include <stdlib.h> #include “point.h" int main( ) { point p1(-1.0, 0.8); point p2; But, again, let's use the usual OOP terminology, so that instead of saying that we are calling a function we say that we are activating a member function. In particular, we are activating the initialize member function of the p1 object. (If you go to a cocktail party and tell your OOP friends that today you called a function for an object, they will laugh behind your back. It is better to impress them by saying that you activated a member function, even though it’s just jargon.) …not even a pair of parentheses

62 x 2 1 -1 -2 y p Default Constructors We could provide a second constructor with no parameters class point { public: point(); point(double init_x, double init_y); private: double x; double y; }; Implementation point::point() { x = 0.0; y = 0.0; } The implementations of member functions do not normally appear within the class definition. We’ll see where they do appear later, but for now, let's just concentrate on this part of the class, which is called the class definition.

63 Constructors: Function Overloading
You may declare as many constructors as you like – one for each different way of initializing an object Each constructor must have a distinct parameter list so that the compiler can tell them part Question: How many default constructor is allowed? Answer: only one, since default constructor has no argument, which cannot have two different parameter list.

64 Constructors: automatic default constructor
What happens if you write a class without any constructors? The compiler automatically creates a simple default constructor which only calls the default constructors for the member variables that are objects of some other classes Programming Tip :Always provide your own constructors, and better with a default constructor

65 Value Semantics of a Class
Value semantics determines how values are copied from one object to another Consists of two operations in C++ The assignment operator The copy constructor Document the value semantics When you implement an ADT, the document should include a comment indicating that the value semantics is safe to use.

66 Value Semantics: assignment operator
Automatic assignment operator For a new class, C++ normally carries out assignment by simply copying each variable from the object on the right to that on the left our new class point can use automatic assignment operator When automatic assignment fails we will see examples in Lecture 4 (pointers and dynamic arrays) point p1(-1.0, 0.8), p2; p2 = p1; cout << p2.get_x() <<“ “ << p2.get_y();

67 Value Semantics: copy constructor
A copy constructor is a constructor with exactly one parameter whose data type is the same as the constructor’s class is to initialize a new object as an exact copy of an existing object An example point p1(-1.0, 0.8); point p2 (p1); cout << p2.get_x() <<“ “ << p2.get_y();

68 Value Semantics: copy constructor
A copy constructor is a constructor with exactly one parameter whose data type is the same as the constructor’s class is to initialize a new object as an exact copy of an existing object An alternative syntax point p1(-1.0, 0.8); point p2 = p1; cout << p2.get_x() <<“ “<< p2.get_y();

69 Value Semantics: discussion
point p2 = p1; versus p2 = p1; The assignment p2 = p1; merely copies p1 to the already existing object p2 using the assignment operator. The syntax point p2 = p1; looks like an assignment statement, but actually a declaration that both declare a new object, and calls the copy constructor to initialize p2 as a copy of p1. p2 will be the same iff the assignment operator and the copy constructor do the same things

70 Copy Constructor: Implementation
You may write a copy constructor much like any other constructor Lecture 4 and later Take advantage of a C++ feature automatic copy constructor similar to assignment, the automatic copy constructor initializes a new object by merely copy all the member variables from the existing object. Automatic versions may fail! Point Demo Demo: point class in Chapter 2 – run point.dsw

71 Constructors, etc.– a summary
Constructor is a member function define your own constructors (including a default) automatic default constructor inline member functions ( Ch 2.2) Place a function definition inside the class definition for time efficiency value semantics of a class assignment operators and copy constructor automatic assignment op and copy constructor

72 Outline A Review of C++ Classes (Lecture 2) OOP, ADTs and Classes
Class Definition, Implementation and Use Constructors and Value Semantics More on Classes (Lecture 3) Namespace and Documentation Classes and Parameters Operator Overloading

73 Assignments Reading: Programming assignment 1 - Due Sep. 16
Send to Reading: Chapter Programming assignment 1 - Due Sep. 16 Need all of chapter 2 to finish, but you can start doing it now Requirements and guidelines have been posted on the course web site Note: you have to run your program with statexam.cxx to generate an output file in a text or PDF file

74 The first part (p.3-47) of this lecture was adapted from:
Presentation copyright 1997, Addison Wesley Longman For use with Data Structures and Other Objects Using C++ by Michael Main and Walter Savitch. Some artwork in the presentation is used with permission from Presentation Task Force (copyright New Vision Technologies Inc.) and Corel Gallery Clipart Catalog (copyright Corel Corporation, 3G Graphics Inc., Archive Arts, Cartesia Software, Image Club Graphics Inc., One Mile Up Inc., TechPool Studios, Totem Graphics Inc.). Students and instructors who use Data Structures and Other Objects Using C++ are welcome to use this presentation however they see fit, so long as this copyright notice remains intact. THE END


Download ppt "CSC212 Data Structure - Section BC"

Similar presentations


Ads by Google