Object Oriented Software Design II
|
|
|
- Alice Montgomery
- 10 years ago
- Views:
Transcription
1 Object Oriented Software Design II Introduction to C++ Giuseppe Lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Outline 1 Course contents 2 Introduction to C++ 3 Classes 4 Access Control 5 Memory layout 6 Pointers 7 Function Overloading 8 Exercise G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
2 Prerequisites To understand this course, you should at least know the basic C syntax functions declaration and function call, global and local variables pointers (will do again during the course) structures First part of the course: classes Classes, objects, memory layout Pointer and references Copying Inheritance, multiple inheritance Access rules Public, protected and private inheritance Exceptions G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Summary - cont. Second part: templates Templates The Standard Template Library Third part: new standard What does it change lambda functions auto move semantic new STL classes Safety to exceptions Fourth part: patterns Some patterns in C++ Function objects Template patterns Meta-programming with templates Fifth part: libraries Thread library, synchronization Futures and promises The Active Object pattern G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
3 Classes C is not a high-level language. Brian Kernighan, inventor of C with D. M. Ritchie Those types are not abstract: they are as real as int and float Doug McIlroy Actually I made up the term object-oriented, and I can tell you I did not have C++ in mind. Alan Kay G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Abstraction An essential instrument for OO programming is the support for data abstraction C++ permits to define new types and their operations Creating a new data type means defining: Which elements it is composed of (internal structure); How it is built/destroyed (constructor/destructor); How we can operate on this type (methods/operations). G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
4 Data abstraction in C We can do data abstraction in C (and in almost any language) typedef struct complex { double real_; double imaginary_; cmplx; void add_to(cmplx *a, cmplx *b); void sub_from(cmplx *a, cmplx *b); double get_module(cmplx *a); We have to pass the main data to every function name clashing: if another abstract type defines a function add_to(), the names will clash! No information hiding: any user can access the internal data using them improperly G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Classical example class Complex { double real_; double imaginary_; Complex(); Complex(double a, double b); ~Complex(); double real() const; double imaginary() const; double module() const; Complex &operator =(const Complex &a); Complex &operator+=(const Complex &a); Complex &operator-=(const Complex &a)); G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
5 How to use complex Complex c1; Complex c2(1,2); Complex c3(3,4); // default constructor // constructor // constructor cout << "c1=(" << c1.real() << "," << c1.imaginary() << ")" << endl; c1 = c2; // assignment c3 += c1; // operator += c1 = c2 + c3; // ERROR: operator + not yet defined G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Using new data types The new data type is used just like a predefined data type it is possible to define new functions for that type: real(), imaginary() and module() It is possible to define new operators =, += and -= The compiler knows automatically which function/operator must be invoked C++ is a strongly typed language the compiler knows which function to invoke by looking at the type G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
6 Class Class is the main construct for building new types in C++ A class is almost equivalent to a struct with functions inside In the C-style programming, the programmer defines structs, and global functions to act on the structs In C++-style programming, the programmer defines classes with embedded functions class MyClass { int a; int myfunction(int param); Class declaration Remember the semicolon! G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Members A class contains members A member can be any kind of variable (member variables) any kind of function (member functions or methods) class MyClass { int a; double b; int c; member variables (private) member variable (public) void f(); int geta(); int modify(double b); member functions (public) G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
7 Declaring objects of a class: constructor An object is an instance of a class An object is created by calling a special function called constructor A constructor is a function that has the same name of the class and no return value It may or may not have parameters; It is invoked in a special way class MyClass { MyClass() { cout << "Constructor"<<endl; MyClass obj; Declaration of the constructor Invoke the constructor to create an object G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Constructor - II Constructors with parameters class MyClass { int a; int b; MyClass(int x); MyClass(int x, int y); MyClass obj; MyClass obj1(2); MyClass obj2(2,3); int myvar(2); double pi(3.14); A class can have many constructors This is an error, no constructor without parameters Calls the first constructor Calls the second constructor Same syntax is valid for primitive data types G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
8 Default constructor Rules for constructors If you do not specify a constructor, a default one with no parameters is provided by the compiler If you provide a constructor (any constructor) the compiler will not provide a default one for you Constructors are used to initialise members class MyClass { int a; int b; MyClass(int x, int y) { a = x; b = 2*y; G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Initialization list Members can be initialised through a special syntax This syntax is preferable (the compiler can catch some obvious mistake) use it whenever you can (i.e. almost always) class MyClass { int a; int b; MyClass(int x, int y) : a(x), b(y) { // other initialisation A comma separated list of constructors, following the : G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
9 Accessing member objects Members of one object can be accessed using the dot notation, similarly to structs in C class MyClass { int a; int f(); void g(int i, int ii); MyClass x; MyClass y; x.a = 5; y.a = 7; x.f(); y.g(5, 10); Assigning to a member variable of object x Assigning to a member variable of object y Calling member function f() of object x Calling member function g() of object y G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Implementing member functions You can implement a member function (including constructors) in a separate.cpp file complex.h class Complex { double real_; double img_;... double module() const;... complex.cpp double Complex::module() { double temp; temp = real_ * real_ + img_ * img_; return temp; This is preferable most of the times put implementation in include files only if you hope to use in-lining optimisation G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
10 Accessing internal members double Complex::module() const { double temp; temp = real_ * real_ + img_ * img_; return temp; scope resolution access to internal variable The :: operator is called scope resolution operator like any other function, we can create local variables member variables and functions can be accessed without dot or arrow G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Access control A member can be: private: only member functions of the same class can access it; other classes or global functions can t protected: only member functions of the same class or of derived classes can access it: other classes or global functions can t every function can access it class MyClass { private: int a; int c; MyClass data; cout << data.a; cout << data.c; // ERROR! // OK G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
11 Access control Default is private An access control keyword defines access until the next access control keyword class MyClass { int a; double b; int c; void f(); int geta(); private: int modify(double b); private (default) public private again G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Access control and scope int xx; class A { int xx; void f(); global variable member variable void A::f() { xx = 5; ::xx = 3; access local xx access global xx xx = ::xx + 2; G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
12 Why access control? The technique of declaring private members is also called encapsulation In this way we can precisely define what is interface and what is implementation The public part is the interface to the external world The private part is the implementation of that interface When working in a team, each group take care of a module To ensure that the integration is done correctly and without problems, the programmers agree on interfaces G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Private Some people think that private is synonym of secret they complain that the private part is visible in the header file private means not accessible from other classes and does not mean secret The compiler needs to know the size of the object, in order to allocate memory to it In an hypothetical C++, if we hide the private part, the compiler cannot know the size of the object G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
13 Friends class A { friend class B; int y; void f(); int g(); B is friend of A class B { int x; void f(a &a); void B::f(A &a) { x = a.y; a.f(); B can access private members of A G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Friend functions and operator Even a global function or a single member function can be friend of a class class A { friend B::f(); friend h(); int y; void f(); int g(); friend member function friend global function It is better to use the friend keyword only when it is really necessary because it breaks the access rules. "Friends, much as in real life, are often more trouble than their worth." Scott Meyers G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
14 Nested classes It is possible to declare a class inside another class Access control keywords apply class A { class B { int a; int b; B obj; void f(); Class B is private to class A: it is not part of the interface of A, but only of its implementation. However, A is not allowed to access the private part of B!! (A::f() cannot access B::a). To accomplish this, we have to declare A as friend of B G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Memory layout Let us recapitulate the rules for the lifetime and visibility of variables Global variables are defined outside of any function. Their lifetime is the duration of the program: they are created when the program is loaded in memory, and deleted when the program exits Local variables are defined inside functions or inside code blocks (delimited by curly braces { and ). Their lifetime is the execution of the block: they are created before the block starts executing, and destroyed when the block completes execution Global and local variables are in different memory segments, and are managed in different ways G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
15 Memory segments The main data segments of a program are shown below The BSS segment contains global variables. It is divided into two segments, one for initialised data (i.e. data that is initialised when declared), and non-initialised data. The size of this segment is statically decided when the program is loaded in memory, and can never change during execution The STACK segment contains local variables Its size is dynamic: it can grow or shrink, depending on how many local variables are in the current block The HEAP segment contains dynamic memory that is managed directly by the Here programmer is an example: HEAP STACK BSS Dynamic memory Local variables Global variables G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Example int a = 5; // initialised global data int b; // non initialised global data int f(int i) // i, d and s[] are local variables { // will be created on the stack when double d; // function f() is invoked char s[] = "Lipari";... int main() { int s, z; // local variables, are created on the stack // when the program starts f(); // here f() is invoked, so the stack for f() is created G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
16 Pointer A pointer is a variable that can hold a memory address Basic syntax: int a = 5; int b = 7; int *p; p = &a; cout << p << endl; cout << *p << endl; *p = 6; p = &b; cout << *p << endl; Declaration of a pointer to an integer variable p takes the address of a print the address prints the value in a changes the value in a = 6 now p points to b prints the value in b G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Arrays The name of an array is equivalent to a constant pointer to the first element With non-const pointers we can do pointer arithmetic char name[] = "Giuseppe"; cout << *name << endl; char *p = name; p++; assert(p == name+1); while (*p!= 0) cout << *(p++); cout << endl; prints G declares a pointer to the first element of the array Increments the pointer, now points to i this assertion is correct zero marks the end of the string prints the content of address pointed by p, and increments it G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
17 Dynamic memory Dynamic memory is managed by the user In C: to allocate memory, call function malloc to deallocate, call free Both take pointers to any type, so they are not type-safe In C++ to allocate memory, use operator new to deallocate, use operator delete they are more type-safe G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 The new operator The new and delete operators can be applied to primitive types, and classes operator new automatically calculates the size of memory to be allocated int *p = new int(5); class A {... A *q = new A(); delete p; delete q; Allocates an integer pointed by p Does two things: 1) Allocates memory for an object of class A 2) calls the constructor of A() Deallocates the memory pointed by p Does two things: 1) Calls the destructor for A 2) deallocates the memory pointed by q G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
18 Destructor The destructor is called just before the object is deallocated. It is always called both for all objects (allocated on the stack, in global memory, or dynamically) If the programmer does not define a constructor, the compiler automatically adds one by default (which does nothing) Syntax class A {... A() {... // constructor ~A() {... // destructor The destructor never takes any parameter G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Example See./examples/01.summary-examples/destructor.cpp G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
19 Why a destructor A destructor is useful when an object allocates memory so that it can deallocate it when the object is deleted class A {... class B { A *p; B() { p = new A(); ~B() { delete p; p is initialised when the object is created The memory is deallocated when the object is deleted G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 New and delete for arrays To allocate an array, use this form int *p = new int[5]; // allocates an array of 5 int... delete [] p; // notice the delete syntax A *q = new A[10]; // allocates an array of // objects of type A delete [] q; In the second case, the default constructor is called to build the 10 objects Therefore, this can only be done is a default constructor (without arguments) is available G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
20 Null pointer The address 0 is an invalid address (no data and no function can be located at 0) therefore, in C/C++ a pointer to 0 is said to be a null pointer, which means a pointer that points to nothing. Dereferencing a null pointer is always a bad error (null pointer exception, or segmentation fault) In C, the macro NULL is used to mark 0, or a pointer to 0 however, 0 can be seen to be of integer type, or a null pointer In the new C++, the null pointer is indicated with the constant nullptr this constant cannot be automatically converted to an integer G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Function overloading In C++, the argument list is part of the name of the function this mysterious sentence means that two functions with the same name but with different argument list are considered two different functions and not a mistake If you look at the internal name used by the compiler for a function, you will see three parts: the class name the function name the argument list G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
21 Function overloading class A { void f(int a); void f(int a, int b); void f(double g); class B { void f(int a); A_f_int A_f_int_int A_f_double B_f_int To the compiler, they are all different functions! beware of the type... G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Which one is called? class A { void f(int a); void f(int a, int b); void f(double g); class B { void f(int a); A a; B b; a.f(5); b.f(2); a.f(3.0); a.f(2,3); a.f(2.5, 3); A_f_int B_f_int A_f_double A_f_int_int A_f_int_int G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
22 Return values Notice that return values are not part of the name the compiler is not able to distinguish two functions that differs only on return values class A { int floor(double a); double floor(double a); This causes a compilation error It is not possible to overload a return value G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Default arguments in functions Sometime, functions have long argument lists Some of these arguments do not change often We would like to set default values for some argument This is a little different from overloading, since it is the same function we are calling! int f(int a, int b = 0); f(12); // it is equivalent to f(12,0); The combination of overloading with default arguments can be confusing it is a good idea to avoid overusing both of them G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
23 Time to do an example Let us implement a Stack of integers class Stack stack;... stack.push(12); stack.push(7);... cout << stack.pop(); cout << stack.pop(); G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54 Interface class Stack {... Stack(int maxsize); ~Stack(); void push(int a); int pop(); int peek(); int size(); Constructor: maxsize is the maximum number of elements on the stack Destructor Returns the top element Returns the current number of elements Hint: Use an array to store the elements G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 20, / 54
Object Oriented Software Design II
Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
Glossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON
PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London
An Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
El Dorado Union High School District Educational Services
El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.
Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)
Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Duration of Course: 6 Months Fees: Rs. 25,000/- (including Service Tax) Eligibility: B.E./B.Tech., M.Sc.(IT/ computer
6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang
6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang Today s topics Why objects? Object-oriented programming (OOP) in C++ classes fields & methods objects representation
Object Oriented Software Design II
Object Oriented Software Design II Real Application Design Christian Nastasi http://retis.sssup.it/~lipari http://retis.sssup.it/~chris/cpp Scuola Superiore Sant Anna Pisa April 25, 2012 C. Nastasi (Scuola
13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
C++ Programming Language
C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract
KITES TECHNOLOGY COURSE MODULE (C, C++, DS)
KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php [email protected] [email protected] Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points
Fundamentals of Java Programming
Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors
Course notes Standard C++ programming
Department of Cybernetics The University of Reading SE2B2 Further Computer Systems Course notes Standard C++ programming by Dr Virginie F. Ruiz November, 03 CREATING AND USING A COPY CONSTRUCTOR... 27
www.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions
Chapter 4 OOPS WITH C++ Sahaj Computer Solutions 1 Session Objectives Classes and Objects Class Declaration Class Members Data Constructors Destructors Member Functions Class Member Visibility Private,
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
Chapter 13 Storage classes
Chapter 13 Storage classes 1. Storage classes 2. Storage Class auto 3. Storage Class extern 4. Storage Class static 5. Storage Class register 6. Global and Local Variables 7. Nested Blocks with the Same
CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator=
CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator= We already know that the compiler will supply a default (zero-argument) constructor if the programmer does not specify one.
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
C++ Crash Kurs. C++ Object-Oriented Programming
C++ Crash Kurs C++ Object-Oriented Programming Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ classes A class is user-defined type
C++ Support for Abstract Data Types
Topics C++ Support for Abstract Data Types Professor Department of EECS [email protected] Vanderbilt University www.cs.wustl.edu/schmidt/ (615) 343-8197 Describing Objects Using ADTs Built-in vs.
N3458: Simple Database Integration in C++11
N3458: Simple Database Integration in C++11 Thomas Neumann Technische Univeristät München [email protected] 2012-10-22 Many applications make use of relational database to store and query their data. However,
1 Abstract Data Types Information Hiding
1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content
C++ Overloading, Constructors, Assignment operator
C++ Overloading, Constructors, Assignment operator 1 Overloading Before looking at the initialization of objects in C++ with constructors, we need to understand what function overloading is In C, two functions
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive
Konzepte objektorientierter Programmierung
Konzepte objektorientierter Programmierung Prof. Dr. Peter Müller Werner Dietl Software Component Technology Exercises 3: Some More OO Languages Wintersemester 04/05 Agenda for Today 2 Homework Finish
Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009
Software Engineering Concepts: Testing Simple Class Example continued Pointers & Dynamic Allocation CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009 Glenn G. Chappell Department
Chapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example
Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics
Applied Informatics C++ Coding Style Guide
C++ Coding Style Guide Rules and Recommendations Version 1.4 Purpose of This Document This document describes the C++ coding style employed by Applied Informatics. The document is targeted at developers
C++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
CEC225 COURSE COMPACT
CEC225 COURSE COMPACT Course GEC 225 Applied Computer Programming II(2 Units) Compulsory Course Duration Two hours per week for 15 weeks (30 hours) Lecturer Data Name of the lecturer: Dr. Oyelami Olufemi
Curriculum Map. Discipline: Computer Science Course: C++
Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations
Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1
Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1 Introduction to Classes Classes as user-defined types We have seen that C++ provides a fairly large set of built-in types. e.g
Design Patterns in C++
Design Patterns in C++ Concurrency Patterns Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa May 4, 2011 G. Lipari (Scuola Superiore Sant Anna) Concurrency Patterns May 4,
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
Java (12 Weeks) Introduction to Java Programming Language
Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short
C++FA 3.1 OPTIMIZING C++
C++FA 3.1 OPTIMIZING C++ Ben Van Vliet Measuring Performance Performance can be measured and judged in different ways execution time, memory usage, error count, ease of use and trade offs usually have
Tutorial on C Language Programming
Tutorial on C Language Programming Teodor Rus [email protected] The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:
Coding conventions and C++-style
Chapter 1 Coding conventions and C++-style This document provides an overview of the general coding conventions that are used throughout oomph-lib. Knowledge of these conventions will greatly facilitate
Introduction to Programming Block Tutorial C/C++
Michael Bader Master s Program Computational Science and Engineering C/C++ Tutorial Overview From Maple to C Variables, Operators, Statements Functions: declaration, definition, parameters Arrays and Pointers
Evolution of the Major Programming Languages
142 Evolution of the Major Programming Languages Object Oriented Programming: Smalltalk Object-Oriented: It s fundamental characteristics are: Data abstraction, Inheritance and Dynamic Binding. The essence
Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example
Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include
CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing
CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects
C++ Language Tutorial
cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain
Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
D06 PROGRAMMING with JAVA. Ch3 Implementing Classes
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch3 Implementing Classes PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com,
Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.
Coding Rules Section A: Linux kernel style based coding for C programs Coding style for C is based on Linux Kernel coding style. The following excerpts in this section are mostly taken as is from articles
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
Variable Base Interface
Chapter 6 Variable Base Interface 6.1 Introduction Finite element codes has been changed a lot during the evolution of the Finite Element Method, In its early times, finite element applications were developed
OpenCL Static C++ Kernel Language Extension
OpenCL Static C++ Kernel Language Extension Document Revision: 04 Advanced Micro Devices Authors: Ofer Rosenberg, Benedict R. Gaster, Bixia Zheng, Irina Lipov December 15, 2011 Contents 1 Overview... 3
Chapter One Introduction to Programming
Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of
CS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator=
CS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator= Much of the surrounding prose written by Andy Maag, CS193D instructor from years ago. The compiler will supply a default (zero-argument)
5 CLASSES CHAPTER. 5.1 Object-Oriented and Procedural Programming. 5.2 Classes and Objects 5.3 Sample Application: A Clock Class
CHAPTER 5 CLASSES class head class struct identifier base spec union class name 5.1 Object-Oriented and Procedural Programming 5.2 Classes and Objects 5.3 Sample Application: A Clock Class 5.4 Sample Application:
CISC 181 Project 3 Designing Classes for Bank Accounts
CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on
Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists
Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse
BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering
BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security & BSc. (Hons.) Software Engineering Cohort: BIS/05/FT BCNS/05/FT BSE/05/FT Examinations for 2005-2006 / Semester
INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011
INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011 1 Goals of the Lecture Present an introduction to Objective-C 2.0 Coverage of the language will be INCOMPLETE
Java Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
Computer Programming C++ Classes and Objects 15 th Lecture
Computer Programming C++ Classes and Objects 15 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2013 Eom, Hyeonsang All Rights Reserved Outline
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;
C++ Outline Notes taken from: - Drake, Caleb. EECS 370 Course Notes, University of Illinois Chicago, Spring 97. Chapters 9, 10, 11, 13.1 & 13.2 - Horstman, Cay S. Mastering Object-Oriented Design in C++.
Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c
Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection
Programming languages C
INTERNATIONAL STANDARD ISO/IEC 9899:1999 TECHNICAL CORRIGENDUM 2 Published 2004-11-15 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE
Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
VB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER
WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER Course Outline (2015) Basic Programming With Procedural & Object Oriented Concepts (C, C++) Training Office# Road: 11, House: 1 A, Nikunja 2, Khilkhet,
Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++
Question Bank UNIT 1: Introduction to C++ 1. What is Procedure-oriented Programming System? Dec 2005 2. What is Object-oriented Programming System? June 2006 3. Explain the console I/O functions supported
Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)
Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking
Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved.
The Secret Partner Pattern Revision 3a by Bill Trudell, July 23, 2001 Submitted to the Pattern Languages of Programs Shepherd: Neil Harrison PC Member: Kyle Brown Thumbnail This paper describes the Secret
C Compiler Targeting the Java Virtual Machine
C Compiler Targeting the Java Virtual Machine Jack Pien Senior Honors Thesis (Advisor: Javed A. Aslam) Dartmouth College Computer Science Technical Report PCS-TR98-334 May 30, 1998 Abstract One of the
CORBA Programming with TAOX11. The C++11 CORBA Implementation
CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy
Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions
COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement
ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science
ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science Program Schedule CTech Computer Science Credits CS101 Computer Science I 3 MATH100 Foundations of Mathematics and
Ch 7-1. Object-Oriented Programming and Classes
2014-1 Ch 7-1. Object-Oriented Programming and Classes May 10, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;
Subject Name: Object Oriented Programming in C++ Subject Code: 2140705
Faculties: L.J. Institute of Engineering & Technology Semester: IV (2016) Subject Name: Object Oriented Programming in C++ Subject Code: 21405 Sr No UNIT - 1 : CONCEPTS OF OOCP Topics -Introduction OOCP,
Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum
Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum James P. Kelsh [email protected] Roger Y. Lee [email protected] Department of Computer Science Central
09336863931 : provid.ir
provid.ir 09336863931 : NET Architecture Core CSharp o Variable o Variable Scope o Type Inference o Namespaces o Preprocessor Directives Statements and Flow of Execution o If Statement o Switch Statement
Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism
Polymorphism Problems with switch statement Programmer may forget to test all possible cases in a switch. Tracking this down can be time consuming and error prone Solution - use virtual functions (polymorphism)
Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:
Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of
Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct
Dr. Martin O. Steinhauser University of Basel Graduate Lecture Spring Semester 2014 Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Friday, 7 th March
Illustration 1: Diagram of program function and data flow
The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline
Binary storage of graphs and related data
EÖTVÖS LORÁND UNIVERSITY Faculty of Informatics Department of Algorithms and their Applications Binary storage of graphs and related data BSc thesis Author: Frantisek Csajka full-time student Informatics
Lecture 5: Java Fundamentals III
Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd
Short Notes on Dynamic Memory Allocation, Pointer and Data Structure
Short Notes on Dynamic Memory Allocation, Pointer and Data Structure 1 Dynamic Memory Allocation in C/C++ Motivation /* a[100] vs. *b or *c */ Func(int array_size) double k, a[100], *b, *c; b = (double
Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553]
Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553] Books: Text Book: 1. Bjarne Stroustrup, The C++ Programming Language, Addison Wesley 2. Robert Lafore, Object-Oriented
Objects and classes. Objects and classes. Jarkko Toivonen (CS Department) Programming in Python 1
Objects and classes Jarkko Toivonen (CS Department) Programming in Python 1 Programming paradigms of Python Python is an object-oriented programming language like Java and C++ But unlike Java, Python doesn
Netscape Internet Service Broker for C++ Programmer's Guide. Contents
Netscape Internet Service Broker for C++ Programmer's Guide Page 1 of 5 [Next] Netscape Internet Service Broker for C++ Programmer's Guide Nescape ISB for C++ - Provides information on how to develop and
Data Structures Using C++ 2E. Chapter 5 Linked Lists
Data Structures Using C++ 2E Chapter 5 Linked Lists Test #1 Next Thursday During Class Cover through (near?) end of Chapter 5 Objectives Learn about linked lists Become aware of the basic properties of
