



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to object-oriented design (ood) and abstract data types (adts) in the context of object-oored programming (oop) in c++. Ood focuses on objects and their interactions, while adts define a group of data and operations associated with it. The concept of classes, which define objects and their operations, and the use of classes as a method of implementing an adt. It also explains how to perform operations using objects and the difference between classes and structs.
Typology: Papers
1 / 6
This page cannot be seen from the preview
Don't miss anything!
Object-oriented design (OOD) used in Object-oriented Programming (OOP) focus is on objects (rather than functions) object = an instance of an entity; same as a variable solve the problem by identifying object in the solution & how they interact Closer look at objects o objects are defined by “classes” o class = a structured data type including operations o classes define data types and operations o we’ve already used classes & objects (without knowing it) to do I/O & use string data type o the iostream library file defines the classes istream and ostream o Then within the library file, an object cin is defined to be of type istream o an object cout is defined to be of type ostream istream cin; ostream cout; o in the same way the fstream library defines classes ifstream and ofstream o then you can declare your own object of these classes in your program o the string library defines a class called string o you can then create objects of the string class in your program string firstName; How do we perform operations using objects in C++? o objects have operations ( methods ) associated with them o the syntax to call a function that is associated with an object is
Abstract Data Types (ADTs): Conceptual specification of a group of data and operations associated with the data. From the text: A data type whose properties (domain and operations) are specified independently of any particular implementation. Example: List ADT Data: item Operations: Create a list add and item remove an item search for an item count the items sort the list display all the items Notice that it’s separate from implementation details so this model can be used over & over again. It could be used to model a grocery list, a list of items needed for a chemistry lab, a list of operations that need to occur before the space shuttle takes off, … Once an ADT has been written, it is the programmer’s job to make implementation decisions. For a List we might use an array, of a specific maximum size and another integer to keep track of how many items are in the list.. EX: Clock ADT Data: Time Operations: Create a time object Set the time Display the time Increment the time by 1 second Compare times for equality Compare times for less than Note that all these operations are of different types: Constructor : an operation that creates a new instance of the ADT Transformer : Builds a new value of the ADT. Another way of looking at this is to say a transformer modifies an existing ADT. Observer : Allows us to examine the state of an instance without modifying it. Iterator : An operation that allows us to process - one at a time - all the components of a given ADT
Implementation file: something.cpp //for each function associated with your class returnType YourNewType:: functionName ( parameter list) { function body } EX: Write a class specification file for the Time ADT (don’t worry about how we’ll use it yet!) #include
Using a Class as a Type in a program Consider the Time class that was created previously. The point of creating a user- defined structured data type is to allow someone to use it in a program. Time can be treated just like any other type in that variables can be declared to be of type Time. A variable whose type is defined by a class is said to be an object or instance of the class. In order to use Time as a type in our program, the compiler must “know” what the identifier Time is defined to include. EX: int main( ) { Time aTime; Using the instance to accomplish goals The instance of the class contains data (specified by the private members or instance variables ) and can call upon the methods of the class ( to perform operations. ) EX: int main ( ) { #include “clock.h” Time aTime; int h, m, s; cout << “Enter the initial time for the clock (hrs mins secs)” << endl; cin >> h >> m >> s; aTime.set(h, m, s); aTime.increment( ); aTime.write( ); return 0; } Why don’t the increment( ) and display( ) functions require parameters?