SlideShare a Scribd company logo
1 of 39
Prepared by:
Ms. Sherry B. Naz
   is a widely used programming methodology
   First step in the problem-solving process is to
    identify the components called objects, which
    form the basis of the solution and to determine
    how these objects interact with one another.
   Example: write a program that automates the
    video rental process for a local video store.
     Identify Object: video and customer
     Specify for each object the relevant data and
     operations to be performed on that data.
   Video
     Data
      ▪   movie name
      ▪   starring actors
      ▪   producer
      ▪   production company
      ▪   number of copies in stock
     Operations
      ▪ checking the name of the movie
      ▪ reducing the number of copies in stock by one after a copy is
        rented
      ▪ incrementing the number of copies in stock by one after a
        customer returns a particular video
   An object combines data and operations into
    a single unit
   In OOD, the final program is a collection of
    interacting objects
   A programming language that implements
    OOD       is  called  an    object-oriented
    programming language.
   is collection of fixed number of components
   components of a class are called members of the
    class
   Syntax:
      class classIdentifier
      {
        classMemberList
      };
     where: classMemberList consists of variable
      declarations and/or functions. That is a member of a
      class can be either a variable (to store data) or a
      function.
 If a member of a class is a variable, you declare it just like
  any other variable. Also, in the definition of the class, you
  cannot initialize a variable when you declare it.
 If a member of a class is a function, you typically use the
  function prototype to declare that member.
 If a member of a class is a function, it can (directly) access
  any member of the class – member variables and member
  functions. That is, when you write the definition of a
  member function, you can directly access any member
  variable of the class without passing it as a parameter. The
  only obvious condition is that you must declare an
  identifier before you can use it.
   Members of a class are classified into three
    categories: private, public, protected
   private, public and protected are reserved
    words and are called member access specifiers
   Facts about private and public members of a
    class :
     By default, all members of a class are private
     If a member of a class is private, you cannot access it
      outside the class
     A public member is accessible outside the class
     To make a member of a class public, you use the
      member access specifier public with a colon, :.
 Define a class to implement the time of day in a
  program. Because a clock gives the time of day, let
  use call this class ClockType
 Data members to represent time: hours, minutes, and
  seconds
 Some operations on time
       Set the time.
       Print the time.
       Increment the time by one second.
       Increment the time by one minute.
       Increment the time by one hour.
   How many members are there in ClockType?
class ClockType
{
     int hours;
     int minutes;
     int seconds;
public:
     void setTime();
     void printTime();
     void incrementHours();
     void incrementMinutes();
     void incrementSeconds();
};
   Syntax:
    classType classObjectname;
   Example:
    ClockType yourClock;
    ClockType, myClock, yourClock;
   Syntax:
    classObjectName.memberName
 Example:
  myClock.hours = 5; // if hours is public
  myClock.printTime();
 The class members that a class object can access
  depend on where the object is declared.
     If the object is declared in the definition of member
      function of the class, then the object can access both
      the public and private members.
     If the object is declared elsewhere, then the object
      can access only the public members of the class.
   Not Allowed
     You cannot use arithmetic operations on class objects
      ▪ Example: myClock + yourClock
     You cannot use relational operators to compare two
      class objects for equality
      ▪ Example: if(myClock == yourClock)
   Allowed:                                myClock         yourClock

     Member access operator (.)       hours          2   hours
      ▪ myClock.printTime();           minutes    26      minutes
     Assignmner operator (=)          seconds    47      seconds
      ▪ yourClock = myClock;
yourClock = myClock;


            myClock            yourClock


    hours             2    hours           2

    minutes           26   minutes         26

    seconds           47   seconds         47
   The following rules describe the relationship
    between functions and classes:
     Class objects can be passed as parameters to
      functions and returned as function values
     As parameters to functions, classes can be passed
      either by value of by reference
     If a class object is passed by value, the contents of
      the member variables of the actual parameters
      are copied into the corresponding member
      variables of the formal parameter.
Note: If a variable is passed by values, the formal parameter copies the values of
   the actual parameters.

void sum(int a, int b)
{
    a = a + 5;
    b = b * a;                             sum                 main
}
int main()
{                                     a                    x     3
    int x,y;
    x = 3;y=2;                         b                   y     2
    cout<<x<<“ “<<y<<endl;
    sum(x,y);
    cout<<x<<“ “<<y<<endl;
}
Note: If a variable is passed by reference, the formal parameter receives only the
   address of the actual parameters.

void sum(int& a, int& b)
{
    a = a + 5;
    b = b * a;                               sum                main
}
int main()                               a                  x     3
{
    int x,y;
    x = 3;y=2;                           b                  y     2
    cout<<x<<“ “<<y<<endl;
    sum(x,y);
    cout<<x<<“ “<<y<<endl;
}
   How to pass object as a parameter to a function?
   C++ has no fixed order in which you declare
    public and private members; you can
    declare them in any order. The only thing you
    need to remember is that, by default, all
    members of a class are private.
   If you decide to declare private members
    after the public members , you must use the
    member access specifier private to begin the
    declaration of the private member.
   Categories of Member Functions
     Mutator Function – a member function of a class that
      modifies the value(s) of the member variable(s).
     Accessor Function – a member function of a class
      that only accesses (that is, does not modify the
      value(s) of the member variable(s).
      ▪ As a safeguard, a reserved word const is added at the end of
        the headings of the accessor function.
        ▪ Note: A constant member function of a class cannot modify the
          member variables of that class.
      ▪ A member function of a class is called constant function if
        its heading contains the reserved word const at the end.
        ▪ A constant member function of a class can only call other constant
          member functions of that class.
   Add another member function that simply
    returns the values of the data members of the
    class(hours, minutes and seconds).
   This member function should prevent user
    from modifying the values of member
    variables of the class.
   Be reminded that a function returns at most
    one value.
   What if printTime() is called right after
    creating an object of ClockType()?

int main()
{
  ClockType myClock;
  myClock.printTime();

}
   Is a special function whose main purpose is to
    initialize the data members of a class
   There are two types of constructors:
     Constructors   with parameters (parameterized
      constructor)
     Constructors    without   parameters   (default
      constructor)
   The name of a constructor is the same as the
    name of the class
   A constructor, even though it is a function,
    has no type. That is, it is neither a value-
    returning function nor a void function.
   A class can have more than one constructor.
    However, all constructors of a class have the
    same name.
 If a class has more than one constructor, the
  constructors must have different formal parameter
  lists. That is, either they have a different number of
  formal parameters or, if the number of formal
  parameters is the same, then the data type of the
  formal parameters, in the order list, must differ in at
  least one position.
 Constructors execute automatically when a class
  object enters its scope. Because they have no types,
  they cannot be called like other functions.
 Which constructor executes depends on the types of
  values passed to the class object when the class is
  declared
ClockType::ClockType()
{
  hours = 0;
  minutes = 0;
  seconds = 0;
}
ClockType::ClockType(int hr, int min, int sec)
{
  hours = hr;
  minutes = min;
  seconds = sec;
}
ClockType::ClockType(int hr, int min, int sec)
{
  setTime(hr,min,sec);
}
   Syntax:
    className classObjectName;
   Example:
    ClockType myClock;
   Syntax:
    className classObjectName(argument list);
   Example:
    ClockType myClock(7,19,11);
   Note:
     The number of arguments and their type( in the argument
      list ) should match the formal parameters(in the order
      given) of one of the constructors.
     If the type of the argument does not match the formal
      parameters of any constructor(in the order given), C++
      used type conversion and looks for the best match. For
      example, an integer value might be converted to a floating-
      point value with a zero decimal part. Any ambiguity will
      result in a compile-time error.
   A constructor can also have default
    parameters. In such cases, rules for declaring
    formal parameters are the same as those for
    declaring formal parameters in a function.
    Moreover, actual parameters to a constructor
    with default parameters are passed according
    to the rules for functions with default
    parameters.
   Using ClockType class, we can replace both
    constructors with:

    ClockType(int=0, int=0, int=0);
class TestClass
{
   public:
   void print() const;
   TestClass(int =0, int =0, double =0.0, char =‘*’);
   private:
      int x,y;
      double z;
      char ch;
};
TestClass::TestClass(int tX, int tY, double tZ, char tCh)
{
  x = tX;
  y = tY;
  z = tZ;
  ch = tCh;
}
TestClass::print()const
{
  cout<<“x = “ <<x<<endl;
  cout<<“y = “ <<y<<endl;
  cout<<“z = “ <<z<<endl;
  cout<<“ch = “ <<ch<<endl;
}
int main()
{
  testClass one;
  testClass two(5,6);
  testClass three (5,7,4.5);
  testClass four(4,9,12);
  testClass five(0,0,3.4, ‘D’);
  one.print();
  two.print();
  three.print();
  four.print();
  five.print();
}
 If a class has no constructor(s), C++
  automatically provides the default constructor.
  However, the object declared is still
  uninitialized.
 If  a class includes constructor(s) with
  parameter(s) and does not include the default
  constructor, C++ does not provide the default
  constructor for the class. Therefore, when an
  object of the class is declared, we must include
  the appropriate arguments in the declaration.
    ClockType arrivalTimeEmp[100];
      arrivalTImeTemp
    arrivalTImeTemp[0]
    arrivalTImeTemp[1]
    arrivalTImeTemp[2]                  yourClock

                                      hours

                                      minutes
                                      seconds

    arrivalTImeTemp[99]
1.   Design and implement a class DayType that implements the day of the week
     in a program. The class should store the day such as Sun for “Sunday”. The
     program should be able to perform the following operations on an object of
     type DayType:
        1.   Set the day.
        2.   Print the day.
        3.   Return the day.
        4.   Return the next day.
        5.   Return the previous day.
        6.   Calculate and return the day by adding certain days to the current day. For
             example, if the current day is Monday and we add 4 days, the day to be
             returned is Friday. Similarly, if today is Tuesday, and we add 13 days, the day
             to be returned is Monday.
        7.   Add the appropriate constructors.
2.   Write the definitions if the functions to implement the operations for the
     class DayType as defined in #1. Also, write a program to test various
     operations on this class.

More Related Content

What's hot

Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...JAINAM KAPADIYA
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Javakjkleindorfer
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritancemanish kumar
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesSunil Kumar Gunasekaran
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywordsmanish kumar
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptmanish kumar
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statementmanish kumar
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interfacemanish kumar
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1Vineeta Garg
 

What's hot (20)

Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
 
Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritance
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java basic
Java basicJava basic
Java basic
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
 
Java unit2
Java unit2Java unit2
Java unit2
 
C++ classes
C++ classesC++ classes
C++ classes
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 

Similar to Object oriented design

Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)Durga Devi
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects newlykado0dles
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfismartshanker1
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programmingnirajmandaliya
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptmanomkpsg
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)nirajmandaliya
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08Terry Yoast
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfstudy material
 

Similar to Object oriented design (20)

Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdf
 
Class and object
Class and objectClass and object
Class and object
 
Class and object
Class and objectClass and object
Class and object
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
 
My c++
My c++My c++
My c++
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
 
Chap08
Chap08Chap08
Chap08
 
oops-1
oops-1oops-1
oops-1
 

Recently uploaded

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Recently uploaded (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

Object oriented design

  • 2. is a widely used programming methodology  First step in the problem-solving process is to identify the components called objects, which form the basis of the solution and to determine how these objects interact with one another.  Example: write a program that automates the video rental process for a local video store.  Identify Object: video and customer  Specify for each object the relevant data and operations to be performed on that data.
  • 3. Video  Data ▪ movie name ▪ starring actors ▪ producer ▪ production company ▪ number of copies in stock  Operations ▪ checking the name of the movie ▪ reducing the number of copies in stock by one after a copy is rented ▪ incrementing the number of copies in stock by one after a customer returns a particular video
  • 4. An object combines data and operations into a single unit  In OOD, the final program is a collection of interacting objects  A programming language that implements OOD is called an object-oriented programming language.
  • 5. is collection of fixed number of components  components of a class are called members of the class  Syntax: class classIdentifier { classMemberList };  where: classMemberList consists of variable declarations and/or functions. That is a member of a class can be either a variable (to store data) or a function.
  • 6.  If a member of a class is a variable, you declare it just like any other variable. Also, in the definition of the class, you cannot initialize a variable when you declare it.  If a member of a class is a function, you typically use the function prototype to declare that member.  If a member of a class is a function, it can (directly) access any member of the class – member variables and member functions. That is, when you write the definition of a member function, you can directly access any member variable of the class without passing it as a parameter. The only obvious condition is that you must declare an identifier before you can use it.
  • 7. Members of a class are classified into three categories: private, public, protected  private, public and protected are reserved words and are called member access specifiers  Facts about private and public members of a class :  By default, all members of a class are private  If a member of a class is private, you cannot access it outside the class  A public member is accessible outside the class  To make a member of a class public, you use the member access specifier public with a colon, :.
  • 8.  Define a class to implement the time of day in a program. Because a clock gives the time of day, let use call this class ClockType  Data members to represent time: hours, minutes, and seconds  Some operations on time  Set the time.  Print the time.  Increment the time by one second.  Increment the time by one minute.  Increment the time by one hour.  How many members are there in ClockType?
  • 9. class ClockType { int hours; int minutes; int seconds; public: void setTime(); void printTime(); void incrementHours(); void incrementMinutes(); void incrementSeconds(); };
  • 10. Syntax: classType classObjectname;  Example: ClockType yourClock; ClockType, myClock, yourClock;
  • 11. Syntax: classObjectName.memberName  Example: myClock.hours = 5; // if hours is public myClock.printTime();  The class members that a class object can access depend on where the object is declared.  If the object is declared in the definition of member function of the class, then the object can access both the public and private members.  If the object is declared elsewhere, then the object can access only the public members of the class.
  • 12. Not Allowed  You cannot use arithmetic operations on class objects ▪ Example: myClock + yourClock  You cannot use relational operators to compare two class objects for equality ▪ Example: if(myClock == yourClock)  Allowed: myClock yourClock  Member access operator (.) hours 2 hours ▪ myClock.printTime(); minutes 26 minutes  Assignmner operator (=) seconds 47 seconds ▪ yourClock = myClock;
  • 13. yourClock = myClock; myClock yourClock hours 2 hours 2 minutes 26 minutes 26 seconds 47 seconds 47
  • 14. The following rules describe the relationship between functions and classes:  Class objects can be passed as parameters to functions and returned as function values  As parameters to functions, classes can be passed either by value of by reference  If a class object is passed by value, the contents of the member variables of the actual parameters are copied into the corresponding member variables of the formal parameter.
  • 15. Note: If a variable is passed by values, the formal parameter copies the values of the actual parameters. void sum(int a, int b) { a = a + 5; b = b * a; sum main } int main() { a x 3 int x,y; x = 3;y=2; b y 2 cout<<x<<“ “<<y<<endl; sum(x,y); cout<<x<<“ “<<y<<endl; }
  • 16. Note: If a variable is passed by reference, the formal parameter receives only the address of the actual parameters. void sum(int& a, int& b) { a = a + 5; b = b * a; sum main } int main() a x 3 { int x,y; x = 3;y=2; b y 2 cout<<x<<“ “<<y<<endl; sum(x,y); cout<<x<<“ “<<y<<endl; }
  • 17. How to pass object as a parameter to a function?
  • 18. C++ has no fixed order in which you declare public and private members; you can declare them in any order. The only thing you need to remember is that, by default, all members of a class are private.  If you decide to declare private members after the public members , you must use the member access specifier private to begin the declaration of the private member.
  • 19.
  • 20.
  • 21. Categories of Member Functions  Mutator Function – a member function of a class that modifies the value(s) of the member variable(s).  Accessor Function – a member function of a class that only accesses (that is, does not modify the value(s) of the member variable(s). ▪ As a safeguard, a reserved word const is added at the end of the headings of the accessor function. ▪ Note: A constant member function of a class cannot modify the member variables of that class. ▪ A member function of a class is called constant function if its heading contains the reserved word const at the end. ▪ A constant member function of a class can only call other constant member functions of that class.
  • 22. Add another member function that simply returns the values of the data members of the class(hours, minutes and seconds).  This member function should prevent user from modifying the values of member variables of the class.  Be reminded that a function returns at most one value.
  • 23. What if printTime() is called right after creating an object of ClockType()? int main() { ClockType myClock; myClock.printTime(); }
  • 24. Is a special function whose main purpose is to initialize the data members of a class  There are two types of constructors:  Constructors with parameters (parameterized constructor)  Constructors without parameters (default constructor)
  • 25. The name of a constructor is the same as the name of the class  A constructor, even though it is a function, has no type. That is, it is neither a value- returning function nor a void function.  A class can have more than one constructor. However, all constructors of a class have the same name.
  • 26.  If a class has more than one constructor, the constructors must have different formal parameter lists. That is, either they have a different number of formal parameters or, if the number of formal parameters is the same, then the data type of the formal parameters, in the order list, must differ in at least one position.  Constructors execute automatically when a class object enters its scope. Because they have no types, they cannot be called like other functions.  Which constructor executes depends on the types of values passed to the class object when the class is declared
  • 27. ClockType::ClockType() { hours = 0; minutes = 0; seconds = 0; }
  • 28. ClockType::ClockType(int hr, int min, int sec) { hours = hr; minutes = min; seconds = sec; }
  • 29. ClockType::ClockType(int hr, int min, int sec) { setTime(hr,min,sec); }
  • 30. Syntax: className classObjectName;  Example: ClockType myClock;
  • 31. Syntax: className classObjectName(argument list);  Example: ClockType myClock(7,19,11);  Note:  The number of arguments and their type( in the argument list ) should match the formal parameters(in the order given) of one of the constructors.  If the type of the argument does not match the formal parameters of any constructor(in the order given), C++ used type conversion and looks for the best match. For example, an integer value might be converted to a floating- point value with a zero decimal part. Any ambiguity will result in a compile-time error.
  • 32. A constructor can also have default parameters. In such cases, rules for declaring formal parameters are the same as those for declaring formal parameters in a function. Moreover, actual parameters to a constructor with default parameters are passed according to the rules for functions with default parameters.
  • 33. Using ClockType class, we can replace both constructors with: ClockType(int=0, int=0, int=0);
  • 34. class TestClass { public: void print() const; TestClass(int =0, int =0, double =0.0, char =‘*’); private: int x,y; double z; char ch; };
  • 35. TestClass::TestClass(int tX, int tY, double tZ, char tCh) { x = tX; y = tY; z = tZ; ch = tCh; } TestClass::print()const { cout<<“x = “ <<x<<endl; cout<<“y = “ <<y<<endl; cout<<“z = “ <<z<<endl; cout<<“ch = “ <<ch<<endl; }
  • 36. int main() { testClass one; testClass two(5,6); testClass three (5,7,4.5); testClass four(4,9,12); testClass five(0,0,3.4, ‘D’); one.print(); two.print(); three.print(); four.print(); five.print(); }
  • 37.  If a class has no constructor(s), C++ automatically provides the default constructor. However, the object declared is still uninitialized.  If a class includes constructor(s) with parameter(s) and does not include the default constructor, C++ does not provide the default constructor for the class. Therefore, when an object of the class is declared, we must include the appropriate arguments in the declaration.
  • 38. ClockType arrivalTimeEmp[100]; arrivalTImeTemp arrivalTImeTemp[0] arrivalTImeTemp[1] arrivalTImeTemp[2] yourClock hours minutes seconds arrivalTImeTemp[99]
  • 39. 1. Design and implement a class DayType that implements the day of the week in a program. The class should store the day such as Sun for “Sunday”. The program should be able to perform the following operations on an object of type DayType: 1. Set the day. 2. Print the day. 3. Return the day. 4. Return the next day. 5. Return the previous day. 6. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday, and we add 13 days, the day to be returned is Monday. 7. Add the appropriate constructors. 2. Write the definitions if the functions to implement the operations for the class DayType as defined in #1. Also, write a program to test various operations on this class.