Advanced C++ for Java Programmers

Size: px
Start display at page:

Download "Advanced C++ for Java Programmers"

Transcription

1 Module 7503a Michael Mäder Web:

2 Semester organisation Theoretical lecture with practical hands-on. Two exams (will be announced) Homework (optional, bonus for end grade) Eventually a Mini-Project 2

3 End grade 1/2 First exam 1/2 Second exam Additional bonus (maximum 1 point) of the end grade depending of the homework Example: 4.5 first exam, 5 second exam and.25 points on homework gives: ( )/ = 5 3

4 Information and Bibliography (printed at the school s printing service) A lot of information can be found on the web (e.g. Wikipedia, The C++ Programming Language, Bjarne Stroustrup, Addison Wesley (The C++ Bible!) C++ in a nutshell, Ray Lischner, O Reilly Practical C++ Programming, Steve Oualline, O Reilly... and a lot more 4

5 Semester agenda The following major topics will be discussed during the semester: Differences and similarities C++ specific stuff The standard template library (STL) Function pointers and function objects Memory management Casting Runtime Type Identification (RTTI) Code Optimization (optional) C language compatibility issues (optional) C++ idioms (optional) 5

6 Major reasons for Java to know C++ Native classes for Java are written in C++ Native code generation (better speed performance, less resource wasting) Tremendous amount of C++ programs and libraries exist Direct access to operating system. Hardware access C-style pointers still exist. Useful also for hardware and port access 6

7 Differences and Similarities

8 C++ Overview - Introduction Developed in early 1980 by Bjarne Stroustrup The main goals of its introduction was: Introduce object-orientation to classical C Be backward compatible to C C++ design decision were made to enhance performance Just a few standard library directly integrated with the language. But a lot of external libraries available (not in the scope of this course) 8

9 Contribution of other languages to Java Simula 9 Ada Sm alltalk C Pascal Eiffel Objective-C C++ Java Object- Pascal Oberon-2 Modula-2 Modula-3

10 Transformation from a C++ source code to an executable program High-level code C++ source code Compiler Assembly-language program Assembler Object code Linker Library 10 Executable program

11 Syntactical Similarities and Differences - main, argc, argv Main program function is the entry point of the application: int main (int argc, char* argv[]) Always a function outside of a class Returns 0 if okay and non-zero otherwise First argument (argv[0]) contains the name and the path of the program Example: /home/mdm3/prg arg1 arg2 This gives the following arguments: argv[0]: /home/mdm3/prg argv[1]: arg1 argv[2]: arg2 argc: 3 11

12 Syntactical Similarities and Differences - Classes in C++ (1) Data members : Member functions : Attributes Methods Class declaration: Describe the member functions and the data members of the class This is described in.h files (e.g. queue.h) Class definition: Contains the code that implements the member functions This is described in.cpp files (e.g. queue.cpp) 12

13 Syntactical Similarities and Differences - Classes in C++ (2) Class declaration Class TagName // class body }; Class body Data members Member functions 13

14 Syntactical Similarities and Differences - Classes in C++ (3) Example class IntQueue public: int size( void ); int isempty( void ); int isfull( void ); void enqueue( int elem ); int serve( void ); protected: int queuesize; int front; int rear; int array[100]; }; 14

15 Syntactical Similarities and Differences - Classes in C++ / Access levels Public member Accessible from anywhere Protected member Behaves as public to a derived class Behaves as private to the rest Private member (default access level) Only accessible by the member functions of its class 15

16 Syntactical Similarities and Differences - Classes in C++ / Class definition #include "IntQueue.h int IntQueue::size( void ) return queuesize; } int IntQueue::isEmpty( void ) return queuesize == 0; } int IntQueue::isFull( void ) return queuesize == 100; } void IntQueue::enqueue( int elem ) if(! isfull() ) rear = ( ++rear % 100 ); array[ rear ] = elem; queuesize++; } } int IntQueue::serve( void ) if(! isempty() ) Object ret = array[front]; front = ( ++front % 100 ); queuesize--; return ret; } else // exception (see later!) } 16

17 Syntactical Similarities and Differences - const member functions (1) Keyword const defines a constant variable (in Java final) The attempt to modify a const variable will create a compiler error const char blank = ; blank = x ; compilation error Class objects can also be const, thus safe and unsafe member functions exist const IntQueue queue; int emtpy = queue.isempty(); queue.enqueue (13); // safe //unsafe 17

18 Syntactical Similarities and Differences - const member functions (2) Safe member functions are indicated safe by specifying them as const class IntQueue public: int size( void ) const; int isempty( void ) const; int isfull( void ) const; void enqueue( int elem ); int serve(); //... }; The const declaration has to be repeated in the implementation int IntQueue::isEmpty( void ) const return queuesize == 0; } 18

19 Syntactical Similarities and Differences - const member functions (3) It is illegal to declare const a member function that modifies a data member. void IntQueue::enqueue( int elem ) const if(! isfull() ) rear = ( ++rear % arraysize ); array[ rear ] = elem; queuesize++; } } 19

20 Syntactical Similarities and Differences - Instantiation and object access (1) Two different instantiations exist in C++ Static instantiation (automatic allocation and freeing of memory) IntQueue queue; // executes constructor... queue.enqueue(7); } // here, the queue object is destroyed Java doesn t use the static way, it uses the dynamic allocation! 20

21 Syntactical Similarities and Differences - Instantiation and object access (2) Dynamic instantiation (explicit usage of new and delete). Java uses the same mechanism. The only exception is the automatic garbage collector, which doesn t exist in C++ IntQueue* queueptr; // creation of IntQueue pointer // allocation of memory and execution of the constructor queueptr = new IntQueue(); (*queueptr).enqueue(13); // dereferencing method queueptr->enqueue(13); // abbreviated method delete queueptr; // destructor and freeing of memory The -> operator dereference an object for function using 21

22 Syntactical Similarities and Differences - Instantiation and object access (3) No garbage collection exists in C++, for this reason, the programmer is responsible to destroy any dynamically created objects. The delete (free in Java) command will be used for this purpose. The creation and destruction of dynamic arrays looks like this: // create an array of 10 IntQueue objects IntQueue* queues = new IntQueue [10] // destruct the 10 queues delete [] queues; 22

23 Syntactical Similarities and Differences - Reference Types (1) A reference type declares a new symbol for an existing variable or object int i = 10; int& p = i; // p stands for the same adr as i int m = p; // m = 10 int* r = &p; // r is a pointer to i A reference type must always be initialized int& q; // error, not initialized In the example above p means the same memory place than i Reference type should only be used as argument or return type of functions. (They can be very confusing) 23

24 Syntactical Similarities and Differences - Reference Types (2) C++ passes arguments by value. Thus, modifications are made on local copies and the arguments remain untouched void swap (int v1, int v2)...} Using pointers is a work around void pswap (int* v1, int* v2)...} The call would be: pswap(&i, &j); Another possibility is to use the reference types void rswap (int& v1, int& v2)...} The call would be: rswap(i, j); The reference types are used in the following cases: When the function arguments have to altered in the function (like Java) When large objects have to be passed (time and space costs) 24

25 Syntactical Similarities and Differences - Reference Types (3) Reference types can also be used as return type. This avoids the creation of a copy of a huge object HugeObj addobjects( HugeObj& l, HugeObj& r) } HugeObj result;... return result; // the whole object is copied With a reference type as return type: HugeObj& addobjects( HugeObj& l, HugeObj& r) }... return result; // a reference to result is returned The object result must be a data member of the class HugeObj 25

26 New room allocation Rolex Building, room N321 Still Monday 17h55 19h30 26

27 Syntactical Similarities and Differences - Reference Types - Exercise Exercise 1-1 (page 10) 27

28 Syntactical Similarities and Differences - This pointer (1) Any object instance maintains its own copy of the class data member But only one copy of the member functions exists This presents two problems: As only one instance of a member function exists, it can t be stored inside the class object instance How are the particular data members of a class manipulated within the member function? The this pointer (similar to the this reference in Java) can solve this problem Each class member function contains a pointer of its class type 28

29 Syntactical Similarities and Differences - This pointer (2) The member function void Point::Shift(int dx, int dy) x += dx; y += dy; } Will be internally by the Compiler modified into a nonmember C function like this: void Shift Point(Point* this, int dx, int dy) } this->x += dx; this->y += dy; 29

30 Syntactical Similarities and Differences - This pointer (3) Invocation of the member function mypoint.shift(2, 3); Will be translated by the compiler to Shift Point(&myPoint, 2, 3); The programmer can also explicitly reference the this pointer bool Point::isEqual(Point& p) if (this == &p) return true; // physical eq return ((x==p.x)&&(y==p.y)); } 30

31 Syntactical Similarities and Differences Static Class Members (1) All instances of a class have access to the same variable (e.g. counters, flags, Mutex,...) For example a counter of object instances The same than class methods and class data fields in Java This global variable for its class provides two major advantages over the usage of global variables: Information hiding (declaring as private) The static member is not in the program s global name space (avoids name conflicts) 31

32 Syntactical Similarities and Differences Static Class Members (2) Definition of the single static member in a class with the keyword static in front of the data type class TempFile public: static int nrofopenedfiles(void); private: static int nroffiles; } 32

33 Syntactical Similarities and Differences Static Class Members (3) The initialization must be done outside the class definition (like a non-member variable) Normally done in the definition file (e.g. TempFile.cpp) The class scope must be used: int TempFile::nrOfFiles = 0; A member function that accesses only static members may be declared also static (see slide before) Accessing a static data member is like accessing any other data member. 33

34 Syntactical Similarities and Differences Static Class Members (4) A static member function has no this pointer A static member and/or a static member function can be accessed respectively invoked directly (even if no object of the class exists) openfiles = TempFile::nrOfOpenedFiles(); 34

35 Syntactical Similarities and Differences Inline functions (1) Inline member functions are declared and defined within its class Compiler optimization can reduce call overhead of inline functions, by calling directly the compiled code (inline expansion) The inline specifier forces the compiler to try the inline expansion Inline requests are reserved for small, frequently used functions (e.g. operator functions, getter, setter,...) Inline functions are used to replace the C-style macros (e.g. #define max(x, y) ((x > y)? x: y)) Inline functions are type-safe!!! (Not the case of C- style macros) 35

36 Syntactical Similarities and Differences Inline functions (2) Examples class X public: char* func(void) return i;}; //inline by default } is the same as: inline char* X::func(void) return i; } 36

37 Syntactical Similarities and Differences Inheritance (1) In C++ no explicit base class (as in Java the Object class) exists Any class that does not have a super class is a base class Inheritance should be used in the normal OO way The syntax: class subclass : public baseclass example next slide 37

38 Syntactical Similarities and Differences Inheritance (2) class Vehicle public: Vehicle(); Vehicle(unsigned int wt); unsigned int getweight(void) const; void setweight(unsigned int wt); private: unsigned int weight; }; class LandVehicle : public Vehicle public: LandVehicle(); LandVehicle(unsigned int wt, unsigned int sp); unsigned int getspeed(void) const; void setspeed(unsigned int sp); private: unsigned int speed; }; 38

39 Syntactical Similarities and Differences Inheritance (3) Three inheritance level for the base class exists: Public inheritance The inheritance is part of the interface Private inheritance The inheritance is not part of the interface, it is just an implementation detail Protected inheritance The inheritance is part of the interface of the derived class 39

40 Syntactical Similarities and Differences Inheritance (4) Access specifier in the base class Public inheritance Private inheritance Protected inheritance Private Private member Private member Private member Public Public member Private member Protected member Protected Protected member Private member Protected member 40

41 Syntactical Similarities and Differences Inheritance Initialization of a derived classes (1) Different possibilities to initialize a derived class exists The easy one, where the default constructor of the base class is used: LandVehicle::LandVehicle(unsigned int wt, unsigned int sp) setweight(wt); setspeed(sp); } Not very good, because first the default constructor of Vehicle is called and then the setter method setweight This can be done in one single step 41

42 Syntactical Similarities and Differences Inheritance Initialization of a derived classes (2) Not the base classe s default constructor will be used, but its customized one that already sets the weight of the vehicle. LandVehicle::LandVehicle(unsigned int wt, unsigned int sp) : Vehicle(wt), speed(sp) // nothing to do } The list of the calls right after the constructer is called member initialization list The member initialization list can contain calls to the baseclass constructors as also constructors for class members 42

43 Syntactical Similarities and Differences Multiple inheritance A C++ class can be derived from more than just one super class (not possible in Java) The derivation from multiple classes will be specified in a comma separated list: class Truck : public Engine, public Trailer... } The keyword (public, private or protected) must be repeated before each base class specification. Of course, the access levels can be intermixed! 43

44 Syntactical Similarities and Differences Polymorphism The same operation may behave differently on different classes E.g. the addition operation on an integer behaves different as on a complex number The dynamic binding or late binding decides during runtime which classes operation will be executed Virtual functions uses the dynamic binding Without using virtual functions, no dynamic binding will be performed, even if the pointers are cast to another class type! 44

45 Syntactical Similarities and Differences Polymorphism Virtual functions Virtual declared functions will cope with the previously seen problem, that a cast pointer to an object will execute function of the cast object The keyword virtual for the common methods must be used Only class member functions can be declared as virtual The redefinition of a virtual function in a derived class must match exactly the name, signature and return type of the base class instance If the redefinition doesn t match exactly, the function is not handled as virtual for the derived class 45

46 Syntactical Similarities and Differences Polymorphism Pure Virtual functions (1) Pure virtual functions are functions that aren t declared in the base class, because it makes no sense to call the function on a base class object The Java correspondence are the abstract method Any class that declares or inherits a pure virtual function is a abstract base class The creation of an object of an abstract base class will cause a compile error! A class inheriting from an abstract base class and overriding an pure virtual function will become a concrete (non-abstract) class 46

47 Syntactical Similarities and Differences Polymorphism Pure Virtual functions (2) An abstract base class declares an interface No full set of implementation is needed Similar to Java interface (interfaces doesn t exist in C++) The interface specifies the abstract operations of all derived objects A pure virtual function is declared with a =0 after the argument class Vehicle public: virtual unsigned int getspeed(void) = 0; } 47

48 Syntactical Similarities and Differences Exercises that should be checked and that should count for the bonus must: be mailed to with the Subject: [Exercisex-y] at latest on Monday after, not after 17h00 48

C++ INTERVIEW QUESTIONS

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

More information

C++ Programming Language

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

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

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 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

More information

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship. CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation

More information

The C Programming Language course syllabus associate level

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

More information

Inheritance in Programming Languages

Inheritance in Programming Languages Inheritance in Programming Languages Krishnaprasad Thirunarayan Metadata and Languages Laboratory Department of Computer Science and Engineering Wright State University Dayton, OH-45435 INTRODUCTION Inheritance

More information

Glossary of Object Oriented Terms

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

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

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

More information

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1 The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose

More information

Description of Class Mutation Mutation Operators for Java

Description of Class Mutation Mutation Operators for Java Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea ysma@etri.re.kr Jeff Offutt Software Engineering George Mason University

More information

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding Compiling Object Oriented Languages What is an Object-Oriented Programming Language? Last time Dynamic compilation Today Introduction to compiling object oriented languages What are the issues? Objects

More information

Sources: On the Web: Slides will be available on:

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,

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

CORBA Programming with TAOX11. The C++11 CORBA Implementation

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

More information

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

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)

More information

Java Interview Questions and Answers

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

More information

Comp151. Definitions & Declarations

Comp151. Definitions & Declarations Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

More information

El Dorado Union High School District Educational Services

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.

More information

Konzepte objektorientierter Programmierung

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

More information

On the (un)suitability of Java to be the first programming language

On the (un)suitability of Java to be the first programming language On the (un)suitability of Java to be the first programming language Mirjana Ivanovic Faculty of Science, Department of Mathematics and Informatics Trg Dositeja Obradovica 4, Novi Sad mira @im.ns.ac.yu

More information

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 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

More information

Classes and Pointers: Some Peculiarities (cont d.)

Classes and Pointers: Some Peculiarities (cont d.) Classes and Pointers: Some Peculiarities (cont d.) Assignment operator Built-in assignment operators for classes with pointer member variables may lead to shallow copying of data FIGURE 3-22 Objects objectone

More information

1. Polymorphism in C++...2

1. Polymorphism in C++...2 1. Polymorphism in C++...2 1.1 Polymorphism and virtual functions... 2 1.2 Function call binding... 3 1.3 Virtual functions... 4 1.4 How C++ implements late binding... 6 1.4.1 Why do I have to know at

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

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

More information

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction

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

More information

1.1.3 Syntax The syntax for creating a derived class is very simple. (You will wish everything else about it were so simple though.

1.1.3 Syntax The syntax for creating a derived class is very simple. (You will wish everything else about it were so simple though. Stewart Weiss Inheritance is a feature that is present in many object-oriented languages such as C++, Eiffel, Java, Ruby, and Smalltalk, but each language implements it in its own way. This chapter explains

More information

Evolution of the Major Programming Languages

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

More information

13 Classes & Objects with Constructors/Destructors

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.

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

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

More information

C++FA 5.1 PRACTICE MID-TERM EXAM

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

More information

BCS2B02: OOP Concepts and Data Structures Using C++

BCS2B02: OOP Concepts and Data Structures Using C++ SECOND SEMESTER BCS2B02: OOP Concepts and Data Structures Using C++ Course Number: 10 Contact Hours per Week: 4 (2T + 2P) Number of Credits: 2 Number of Contact Hours: 30 Hrs. Course Evaluation: Internal

More information

CSC230 Getting Starting in C. Tyler Bletsch

CSC230 Getting Starting in C. Tyler Bletsch CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly

More information

CEC225 COURSE COMPACT

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

More information

OpenCL Static C++ Kernel Language Extension

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

More information

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 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

More information

Fundamentals of Java Programming

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

More information

A deeper look at Inline functions

A deeper look at Inline functions A deeper look at Inline functions I think it s safe to say that all Overload readers know what C++ inline functions are. When we declare a function or member function as inline we are trying to avoid the

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

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

More information

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 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

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

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

More information

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

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

More information

CIS 190: C/C++ Programming. Polymorphism

CIS 190: C/C++ Programming. Polymorphism CIS 190: C/C++ Programming Polymorphism Outline Review of Inheritance Polymorphism Car Example Virtual Functions Virtual Function Types Virtual Table Pointers Virtual Constructors/Destructors Review of

More information

Lecture 1: Introduction

Lecture 1: Introduction Programming Languages Lecture 1: Introduction Benjamin J. Keller Department of Computer Science, Virginia Tech Programming Languages Lecture 1 Introduction 2 Lecture Outline Preview History of Programming

More information

Chapter 1 Fundamentals of Java Programming

Chapter 1 Fundamentals of Java Programming Chapter 1 Fundamentals of Java Programming Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The

More information

Moving from CS 61A Scheme to CS 61B Java

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

More information

Advanced Data Structures

Advanced Data Structures C++ Advanced Data Structures Chapter 8: Advanced C++ Topics Zhijiang Dong Dept. of Computer Science Middle Tennessee State University Chapter 8: Advanced C++ Topics C++ 1 C++ Syntax of 2 Chapter 8: Advanced

More information

Basic Logic Gates. Logic Gates. andgate: accepts two binary inputs x and y, emits x & y. orgate: accepts two binary inputs x and y, emits x y

Basic Logic Gates. Logic Gates. andgate: accepts two binary inputs x and y, emits x & y. orgate: accepts two binary inputs x and y, emits x y Basic andgate: accepts two binary inputs x and y, emits x & y x y Output orgate: accepts two binary inputs x and y, emits x y x y Output notgate: accepts one binary input x, emits!y x Output Computer Science

More information

Object Oriented Software Design II

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,

More information

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

An Introduction to Assembly Programming with the ARM 32-bit Processor Family An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

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

More information

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++

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

More information

Compile-time type versus run-time type. Consider the parameter to this function:

Compile-time type versus run-time type. Consider the parameter to this function: CS107L Handout 07 Autumn 2007 November 16, 2007 Advanced Inheritance and Virtual Methods Employee.h class Employee public: Employee(const string& name, double attitude, double wage); virtual ~Employee();

More information

Java Programming Language

Java Programming Language Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming

More information

JAVA - METHODS. Method definition consists of a method header and a method body. The same is shown below:

JAVA - METHODS. Method definition consists of a method header and a method body. The same is shown below: http://www.tutorialspoint.com/java/java_methods.htm JAVA - METHODS Copyright tutorialspoint.com A Java method is a collection of statements that are grouped together to perform an operation. When you call

More information

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

More information

Basics of C++ and object orientation in OpenFOAM

Basics of C++ and object orientation in OpenFOAM Basics of C++ and object orientation in OpenFOAM To begin with: The aim of this part of the course is not to teach all of C++, but to give a short introduction that is useful when trying to understand

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages Course Organization Introduction CSE 307: Principles of Programming Languages Spring 2015 R. Sekar Course Organization Introduction 1 / 34 Topics 1. Course Organization Info and Support Course Description

More information

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance Introduction to C++ January 19, 2011 Massachusetts Institute of Technology 6.096 Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance We ve already seen how to define composite datatypes

More information

Java Application Developer Certificate Program Competencies

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

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming Programming with Data Types to enhance reliability and productivity (through reuse and by facilitating evolution) Object (instance) State (fields) Behavior (methods) Identity

More information

C++ Support for Abstract Data Types

C++ Support for Abstract Data Types Topics C++ Support for Abstract Data Types Professor Department of EECS d.schmidt@vanderbilt.edu Vanderbilt University www.cs.wustl.edu/schmidt/ (615) 343-8197 Describing Objects Using ADTs Built-in vs.

More information

CS11 Advanced C++ Spring 2008-2009 Lecture 9 (!!!)

CS11 Advanced C++ Spring 2008-2009 Lecture 9 (!!!) CS11 Advanced C++ Spring 2008-2009 Lecture 9 (!!!) The static Keyword C++ provides the static keyword Also in C, with slightly different usage Used in two main contexts: Declaring static members of a class

More information

1 Abstract Data Types Information Hiding

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

More information

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint) TN203 Porting a Program to Dynamic C Introduction Dynamic C has a number of improvements and differences compared to many other C compiler systems. This application note gives instructions and suggestions

More information

Tutorial on Writing Modular Programs in Scala

Tutorial on Writing Modular Programs in Scala Tutorial on Writing Modular Programs in Scala Martin Odersky and Gilles Dubochet 13 September 2006 Tutorial on Writing Modular Programs in Scala Martin Odersky and Gilles Dubochet 1 of 45 Welcome to the

More information

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction Standard 2: Technology and Society Interaction Technology and Ethics Analyze legal technology issues and formulate solutions and strategies that foster responsible technology usage. 1. Practice responsible

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

Object Oriented Software Design II

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

More information

Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.

Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the. Objectif This six-day instructor-led course provides students with the knowledge and skills to develop applications in the.net 3.5 using the C# 3.0 programming language. C# is one of the most popular programming

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Introduction to Electrical and Computer Engineering II Lecture 1 Course Overview Welcome! What is this class about? Java programming somewhat software somewhat

More information

Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553]

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

More information

www.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions

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,

More information

Basic Object-Oriented Programming in Java

Basic Object-Oriented Programming in Java core programming Basic Object-Oriented Programming in Java 1 2001-2003 Marty Hall, Larry Brown http:// Agenda Similarities and differences between Java and C++ Object-oriented nomenclature and conventions

More information

Friendship and Encapsulation in C++

Friendship and Encapsulation in C++ Friendship and Encapsulation in C++ Adrian P Robson Department of Computing University of Northumbria at Newcastle 23rd October 1995 Abstract There is much confusion and debate about friendship and encapsulation

More information

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program CS 2112 Lecture 27 Interpreters, compilers, and the Java Virtual Machine 1 May 2012 Lecturer: Andrew Myers 1 Interpreters vs. compilers There are two strategies for obtaining runnable code from a program

More information

Parameter Passing. Parameter Passing. Parameter Passing Modes in Fortran. Parameter Passing Modes in C

Parameter Passing. Parameter Passing. Parameter Passing Modes in Fortran. Parameter Passing Modes in C Parameter Passing In this set of notes you will learn about: Parameter passing modes Call by Call by reference Call by sharing Call by result Call by /result Call by name Subroutine closures as parameters

More information

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) { Operators C and C++ 6. Operators Inheritance Virtual Alastair R. Beresford University of Cambridge Lent Term 2008 C++ allows the programmer to overload the built-in operators For example, a new test for

More information

Grundlagen der Betriebssystemprogrammierung

Grundlagen der Betriebssystemprogrammierung Grundlagen der Betriebssystemprogrammierung Präsentation A3, A4, A5, A6 21. März 2013 IAIK Grundlagen der Betriebssystemprogrammierung 1 / 73 1 A3 - Function Pointers 2 A4 - C++: The good, the bad and

More information

Java from a C perspective. Plan

Java from a C perspective. Plan Java from a C perspective Cristian Bogdan 2D2052/ingint04 Plan Objectives and Book Packages and Classes Types and memory allocation Syntax and C-like Statements Object Orientation (minimal intro) Exceptions,

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Introduction to Objective-C. Kevin Cathey

Introduction to Objective-C. Kevin Cathey Introduction to Objective-C Kevin Cathey Introduction to Objective-C What are object-oriented systems? What is the Objective-C language? What are objects? How do you create classes in Objective-C? acm.uiuc.edu/macwarriors/devphone

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman

More information

Managing Variability in Software Architectures 1 Felix Bachmann*

Managing Variability in Software Architectures 1 Felix Bachmann* Managing Variability in Software Architectures Felix Bachmann* Carnegie Bosch Institute Carnegie Mellon University Pittsburgh, Pa 523, USA fb@sei.cmu.edu Len Bass Software Engineering Institute Carnegie

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

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

More information

5 Arrays and Pointers

5 Arrays and Pointers 5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of

More information

Getting Started with the Internet Communications Engine

Getting Started with the Internet Communications Engine Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2

More information

Informatica e Sistemi in Tempo Reale

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)

More information

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio. Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Names, Bindings, and Scopes A name is a symbolic identifier used

More information

Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved.

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

More information

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 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

More information

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER

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,

More information

Adapter, Bridge, and Façade

Adapter, Bridge, and Façade CHAPTER 5 Adapter, Bridge, and Façade Objectives The objectives of this chapter are to identify the following: Complete the exercise in class design. Introduce the adapter, bridge, and façade patterns.

More information