Lipmann and Lajoie, and Goodrich et al, are C++ text books that give a general introduction as well as covering some of he more advanced topics.

Size: px
Start display at page:

Download "Lipmann and Lajoie, and Goodrich et al, are C++ text books that give a general introduction as well as covering some of he more advanced topics."

Transcription

1 1

2 2

3 3

4 Lipmann and Lajoie, and Goodrich et al, are C++ text books that give a general introduction as well as covering some of he more advanced topics. The C++ bible is by Stroustrup. Meyers is not a textbook. Rather it is a set of recommendations for good software engineering in C++ that gives lots of interesting examples of typical dilemmas faced by C++ programmers. Gamma, et al, is for advanced reading only. It covers lots of standard designs that crop up regularly in OOP, gives them names, and shows how they can be implemented and used. The idea is that rather than reinventing the wheel, standard designs should be reused. 4

5 Recall that top-down design means breaking the problem down into components (modules) recursively. Each module should comprise related data and functions, with this idea becoming explicit in OOP. Remember that the designer needs to specify how these components interact what their dependencies are, and what the interfaces between them are. Minimising dependencies, and making interfaces as simple as possible are both desirable to facilitate modularity. By minimising the ways in which modules can interact, we greatly limit the overall complexity, and hence limit unexpected behaviour, increasing robustness. Because a particular module interacts with other modules in a carefully defined manner, it becomes easier to test/validate, and can become a reusable component. A key part of this course will emphasize how C++ provides tools to help the designer/programmer explicitly separate interface and implementation, and so create more modular code. Note again reference to the general engineering principles of abstraction and modularity. A word about each in its software context: Abstraction: the idea here is to distil the software down to its fundamental parts, and describe these parts precisely, but without cluttering the description with unnecessary details such as exactly how it is implemented. The abstraction specifies what operations a module is for, without specifying how the operations are performed. Modularity: the aim is to define a set of modules each of which transcribes, or encapsulates particular functionality, and which interacts with other modules in well defined ways. The more complicated the set of possible interactions between modules, the harder it will be to understand, and humans are only capable of understanding and managing a certain degree of complexity. It is quite easy (but bad practice) to write software that exceeds this capability. 5

6 As we saw in the previous course, in procedural programming we tend to focus design effort on sub-dividing a program into functional blocks (i.e. functions). Object oriented design is an alternative paradigm for software design. Objectoriented design is the process of planning a system of interacting objects for the purpose of solving a software problem. An object contains encapsulated data and procedures grouped. The 'object interface -- how the object can be interacted with -- is also defined. An object-oriented program is described by the interaction of these objects. Object-oriented design is the discipline of defining the objects and their interactions to solve a problem. 6

7 Definitions modified from originals on wikipedia 7

8 Concept of class is fundamental in C++. Like C s struct, C++ provides a compound data structure 8

9 The data elements that make up the class are known as fields 9

10 We could represent the state as a set of four atomic variables. However this would not capture the conceptual relationship between the variables, and would result in code has a more complicated interface. The controller would need to take 4 input variables instead of one! Likewise the simulator output would be four quantities. Harder to understand, less close to our data flow diagram. 10

11 Data fields are accessed using the. (dot) operator. s is a variable of type State. In object-oriented terminology, s is an instance of State. Note, however, that in practice this kind of access to data members is actively discouraged in C++. Instead the better practice is have data declared private and accessed only through the class methods. 11

12 12

13 Methods, like data fields, are accessed using the dot operator. Notice, however, that the fields re and im are accessed directly inside the member functions. This is because when a method is invoked, it is invoked by a specific object (in this case z), so we already know which object s fields are being referred to; the z. is implicit. Actually, it s a z-> not a z.. When an object s method is called, a pointer to the calling object is always passed in as a parameter. In the rare event that you need access to the whole object, you can do so via the this pointer. 13

14 14

15 The private data fields of an instance of the Complex class, cannot be accessed by other software components. Instead, these components must use the so-called accessor methods Re() and Im(). This may seem like we are adding an unnecessary layer of complexity, but in we do so in order that the interface of the object is as unambiguously defined as possible. We have created a public interface to private data. Code that used z.re or z.im would produce an error. Live compilation demonstration. 15

16 Here, the internal representation of Complex has been changed. This has necessitated a change to the internal workings of each of the methods, but the interface -- the way other software components use this class -- has remained unaltered. This is the essence of encapsulation and it is the reason why it is such an important programming concept. The interface captures all the functionality that is required for other program components to use the class. 16

17 If re is a private data field of the Complex class then we can no longer legitimately say z.re=1.0, for instance. This begs the question of how we can modify the data. One way is at the point at which an object is created. We do this via a special method called a constructor. To understand the concept of a constructor, first consider what happens when a variable is declared in a piece of C++ code. At compile time, it tells the compiler what type of data it to be stored and used, and this enables the compiler to ensure that the body of code is using that data correctly (eg by flagging an error if a variable of type bool is passed to a the sin() function). At run time memory space is allocated for the variable (note that for a local variable this space would be on the stack, and this allocation should not be confused with dynamic memory allocation on the heap). In object-oriented parlance, at run-time we are creating a class instance, or creating an object. In general, variable declaration creates space at run-time, but by default does not set the value of the variable. What creates the space and sets the variable s value? A C-programmer would say the run-time system, because space allocation and variable initialisation just happens. 17

18 Can we initialise a complicated object? This is the work of the constructor, the function that is called once, at creation time, for each object instance at the point at which the object is created. For the predefined types, the constructor is automatically defined and so we never mention it. However C++ gives the programmer control over what happens when a user-defined type is created, by allowing the programmer to specify a constructor. The third form above int i(10) is the C++ style of initialisation. This form makes it clearer that the constructor is being called, though the syntax looks slightly different from a normal function call. The constructor is defined in the class definition like any other method. It has no return type and has the same name as the class. Just to emphasize, it is called once each time an instance of the class is created (ie a variable of that class is declared) 17

19 When a variable is declared in a piece of C++ code, it has two effects. At compile time, it tells the compiler what type of data it to be stored and used, and this enables the compiler to ensure that the body of code is using that data correctly (eg by flagging an error if a variable of type bool is passed to a the sin() function). At run time memory space is allocated for the variable (note that for a local variable this space would be on the stack, and this allocation should not be confused with dynamic memory allocation on the heap). In object-oriented parlance, at run-time we are creating a class instance, or creating an object. In general, variable declaration creates space at run-time, but by default does not set the value of the variable. Various types of declaration above can be used to declare and initialise. What creates the space and sets the variable s value? A C-programmer would say the run-time system, because space allocation and variable initialisation just happens. However how can we initialise a complicated object? This is the work of the constructor, the function that is called once, at creation time, for each object instance at the point at which the object is created. For the predefined types, the constructor is automatically defined and so we never mention it. However C++ gives the programmer control over what happens when a user-defined type is created, by 18

20 allowing the programmer to specify a constructor. The third form above int i(10) is the C++ style of initialisation. This form makes it clearer that the constructor is being called. The constructor is defined in the class definition like any other method. It has no return type and has the same name as the class. Just to emphasize, it is called once each time an instance of the class is created (ie a variable of that class is declared) 18

21 We have added a constructor to the interface for Complex. We can therefore now declare a Complex variable and set its values. When the constructor is called, the actual parameters to the constructor (in this example) are 10.0 and 8.0. The code in the constructor sets the value of re to be the first formal parameter (x) and the value of im to be the second formal parameter (y). 19

22 Here, the internal representation of Complex has been changed. This has necessitated a change to the internal workings of each of the methods, including a change in the operation of the constructor. But the interface -- the way other software components use this class -- has remained unaltered. In particular, in order to create (declare) an instance of type Complex, we specify the real and imaginery components. 20

23 It is good practice always to provide a copy constructor explicitly 21

24 Here, the internal representation of Complex has been changed. This has necessitated a change to the internal workings of each of the methods, but the interface -- the way other software components use this class -- has remained unaltered. This is the essence of encapsulation and it is the reason why it is such an important programming concept. The interface captures all the functionality that is required for other program components to use the class. Note that we have now defined two functions with the same name. How is this possible? It s called overloading, and its possible because the compiler looks at both the name of the function and the types of the arguments when deciding which function to call. We will go into some more detail on this later. 22

25 In C++ programs the header file (.h) plays a much more important role than in C. Every program element that uses the Complex class needs to know how it is defined. Well, actually, more specifically, each program element needs to know the interface. This part, which is, captured in the header file is then included in every module that uses Complex: #include Complex.h The implementation detail is in the.cc or.cpp file 23

26 The implementation of each method in the Complex class appears in the.cpp file. The class scoping operator :: is used to inform the compiler that each function is a method belonging to class Complex. In order to understand how to use a class, the programmer usually doesn t need to look at the.cpp file (the implementation); rather she can look at the beautifully uncluttered header file defining the interface that tells her everything she needs to know. More to the point, whenever she wants to use the Complex class, she simply imports the header into her code via the #include Complex.h compiler directive, and the compiler knows everything it needs to know about legal uses of the class. It is the job of the linker to join the implementation details of the class (that lives in Complex.cpp) with the rest of the code. 24

27 Recall that C/C++ parameters are passed by value (ie the value of the actual parameter is copied onto the stack), not by reference. Except arrays, which are passed by reference Why are arrays different? Because they can be very big, and it is wasteful of stack space, and costly in terms of processing to put a copy of a really big array onto the stack. Instead, it is cheap both in memory and processing to put a reference onto the stack. The same issues of space and time affect large classes. By default the whole of an object is copied onto the stack when an object is passed to a function. However we can avoid this cost by passing the object by reference, as above. The problem with this function definition (its interface) is that there is nothing to prevent the code in foo changing values of x, causing a side-effect. Maybe that s what we want, but if it s not, we should declare the formal parameter const and then the compiler can enforce this by making sure no values in x are changed by foo. This is then the standard way of passing large objects into a function. 25

28 26

29 We might like to declare a Complex variable z to be const. This would be a sensible thing to do if its value never changes, and will mean that the compiler will ensure its value can t be changed. All good so far, but this can often lead to difficult to find compile-time errors. The code above, for instance, will generate an error. The reason is that the compiler doesn t analyse the semantics of each function, so it can t be sure that the function z.re() doesn t change the internal values (re=10.0 and im=8.0) of the object z. The way to avoid this is to declare the accessor methods as const functions. 27

30 To fix this problem we add the const keyword after the function name for the functions that don t change the value; these are const methods, telling the programmer and the compiler that these functions do not modify any of the object s data. You might be tempted to sidestep the issue by having all data public and never using const, etc. Don t. The grief you will get ensuring that your well designed classes compile correctly will be minor compared to the potential problems created by code that abuses or sidesteps the interface, whether intentionally or accidentally. 28

31 29

32 30

33 31

34 See interesting discussion Item 19 in Meyers book 32

35 As you know, C++ (and Matlab and all other high level languages) provide operators for performing arithmetic and boolean operations and forming expression. 33

36 As we heard previously, C++ aims for user-defined types to mimic, as far as possible, the predefined types. We know that we can create function to add two complex numbers together, but it would be much more convenient to be able to use the + operator. 34

37 C++ provides a mechanism for doing this by exposing the fact that a+b is really just the infix notation shorthand for a function operator+(a,b) (this is the prefix notation). 35

38 36

39 The return value of z2.operator=(z1) is a reference to z2. That way we can concatenate assignments as in z3 = z2 = z1 which assigns the value of z1 to z2 and to z3, viz (z3 = (z2 = z1)). 37

40 We can use this array as follows: SafeFloatArray s; s[0]=10.0; s[5]=s[0]+22.4; s[15]=12.0; Compiles but at runtime the last call generates the error message Oops and the program exits. Live example. 38

41 39

42 This is Complex.h and defines the interface. Any program that wants to use the Complex class should include this file: #include Complex.h 40

43 This is Complex.cpp. It contains the implementation of the various methods in the class interface. 41

44 Complex.cpp continued 42

45 Complex.cpp last page 43

46 main.cpp contains code that uses the Complex class 44

47 Strictly speaking, the first three points apply to so-called object-based programming. They are general design principles. Object-oriented programming includes further powerful mechanism that help organise hierarchies of objects (inheritance), and enable objects in the same hierarchy to respond in tailored ways to the same events (polymorphism). Object-oriented programming has become the programming paradigm of choice for large projects. The reason is that OOP actively encourages encapsulation. By specifying the object interfaces clearly in the design phase of a project, teams of programmers can then implement the components with some assurance that the components will all work together. 45

48 A class in C++ inherits from another class using the : operator in the class definition. The code above reads class A inherits from class B, or class A is derived from class B. 46

49 The class at the top is known as the base class. A GraphicsWindow, for example, has the data fields width, height, posx, posy, background_colour And the methods raise(), hide(), select(), iconify(), clear() and fill() An InteractiveGraphicsWindow does not add any data fields, but does add methods that deal with mouse interactions. 47

50 48

51 Notice that in the previous example, both TextWindow and GraphicsWindow have a method redraw(). Indeed it will probably be the case that we want a redraw() method for any type of window. We could get this, of course, by putting the method redraw() into the base class, but what if the way to redraw a TextWindow is different from the way to redraw a GraphicsWindow? For example a TextWindow redraw() method will probably render all the characters that are currently in the window in the right font, etc, while the GraphicsWindow redraw will display an image, or render a pipeline of graphics drawing commands. The idea behind polymorphism is to permit the two different window types to share the interface redraw(), but implement it in different ways. Thus different objects (TextWindow and GraphicsWindow) respond to the same event (eg a raise() event which calls a redraw() event) in different ways. 49

52 50

53 51

54 First consider the code above. The call y.func() clearly will invoke the func method belonging to class B because y is an instance of class B. Likewise z.func() will call class C s func() method. callfunc(x) passes an object of type A into callfunc. The effect is to call the func() method of class A callfunc(y) passes an object of type B into the function. Because every B is also an A this is acceptable, but the formal parameter is a by-value parameter. The effect of this is that only the bit of y that is an A is put onto the stack into the activation record. The B bits are left behind, so as far as callfunc is concerned, it s received an object of type A, and param.func() will call A s func() method. 52

55 Recall that when a function is called, parameters, return location and other stuff are put onto the stack in the activation record. 53

56 Note that here there is no return value because callfunc returns void (ie no return value) 54

57 Now consider the slightly changed code above. Notice that the function func() in the base class A has been designated as a virtual function, and that the parameter to callfunc() is now passed by reference. The call y.func() still invokes the func method belonging to class B because y is an instance of class B. Likewise z.func() will call class C s func() method. callfunc(x) passes an object of type reference to A into callfunc. Since x is of type A, the effect of param.func() is to call the func() method of class A callfunc(y) passes an object of type B into the function. Because every B is also an A this is acceptable. The formal parameter is a reference parameter, and so the activation record will contain a reference to the object (ie a memory location where the object is stored), not a copy of the object. Dereferencing the reference gets us to the object, which contains information about what type of object it is (class B) as well as its private data (etc). The run-time system is therefore able to identify that the actual parameter is in fact of type B. This is known as Run-time Type Identification (RTTI). Because func() has been declared virtual in the base class, the system will therefore invoke a function call to the func() method belonging to class B. Similarly the call callfnc(z) will result in C s func() method being called. 55

58 Note that here there is no return value because callfunc returns void (ie no return value) 56

59 57

60 58

61 This code will generate a compile time error because we have tried to instantiate A. But because A has a pure virtual function, denoted with the = 0 it is abstract. There is no function func(). This forces any object that derives from A to implement a function func(). 59

62 Slightly technical point to do with C++ (rather than being a general principle): an array can only store objects of the same type. In this case it stores pointers to (ie the memory address of) each object. The -> operator does the same thing as the dot operator, but dereferences the pointer (looks up the object via the memory address) first. 60

63 This says that a spreadsheet comprises an array of references to Cells and each object of type Cell must be able to return its own value via an Evaluate() method. We can therefore write the implementation of Spreadsheet before we have designed all the Cell types. Or we can decide after it s all implemented and working that we d like another type of Cell (ie a new class that inherits from Cell) that is the product of two other Cells. Providing we implement the Evaluate() method for the new class correctly, Spreadsheet can use it seamlessly. 61

64 Euler::Euler(Func &f) : _f(f) {}; void Euler::Simulate(double x, double step, double time) { Cout << x endl; for (int t=0; t<time; t+=step) { x = x + step*_f(t, x(n,:) = x(n-1,:) + h * feval(fnname, t, x(n- 1,:)); end 62

65 The code above implements our generic Euler method. We then instantiate an Euler object (here called e ) in which the object y becomes the private member fn of e. In order for this to work, y (which is class YdotPlusY) must be an instance of Func. That is, YdotPlusY must inherit from Func. 63

66 The code above implements an abstract base class Func. Func specifies that any object that is to be used in the Euler simulation (ie simulation of a particular first order differential equation) must implement a dx_by_dt function. Our particular dx_by_dt function comes from the equation xdot + x = 0, hence dx_by_dt returns x. For the non-linear equation xdot + x^2 = 0 we can define a new class that implements dx_by_dt = -x*x 64

67 We previously created a class that could do array bounds checking, but it was limited to storing only floats. Above you see that code. Templates provide a way to parameterize a class definition with a type. That then allows the programmer to define different classes with the same overall design but containing different types. 65

68 To implement a template in C++, you prefix the class definition with template <class XX> where XX is a place holder or parameter to the class definition (above we have used Type ). At compile time the compiler encounters BoundedArray<int> x and sets about creating a class definition (if it doesn t already exist) in which Type is replaced with int everywhere in the definition. Of course we could do this ourselves by simply copying and pasting the code and doing a manual replacement. There are a number of good reasons for not doing this, not least the extra work required and that it s error prone. 66

69 Here we create a template class that is a container for a templated number of elements of a templated type. 67

70 Programmers regularly use similar, or even identical design solutions for problems. 68

71 The Standard Template Library is a suite of code that implements (among other things) classes of container types with standard ways of accessing elements, inserting, adding, deleting elements, etc, as well as a set of standard algorithms that operate on these classes (eg searching, iterating over all elemnets, etc). While these could all be coded from scratch by a competent programmer, code re-use in this way speeds development and reduces the possibility of introducing errors in the implementation. This addresses one of the issue with Software Engineering discussed in lecture 1, that of the lack of historical design data to rely on. The point here is that though different applications will have to represent different data, and will therefore have custom classes, it is common for the organisation of multiple instances of these classes to be done in standard ways (such as in an array). The use of custom classes is at first thought problematic if we want to implement these standard containers until we realise that templates enable us to write the generic, templated code, and specialise it to our custom classes at compile-time. 69

72 If we were coding an extensible array class ourselves we would use dynamic memory allocation (ie on the heap) and we would want to have: -- operator[] overloaded to access the ith element -- a size() method to report current length -- a resize() function to allocate more space -- a method to add an element to the end that will automatically allocate a new chunk of memory if we go beyond the end of the memory that has already been allocated. The point is we don t need to implement this because someone else has done it for us, and this is only possible through the use of templates, because the person who coded the vector class couldn t possibly anticipate all the classes that anyone might want to store. 70

73 71

74 72

75 73

76 An iterator is a class that supports the standard programming pattern of iterating over a container type without exposing the underlying representation of the container type itself (cf iterating using an integer index this relies specifically on the ability of the representation to index). 74

77 75

78 Refine specification. Not much to do here: How will the size be specified? How to print it out? What algorithm to use? Now design data structures 76

79 Now design the data structures. In particular, think about the classes and the class interfaces. 77

80 // cell.h // #ifndef _cell_ #define _cell_ class Cell { public: Cell(); bool Visited(); void MarkVisited(); bool BottomWall(); bool RightWall(); void BreakBottom(); void BreakRight(); private: bool bottomwall; bool rightwall; bool visited; }; #endif //_cell_ 78

81 // maze.h // #ifndef _maze_ #define _maze_ #include <vector> #include "cell.h" class Maze { public: Maze(int width, int height); void Compute(int x, int y); void Print(); private: }; int Rand(int n); int H, W; std::vector< std::vector<cell> > cells; #endif //_maze_ 79

82 80

83 81

B16 Object Oriented Programming

B16 Object Oriented Programming B16 Object Oriented Programming Michael A. Osborne mosb@robots.ox.ac.uk http://www.robots.ox.ac.uk/~mosb/teaching.html#b16 Hilary 2013 This course will introduce object-oriented programming (OOP). It will

More information

B16 Object Oriented Programming

B16 Object Oriented Programming B16 Object Oriented Programming Michael A. Osborne mosb@robots.ox.ac.uk http://www.robots.ox.ac.uk/~mosb/teaching.html#b16 Hilary 2013 Topic 4: Constructors Recall our definition of the Complex class.

More information

B16 Object Oriented Programming

B16 Object Oriented Programming B16 Object Oriented Programming Michael A Osborne mosb@robots.ox.ac.uk http://www.robots.ox.ac.uk/~mosb/b16.html Hilary 2014 Topic 10: Templates Recall our array-bounds-checking class: unfortunately, it

More information

B16 Object Oriented Programming

B16 Object Oriented Programming B16 Object Oriented Programming Michael A Osborne mosb@robots.ox.ac.uk http://www.robots.ox.ac.uk/~mosb/b16.html Hilary 2014 Topic 4: Constructors Recall our definition of the Complex class. class Complex

More information

B16 Object Oriented Programming

B16 Object Oriented Programming B16 Object Oriented Programming Michael A Osborne mosb@robots.ox.ac.uk http://www.robots.ox.ac.uk/~mosb/b16.html Hilary 2014 Topic 7: A Complete Complex Example Let s bring it all together by creating

More information

B16 Object Oriented Programming

B16 Object Oriented Programming B16 Object Oriented Programming Frank Wood fwood@robots.ox.ac.uk http://www.robots.ox.ac.uk/~fwood/teaching/ Hilary 2015 This course will introduce object-oriented programming (OOP). It will introduce

More information

B16 Object Oriented Programming

B16 Object Oriented Programming B16 Object Oriented Programming Frank Wood fwood@robots.ox.ac.uk http://www.robots.ox.ac.uk/~fwood/teaching/ Hilary 2015 This course will introduce object-oriented programming (OOP). It will introduce

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 1 Date:

More information

Module 10 Inheritance, Virtual Functions, and Polymorphism

Module 10 Inheritance, Virtual Functions, and Polymorphism Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

C++ (Non for C Programmer) (BT307) 40 Hours

C++ (Non for C Programmer) (BT307) 40 Hours C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular

More information

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module Basic Class Design Goal of OOP: Reduce complexity of software development by keeping details, and especially changes to details, from spreading throughout the entire program. Actually, the same goal as

More information

CSE 303: Concepts and Tools for Software Development

CSE 303: Concepts and Tools for Software Development CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010 CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)

More information

Functions, Pointers, and the Basics of C++ Classes

Functions, Pointers, and the Basics of C++ Classes Functions, Pointers, and the Basics of C++ Classes William E. Skeith III Functions in C++ Vocabulary You should be familiar with all of the following terms already, but if not, you will be after today.

More information

PIC 10A Objects/Classes

PIC 10A Objects/Classes PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++ CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

D Programming Language

D Programming Language Group 14 Muazam Ali Anil Ozdemir D Programming Language Introduction and Why D? It doesn t come with a religion this is written somewhere along the overview of D programming language. If you actually take

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Operator overloading

Operator overloading 1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The

More information

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

7.1 Optional Parameters

7.1 Optional Parameters Chapter 7: C++ Bells and Whistles A number of C++ features are introduced in this chapter: default parameters, const class members, and operator extensions. 7.1 Optional Parameters Purpose and Rules. Default

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Object-Oriented

More information

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

QUIZ. What are 3 differences between C and C++ const variables?

QUIZ. What are 3 differences between C and C++ const variables? QUIZ What are 3 differences between C and C++ const variables? Solution QUIZ Source: http://stackoverflow.com/questions/17349387/scope-of-macros-in-c Solution The C/C++ preprocessor substitutes mechanically,

More information

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

Part X. Advanced C ++

Part X. Advanced C ++ Part X Advanced C ++ topics Philip Blakely (LSC) Advanced C++ 158 / 217 References The following are highly regarded books. They are fairly in-depth, and I haven t read them in their entirity. However,

More information

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location

More information

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms AUTO POINTER (AUTO_PTR) //Example showing a bad situation with naked pointers void MyFunction()

More information

From Java to C++ From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3. Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009

From Java to C++ From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3. Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009 From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3 Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009 C++ Values, References, and Pointers 1 C++ Values, References, and Pointers 2

More information

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak! //Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new

More information

Lesson 13 - Vectors Dynamic Data Storage

Lesson 13 - Vectors Dynamic Data Storage Lesson 13 - Vectors Dynamic Data Storage Summary In this lesson we introduce the Standard Template Library by demonstrating the use of Vectors to provide dynamic storage of data elements. New Concepts

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

See the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I

See the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I Polynomial Class Polynomial(); Polynomial(const string& N, const vector& C); Polynomial operator+(const Polynomial& RHS) const; Polynomial operator-(const Polynomial& RHS) const; Polynomial operator*(const

More information

C++ & Object Oriented Programming Concepts The procedural programming is the standard approach used in many traditional computer languages such as BASIC, C, FORTRAN and PASCAL. The procedural programming

More information

III. Classes (Chap. 3)

III. Classes (Chap. 3) III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

the gamedesigninitiative at cornell university Lecture 7 C++ Overview Lecture 7 Lecture 7 So You Think You Know C++ Most of you are experienced Java programmers Both in 2110 and several upper-level courses If you saw C++, was likely in a systems course Java was based on

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

More information

Lecture 2, September 4

Lecture 2, September 4 Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due

More information

Lecture 3. Lecture

Lecture 3. Lecture True Object-Oriented programming: Dynamic Objects Static Object-Oriented Programming Reference Variables Eckel: 30-31, 41-46, 107-111, 114-115 Riley: 5.1, 5.2 D0010E Object-Oriented Programming and Design

More information

Object-Oriented Programming

Object-Oriented Programming - oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

More information

Programming in C and C++

Programming in C and C++ Programming in C and C++ 5. C++: Overloading, Namespaces, and Classes Dr. Neel Krishnaswami University of Cambridge (based on notes from and with thanks to Anil Madhavapeddy, Alan Mycroft, Alastair Beresford

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Lecture 7. Log into Linux New documents posted to course webpage

Lecture 7. Log into Linux New documents posted to course webpage Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26 COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

Pointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory

Pointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory Pointers A pointer is simply a reference to a variable/object Compilers automatically generate code to store/retrieve variables from memory It is automatically generating internal pointers We don t have

More information

Lecture Notes on Memory Layout

Lecture Notes on Memory Layout Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,

More information

Programming Style and Optimisations - An Overview

Programming Style and Optimisations - An Overview Programming Style and Optimisations - An Overview Summary In this lesson we introduce some of the style and optimization features you may find useful to understand as a C++ Programmer. Note however this

More information

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors Arrays Returning arrays Pointers Dynamic arrays Smart pointers Vectors To declare an array specify the type, its name, and its size in []s int arr1[10]; //or int arr2[] = {1,2,3,4,5,6,7,8}; arr2 has 8

More information

C++ Quick Guide. Advertisements

C++ Quick Guide. Advertisements C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and

More information

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428

More information

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O Outline EDAF30 Programming in C++ 2. Introduction. More on function calls and types. Sven Gestegård Robertz Computer Science, LTH 2018 1 Function calls and parameter passing 2 Pointers, arrays, and references

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

More information

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018 Pointer Basics Lecture 13 COP 3014 Spring 2018 March 28, 2018 What is a Pointer? A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Dynamic Memory Management Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 2. Mai 2017

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

A brief introduction to C++

A brief introduction to C++ A brief introduction to C++ Rupert Nash r.nash@epcc.ed.ac.uk 13 June 2018 1 References Bjarne Stroustrup, Programming: Principles and Practice Using C++ (2nd Ed.). Assumes very little but it s long Bjarne

More information

CS11 Introduction to C++ Fall Lecture 7

CS11 Introduction to C++ Fall Lecture 7 CS11 Introduction to C++ Fall 2012-2013 Lecture 7 Computer Strategy Game n Want to write a turn-based strategy game for the computer n Need different kinds of units for the game Different capabilities,

More information

CPSC 427a: Object-Oriented Programming

CPSC 427a: Object-Oriented Programming CPSC 427a: Object-Oriented Programming Michael J. Fischer Lecture 5 September 15, 2011 CPSC 427a, Lecture 5 1/35 Functions and Methods Parameters Choosing Parameter Types The Implicit Argument Simple Variables

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.! True object-oriented programming: Dynamic Objects Reference Variables D0010E Object-Oriented Programming and Design Lecture 3 Static Object-Oriented Programming UML" knows-about Eckel: 30-31, 41-46, 107-111,

More information

The development of a CreditCard class

The development of a CreditCard class The development of a CreditCard class (an introduction to object-oriented design in C++) January 20, 2006 Rather than explain the many aspects involved in a fully-fledged, yet complex example, we will

More information

Principles of Programming Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns

Principles of Programming Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns Pointers, Dynamic Memory Allocation, Character Arrays, and Buffer Overruns What is an array? Pointers Memory issues The name of the array is actually a memory address. You can prove this by trying to print

More information

Lecture 13: more class, C++ memory management

Lecture 13: more class, C++ memory management CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 13:

More information

CS 32. Lecture 2: objects good?

CS 32. Lecture 2: objects good? CS 32 Lecture 2: objects good? Double Vision This course has two main tracks Unix/shell stuff Object-Oriented Programming Basic C++ familiarity Off by one! Another Troika This class has three main texts

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

Data Structures using OOP C++ Lecture 3

Data Structures using OOP C++ Lecture 3 References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.

More information

1. Write two major differences between Object-oriented programming and procedural programming?

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

Evaluation Issues in Generic Programming with Inheritance and Templates in C++

Evaluation Issues in Generic Programming with Inheritance and Templates in C++ Evaluation Issues in Generic Programming with Inheritance and Templates in C++ Emil Vassev, Joey Paquet Department of Computer Science and Software Engineering Concordia University Montreal, Quebec, H3G

More information

Classes and Objects. Class scope: - private members are only accessible by the class methods.

Classes and Objects. Class scope: - private members are only accessible by the class methods. Class Declaration Classes and Objects class class-tag //data members & function members ; Information hiding in C++: Private Used to hide class member data and methods (implementation details). Public

More information

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example CS 311 Data Structures and Algorithms Lecture Slides Friday, September 11, 2009 continued Glenn G. Chappell

More information

Supporting Class / C++ Lecture Notes

Supporting Class / C++ Lecture Notes Goal Supporting Class / C++ Lecture Notes You started with an understanding of how to write Java programs. This course is about explaining the path from Java to executing programs. We proceeded in a mostly

More information

Chapter 10. Pointers and Dynamic Arrays. Copyright 2016 Pearson, Inc. All rights reserved.

Chapter 10. Pointers and Dynamic Arrays. Copyright 2016 Pearson, Inc. All rights reserved. Chapter 10 Pointers and Dynamic Arrays Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Pointers Pointer variables Memory management Dynamic Arrays Creating and using Pointer arithmetic

More information

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

6. Pointers, Structs, and Arrays. March 14 & 15, 2011 March 14 & 15, 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Recapitulation Pointers Dynamic Memory Allocation Structs Arrays Bubble Sort Strings Einführung

More information

Chapter 10 Pointers and Dynamic Arrays. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

Chapter 10 Pointers and Dynamic Arrays. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo Chapter 10 Pointers and Dynamic Arrays 1 Learning Objectives Pointers Pointer variables Memory management Dynamic Arrays Creating and using Pointer arithmetic Classes, Pointers, Dynamic Arrays The this

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information