Chapter 12 Separate Compilation and Namespaces. Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

M The University Of Michigan Andrew M. Morgan EECS Lecture 09 Savitch Ch Compiling With Multiple Files Make Utility.
Chapter 11 Separate Compilation and Namespaces. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Separate Compilation.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Introduction to C++ Programming. Brief Facts About C++ Evolved from C Designed and implemented by Bjarne Stroustrup at the Bell Labs in the early 1980s.
Chapter 16 Exception Handling. What is Exception Handling? A method of handling errors that informs the user of the problem and prevents the program from.
Vectors, lists and queues
1 Chapter 1 C++ Basics Review Sections 1.4 and 1.5 and additional material from these slides See examples under Lec3.
1 Abstract Data Types Chapter 1. 2 Objectives You will be able to: 1. Say what an abstract data type is. 2. Implement a simple abstract data type in C++
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Approfondimento Classi - Esempi1 // Argomento: Oggetti membri di altre classi // Declaration of the Date class. // Member functions defined in date1.cpp.
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
Chapter 11 Separate Compilation and Namespaces Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12A Separate Compilation and Namespaces For classes this time.
Writing and Testing Programs Drivers and Stubs Supplement to text.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Lab Session-XII CSIT121 Fall 2000 b Namespaces b Will This Program Compile ? b Master of Deceit b Lab Exercise 12-A b First Taste of Classes b Lab Exercise.
Specification and Implementation Separating the specification from implementation makes it easier to modify programs. Changes in the class’s implementation.
Chapter 3 Getting Started with C++
Chapter 10 Defining Classes. User-defined Types Are data types defined by programmers. Include: – typedef: simple data definition – struct: a structure.
Separate Compilation. A key concept in programming  Two kinds of languages, compilation (C, Pascal, …) and interpretation (Lisp, …, Matlab, Phython,
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
Separating Definition & Implementation Headers and Comments.
C++ Functions. Objectives 1. Be able to implement C++ functions 2. Be able to share data among functions 2.
Compilation & Linking Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens The Preprocessor When a C compiler is invoked, the.
1 Chapter-01 Introduction to Software Engineering.
Comp 245 Data Structures (A)bstract (D)ata (T)ypes ADT.
11 Introduction to Object Oriented Programming (Continued) Cats.
38 4/11/98 CSE 143 Modules [Chapter 2]. 39 4/11/98 What is a Module?  Collection of related items packaged together  Examples:  Stereo System Components.
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 05, 2005 Lecture Number: 4.
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
Separate Compilation Bryce Boe 2013/10/09 CS24, Fall 2013.
Chapter 9 Separate Compilation and Namespaces. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Separate Compilation (9.1)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation and Namespaces.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Separate Compilation and Namespaces.
11 Introduction to Object Oriented Programming (Continued) Cats.
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis"
Object Access m1.write(44); m2.write(m2.read() +1); std::cout
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
Chapter 12 Classes and Abstraction
C++ Programming: Presentation 1
Classes C++ representation of an object
#define #include<iostream> using namespace std; #define GO
Advanced Program Design with C++
Separate Compilation and Namespaces
Chapter Structured Types, Data Abstraction and Classes
The Preprocessor Based on Chapter 1 in C++ for Java Programmers by Weiss When a C compiler is invoked, the first thing that happens is that the code is.
Learning Objectives What else in C++ Bitwise operator
Separate Compilation and Namespaces
Name: Rubaisha Rajpoot
Separating Definition & Implementation
Comments, Prototypes, Headers & Multiple Source Files
Code Organization CSCE 121 J. Michael Moore.
Classes.
C++ Compilation Model C++ is a compiled language
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
Classes C++ representation of an object
What Is? function predefined, programmer-defined
CS 144 Advanced C++ Programming February 21 Class Meeting
Class rational part2.
Chapter 11 Class Inheritance
Code Organization Classes
Lecture 8 Object Oriented Programming (OOP)
Presentation transcript:

Chapter 12 Separate Compilation and Namespaces

Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that the users of the class do not have access to the implementation. The separation of what it does (interface) from how it does it (implementation) is enforced by the use of separate files. These two files compose the class library for that ADT.

Separate Compilation The separation of what an ADT does (interface) from how it does (implementation) is enforced by the use of separate files. These two files compose the class library for that ADT. ADT’s are implemented as separate libraries so that they can be used in multiple applications.

Why separate compilation? To create libraries that can be used with different applications: Reusability You can modify your class and not have to modify the programs that use it. The library is only compiled once and can be used by many applications.

Header file (.h) Contains the class definition and any other user defined types used by the class. This is called the class interface. Requires extensive documentation (pre and post conditions) to give users understandings of what to use. // Date.h #ifndef _DATE_H_ #define _DATE_H_ #include … using namespace std; class CDate { … }; #endif

Implementation file (.cpp) Contains the implementation of all the class functions. This is called the class implementation of the purpose of each function. // Date.cpp #include “Date.h” CDate::CDate () { month = 1; day = 1; year = 1900; } CDate::CDate (int m, int d, int y) { month = m; day = d; year = y; } …

Application file (.cpp) contains the program (denoted by “main”) that is using the class. #include “Date.h” using namespace std; void main () { CDate yourBD; cout << "Enter your birthday as month, day and year, separate by spaces: ”; int m, d; cin >> m >> d >> yourBD.year; yourBD.setMonth(m); yourBD.setDay(d); cout << “Your birthday is: " << yourBD.display() << endl; CDate LincohnBD(2, 12, 1809); cout << “Abraham Lincoln's birthday is: " << LincohnBD.display() << endl; CDate twinBrotherBD(yourBD); cout << “Your twin brother’s birthday is: " << twinBrotherBD.display(); }

Data files usually have a.dat and.txt extension are supplemental files containing data to support the Project. AppleAAPL BoeingBA75.50 Intel INTC22.30 NokiaNOK3.35 RambusRMBS5.55 SiriusSIRI3.15 Xilinx XLNX36.80 Conpanies.txt

Linking The header, implementation and application files are linked together in the Project.

Using #ifndef Used to ensure that a header file has not already been included resulting in duplicate copies of the class. States that the header file is not defined previously then use this definition--otherwise, do not include the class again. // Date.h #ifndef _DATE_H_ #define _DATE_H_ #include … using namespace std; class CDate { … }; #endif // Date.cpp #include “Date.h” CDate::CDate () { month = 1; day = 1; year = 1900; } CDate::CDate (int m, int d, int y) { month = m; day = d; year = y; }