Presentation is loading. Please wait.

Presentation is loading. Please wait.

Important Definitions Class: A structured data type that is used to represent an abstract data type (ADT) Class member: A components of a class. It can.

Similar presentations


Presentation on theme: "Important Definitions Class: A structured data type that is used to represent an abstract data type (ADT) Class member: A components of a class. It can."— Presentation transcript:

1 Important Definitions Class: A structured data type that is used to represent an abstract data type (ADT) Class member: A components of a class. It can data or functions. Class object: A variable of a class type. When you will declare the variable, an object of class type will be created. Client: Software that declare and manipulates objects of a particular class.

2 Constructor Constructor is a member function. Constructor has the same name as the class itself. We define constructor to do important initializations. Constructor will be called (invoked) automatically by the compiler when you create an object.

3 Constructor If you don’t provide constructor, the compiler will make a dump default constructor, calls it whenever you declare an object. The dump default simply allocates space for the class’s private data, however it does not do initialization. If you define one or more constructors, the compiler will not make a default for you. Compiler will display syntax error. You can make as many constructors (with different arguments ) as you think useful.

4 Destructor Destructor is implicitly invoked when a class object is destroyed. Destructor is invoked when a local object is out of the scope. The name of a destructor is same as a constructor except that the first character is a tilde (~). For example, if the name of the constructor is Class_one(), the name of the destructor is ~Class_one.

5 Two Approaches to Building Manageable Modules Divides the problem into more easily handled subtasks, until the functional modules (subproblems) can be coded. Identifies various objects composed of data and operations, that can be used together to solve the problem. FUNCTIONAL DECOMPOSITION OBJECT-ORIENTED DESIGN FOCUS ON: processes FOCUS ON: data objects

6 Information Hiding Hiding the details of a function or data structure with the goal of controlling access to the details of a module or structure. PURPOSE: To prevent high-level designs from depending on low-level design details that may be changed.

7 Find Weighted Average Print Weighted Average Functional Design Modules Main Print Data Print Heading Get Data Prepare File for Reading

8 Object-Oriented Design A technique for developing a program in which the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data. Private data << setf...... Private data >> get...... ignore cincout

9 More about OOD l Languages supporting OOD include: C++, Java, Smalltalk, Eiffel, and Object-Pascal. l A class is a programmer-defined data type and objects are variables of that type. l In C++, cin is an object of a data type (class) named istream, and cout is an object of a class ostream. Header files iostream.h and fstream.h contain definitions of stream classes.

10 Procedural vs. Object-Oriented Code “Read the specification of the software you want to build. Underline the verbs if you are after procedural code, the nouns if you aim for an object-oriented program.” Brady Gooch, “What is and Isn’t Object Oriented Design,” 1989.

11 Header File (Complex_t.h) Class Complex_t { public: void add_num(Complex_t num1, Complex_t num2); void subtract_ num(Complex_t num1, Complex_t num2); …………………………………………………………… void print_num(void); float absolute-value(Complex_t num); Complex_t(); // default constructor Complex_t(float, float); //constructor accepting two values private: float real; float imaginary; };

12 Implementation file (Complex_t.cpp #include “Complex_t.h” ………………………… Complex_t :: Complex_t() { real = 0.0; imaginary = 0.0; } Complex_t :: Complex_t(float r, float I) { real = r; imaginary = I; }

13 Implementation file (Complex_t.cpp) void Complex_t :: print_num() { cout << “(“ << real << “,”; cout << imaginary << “)”; } float Complex_t :: absolute_value(Complex_t num) { float a,b, number; a = num. real; b = num. imaginary; number = sqrt(pow(a,2) + pow(b,2)); return number; } ………………………………………………………….

14 Client.cpp #include “Complex.h” int main() { Complex_t Num; // When object Num will be created, default // constructor will be invoked Complex_t num1(2, 4); // When the Objects are created, Complex_t num2(3, -2); // other constructor will be invoked Complex_t num3(5, -2); Complex_t num4(-1, 5); num1. print_num(); //member function call cout << “+”; num2.print_num(); //member function call cout<< “ = “; Num.add_num(num1, num2); num.print_num();…………}

15 How to create an executable file? Use MSDOS Prompt: Steps: C:\>bcc32 – c Complex_t.cpp // create an object file C:\>bcc32 Complex_t Client.cpp //creates an executable file Complex_t C:\>Complex_t

16 How to set path? If you get the error “The name specified is not recognized as an internal and external command, operable program or batch file”, do the following: At DOS Prompt, you have to type the following: C:\>path = path;c:\bc5\bin


Download ppt "Important Definitions Class: A structured data type that is used to represent an abstract data type (ADT) Class member: A components of a class. It can."

Similar presentations


Ads by Google