Object Oriented Programming Full PDF
Object Oriented Programming Full PDF
UNIT
Introduction
CONTENTS
1-2L to 1-11L
Part-1 Introduction, The Meaning.. *******
of Object Orientat0n,
Object Identity, Encapsulation,
Information Hiding8
Polymorphism, ienerosity
1 - 1 L to 1-19L
Part-2 Importance of Modelling, ********
Principles of Modelling,
Object-oriented Modelling
1-191 to 1-22L
Part-3 Introduction of UML, . . . . ******
1-1L(CS/IT-Sem-5)
1-2L(CSIT-Sem-5) Introduction
PART-1
Introduction, The Meaning of Object Orientation, Object Identity,
Encapsulation, Information Hiding, Polymorphism, Generosity
Questions-Answers
Long Answer Type and Medium Answer Type Questions
3. In analysis phase, O0 models are used to fill the gap between problem
and solution.
Answer
Following are the elements of object-oriented system :
1. Objects:
a. An object is something that is exists within problem domain and
can be identified by data (attribute) or behavior
b. All tangible entities (student, patient) and some intangible entities
(bank account) are modeled as object.
Object Oriented System Design 1-3 L (CS/1T-Sem-5)
3 Behavior:
a It specifies what the object can do.
b . I t detfines the operation performed on objects.
4. Class:
a Aclass encapsulates the data and its behavior.
b. Objects with similar meaning and purpose grouped togetheras
class.
5. Methods:
a. Methods determine the behavior of a class.
b. They are nothing more than an action that an object can perform.
6 Message
a Amessage is a function or procedure call from one object to another.
Object 1 Object 2
Message C
Method 2
Method 1
Data Data
ethod
Method 9
Method 6 Method 3
Message B
Message A
Fig. 1.3.1. Message passing between objects with encapsulation,
activating methods that can use or modify the data
within their object.
14L(CSIT-Sem-5) Introduction
i. The only way to reach the data is through these particular methods
(see Fig. 1.3.1).
i. It is the mechanism that binds together code and the data it
manipulates.
1v. This concept is also used to hide the internal representation, or
state, of an object from the outside.
2 Polymorphism:
Polymorphism means having many forms.
. Polymorphism is the ability of a message to be displayed in more
than one form.
. lt plays an important role in allowing objects having different
internal structure to share the same external interface.
3 Inheritance:
Inheritance is the ability to create classes that share the attributes
and methods of existing classes, but with more specific features.
Inheritance is mainly used for code reusability.
4. Final implementation
i. At this stage, the final implementation of classes and relationships
developed during object design takes place.
i. Actual implementation should be done using software engineering
practice. This helps to develop a flexible and extensible system.
and
Que 1.5. Differentiate between structured approach objeet
oriented approach.
Answer
AKTU 2013-14,Marks 05
Answer
4. Adding new data and function Adding new data and function is
1S not easy. easy.
OR
What do you mean by object-oriented techniques ? Explain with
some examples.
AKTU2012-13, Marks 10
Answer
1. Object-Oriented Technology (O0T) is an approach to program
organization and development that attempts to reduce some of the issues
with conventional programming techniques.
It is a new way of organizing and developing programs and has nothing
to do with any particular programming language.
3. However, not all languages are suitable to implement the object-oriented
concepts or implement partial features of object-oriented concepts.
Pros of object-oriented technology are
L It allows parallel development : Ifwe are working with programming
Methods
1-10L(CS/NT-Sem-5)
use to implement
Encapsulation is a common technique programmers
information hiding.
flexibility, such as allowing
is yielding
Advantage of information hiding
5. to m o r e readily modify
a program.
a programmer
modules for easy
s o u r c é code within
6. This also may be done by placing evolves.
develops and
a c c e s s in the future,
as the program
it with
by polymorphism ? Explain
Que 1.11.What do you mean
10. For example, the class File may have an operation print
11. Different methods could be implemented to print ASCI fles, print binary
files, and print digitized picture files.
12. All these methods logically perform the same task. However, each method
may be implemented by a different piece of code.
Object Oriented System Design 1-11 L (CS/AT-Sem-5)
Applicability of polymorphism :
1. In programming languages there are two types of polymorphism ad-hoe
and universal.
2. There are two kinds of universal polymorphism: parametric and
subtyping
3. Ad-hoc polymorphism is a kind of polymorphism in which polymorphic
functions can be applied to arguments of different types.
PART-2
Importance of Modelling, Principles of Modelling,
Object-oriented Modelling.
Questions-Answers
Long Answer Type and Medium Answer Type Questions
? Discuss several
Que 1.12. What do you mean by modeling
purposes served by models with suitable examples.
que 1.13. What are the different models used in object oriented
languages ?
OR
Write short note on dynamic modeling and functional modeling.
AKTU 2011-12, Marlks 05
Answer
There three types
are
of models in object oriented languages are
1. Object model:
a. The object model identifies the classes in the system and their
relationship, as well as their attributes and operations.
b. Itrepresents the static structure of the system. The object model is
represented graphically by a class diagram.
2 Dynamic model :
a. The dynamic model indicates the
dynamics of the objects and their
changes in state.
b. The dynamic model captures the funetional behavior of the system
by exploring the behavior of the objects Over time and the flow of
control and events among the objects.
Object Oriented System Design 1-13 L (CS/IT-Sem-5)
3 Functional model:
a. The functional model is a
data flow diagram of the system and
describes what the system does, not how it is done.
b. A DFD is a network
representation of the system to show the
functional relationships of the values that are
computed by a system.
Data flow diagrams consist of processes, data flows, actors and data
stores.
statement.
Every model may be expressed at different levels of precision:
This means all the user and developers both may visualize a system at
This means we need to have use case view, design view, process view,
implementation view and development view. Each of these views may
have structural as well as behavioral aspects. Together these views
represent a system.
Importance of modeling:
visualize the plan of their
Modeling help the development team better to
them build
allow them to develop more rapidly by helping
system and
the right thing.
Describe various
Que 1.16.|Define object-oriented modeling (0OM).
steps involved in 0OM process. Explain.
AKTU 2010-11, Marks05
Object Oriented System Design 1-15 L (CS/IT-Sem-5)
Answer
Object-oriented modeling:
Object-oriented modeling (OOM) is the construction of objects using a
collection of objects that contain stored values of the instance variables
found within an object.
2. Object-oriented modeling is an approach to modeling an application thatt
is used at the beginning of the software life cycle when using an object-
oriented approach to software development.
Steps involved in 0OM process:
1. System analysis :
2 System design:
i Atthis stage, the complete system architecture is designed.
ii. In this stage the whole system is divided into subsystems, based on
system analysis model and the proposed architecture of the system.
3. Object design:
i At this stage, a design model is developed based on the analysis
model.
4 Final implementation :
At this stage, the final implementation of classes and relationships
developed during object design takes place.
Answer
1 Link and association in object modeling represent the relation between
objects and classes.
2 Link:Link defines the relationship between two or more objects and a
link is considered as an instance of an association.
4 For example:
i Let us take the two classes Person and Company. Now there is an
association relation between these two classes.
i A person may own stock in zero or more companies.
iv. The object diagram below shows the links between the objects of
person and company class.
jhon:Person
name= Jhon
Marry:Person
name=jhon" jhon:Person
name="jhon
James:Person
name=jhon" jhon:Person
Sue:Person name="jhon
name=Jhon
Kriti:Person
name=jhon
Fig. 1.17.1
The class diagram below shows the
association
between the person
and the company class. Both link and association are
represented
with a line in UML notation.
Object Oriented System Design 1-17L (CS/IT-Sem-5)
2. These three models separate a system into orthogonal views that can be
represented and manipulated with a uniform notation.
Stages of object modeling technique:
1. Analysis :
a Starting from a state ment of the problem, the analyst builds a
model of the real-world situation showing its important properties.
b. The analysis model is a concise, precise abstraction of what the
desired system must do.
C. The objects in the model should be application-domain concepts.
2 System design
a. The system designer makes high-level decisions about t verall
architecture.
b. During system design, the target system is organized into
Bubsystems based on both the analysis structure and the proposed
architecture.
1-18 L(CS/TT-Sem-5) Introduction
4 Implementation :
Answer
filament for light bulb:
Designing the a
L PART-3
UML, Architecture.
Introduction of UML, Conceptual Model of
Questions-Answers
Library
has
contains
consults
has_copies
Co
Copy
borrowsB
location
status
language.
It supports O0AD methodology.
2
3. It bridges the communication gap between different entities of system
Client etc).
development (i.e., System Analyst, Developer,
4. Constructed models are easy to understand, even for non-programmers.
Cons of UML
1. UML is often criticized as being large and complex.
2. It takes a lot of time to keep the diagram reasonable and synchronized
with the actual code.
3. You cannot represent every condition in a sequence diagram.
UML? AKTU2014-16,Marks 05
Answer
The UML is required to help system and software developers accomplish
the following tasks
Specification
ii. Visualization
ii Architecture design
iv. Construction
v. Simulation and testing
vi. Documentation
CONTENTS
2-21L to 2-8LL
Part-1 : Basic Structural Modeling.. ****
2-31L
Part-5 Basic Behavioural Modeling, . 2-23L. to
Use Cases, use Case Diagrams,
Activity Diagram, State Machine,
and
Process and Thread, Event
Interaction
Signals, Time Diagram,
Diagram, Package Diagram
*********
. 2-31L to 2-331.
Part-6 Architectural Modeling,
Component, Deployment,
Component Diagrams and
Deployment Diagrams
2-1 L(CS/IT-Sem-5)
2-2L (CS/AT-Sem-5) Basic Structural Modeling
PART 1
Basic Structural Modeling, Class, Relationships, Common
Mechanism and Diagram.
Questions-Answerss
Long Answer Type and Medium Answer Type Questions
2 Behavioral Modeling:
Behavioral model describes the interaction in the system.
b. It represents the interaction among the structural diagrams.
c. Behavioral modeling shows the dynamic nature of the system.
d It consists of Activity diagrams, Interaction diagrams, Use case
diagrams
3 Architectural Modeling:
a Architectural model represents the overall framework ofthe system.
b. It contains both structural and behavioral elements of the system.
Object Oriented System Design 2-3 L (CS/IT-Sem-5)
c. Architectural model can be defined the
as
blueprint of the entire
system.
d. Package diagram comes under
architectural modeling.
UML: Refer Q. 1.20, Page 1-19L, Unit-1.
Que 2.2. What do you understand by architectural modeling ?
Explain its various concepts and diagrams with suitable example.
AKTU 2010-11, Marks 05
OR
Write short notes on architectural modeling with suitable example
and diagrams.
AKTU 2012-13, Marks 05
Answer
Architectural modeling:
1. Architectural modeling represents the overall framework of the
system.
2. It contains both structural and behavioral elements of the
system.
3. Architectural modeling can be defined as the blueprint of the entire
system.
Diagrams used in architectural modeling:
1. The two types of diagrams that give descriptions of the physical
intormation about system
a aredeployment diagrams and component
diagrams.
2. Deployment diagrams show the physical relationship between hardware
and sottware in a system.
Component diagrams show the software components of a system and
their relationships.
These relationships are called dependencies.
A Component diagrams:
1. The component diagrams are mainly used to model the static
implementation view of a system.
2. They represent a high-level packaged view of the code.
3. They can be used to model executables, databases and adaptable systems
4. Component diagrams mainly contain the following:
i. Components
a A component is a physical, replaceable part of a system that
packages implementation and provides the realization of a set
of interfaces,
b. A component is a physical manifestation of an object that has
a well-defined interface and a set of implementations for the
interlace.
C. A complex system can be built using software components. It
enhances re-use in the system and facilitates system evolution.
24L(CST-Sem-5) Basic Structural Modeling
Component
Fig. 2.2.1.Component.
Component
Component au
Fig. 2.2.2. Component diagram.
Component A
Realization
Component A
Interface
-
Component A
<<interface>>
Name
Attributes
Node1
Communication
path
Node2
AnsweT
1. The phrase class is use to refer to a group of similar things.
2 A class describes a group of objects with similar properties, common
behavior, common relationships to other objects, and common semantics.
3. Objects in a class have the same attributes and behavior pattern.
4. Most objects derive their individuality from differences in their attribute
values and relationships to other objects.
5. T'he objects in a class share a common semantie purpose, above and
beyond the requirement of common attributes and behavior.
Each object "knows" its class.
67. Object-oriented programming languages can determine an object's class
at run timne.
Answer
Relationships: A model is not complete unless the relationships between
elements are described properly. The Relationship gives a proper meaning to
a UMIL model. Following are the different types of relationships used in
UML
1 Dependency Notation :
a Dependency describes the dependent elements and the direction of
dependency.
2-6 L (CSIT-Sem-5) Basic Structural Modeling
Vehicle
Water
Land
Relation to inheritance:
Developers use the term generalization or inheritance to refer to the
same concept of reusing shared attributes and operations that you show.
in a superclass and reuse in subclasses.
part-of relationship.
An aggregation association depicts a complex object that is composed ot
other objects.
For example, we may characterize a house in terms of its roof, floors,
House
Roofs
Roofs
other models.
into
Categorize the following relationship
Que 2.6.
:
or a s s o c i a t i o n
generalization, aggregation,
1. A country has a capital city
2
Files contain records. AKTU 2012-13, Marks 05
Answer
association relationship. A
L. A country has a capital city: t is an
country a r e distinct things s o generalization certainly
capital city and
a
ot a country
does not apply. You could argue that
a
capital city i18 a part
and thus they are related by aggregation.
relationship. The word
contain records : It is an aggregation
2 Files is
"containis a clue that the relationship
may be aggregation. A record
to their
and operations on tiles propagate
a part of a
file. Some attributes
constituent records.
Object Oriented System Design 2-9 L (CS/IT-Sem-5)
|PART2
Class and Object Diagram, Terms, Concepts, Modeling
Techniques for Class and Object Diagram.
Questions-Answers
Long Answer Type and Medium Answer Type Questions
AKTU2013-14, Marks 05
Answer
Class diagram:
1. Class diagram is a static diagram.
2. t represents the static view of an application.
3. Class diagram is used for visualizing, describing, and documenting
and also for constructing executable code
differentaspects of a system
of the software application.
4 Class diagram describes the attributes and operations of a class and also
the constraints imposed on the system.
5. The class diagrams are widely used in the modeling of object-oriented
systems because they are the only UML diagrams, which can be mapped
directly with object-oriented languages.
For example :
Party
children
location
parent
Person Organization
Fig. 2.7.1. Class diagram of party composition structure.
Ohject diagram:
O b j e c t diagrams represent an instance of a elass diagram.
2-10L(CS/IT-Sem-5) Basic Structural Modeling
2. Object diagrams represent the static view of a system but this statie
view is a snapshot of the
system at a particular moment.
3. Object diagrams are used to render a set of
as an instance.
objects and their relationships
For example:
Engineering:Organization
Location = "Banglore"
Parent
Parent
example. Also prepare a list of objects that you would expect each of
the following systems to handle : (1) a program for laying out a
newspaper, (2) a catalog store order entry system.
AKTU2011-12, Marks 05
Answer
Class Object
. No.
Class is a blueprint or template| Object is an instance of class.
1.
from which object are created.
For example:
1. A class is a way of grouping objects that share a number of characteristics
attributes (like name, color, height, weight, etc.) and behavior (such as
ability to perform jumps, to run, to swim, etc.).
2 All objects in the class horse will have an attribute named height, for
example. That means that all object in that class have a height-the value
of the attribute height will be different for each instanee of the class
e., for each particular horse)
i A program for laying out a newspaper : Classes that you would
expect in a program for newspaper layout include Page, Column, Line,
Headline, and Paragraph.
i. A catalog store order entry system: For a catalogstore order entry
system, classes include Customer, Order, Store, and Item.
Que 2.9.Give the general layout of a class diagram. Also prepare
aclass diagram for the instance diagram shown in the Fig. 2.9.1.
Explain your multiplicity decisions. How does your diagram express
the fact that points are in sequence ?
Next
(Polygon)
Next
(Point)Last
0
First (Point)
10 10
Next
Fig. 2.9.1.
AKTU2011-12,Marks 05
Answer
0..1
Polygon first Point
1a X real
1y:rea
and points.
Fig 2.9.2,General clas6 diagram for polygon
2-12L(C/TT-Sem-5) Basic Struetural Modeling
Mate
(Person) (Person)
a grandmother grandfather
Child Child
(Person) Mate erson)
(Person siblingyour
an aunt
father
o u r latheer o u r mother
Answer
A Difference:
(PERSON)D
Saurabh
26
B.
Significance
1.
of class diagram:
Class diagram describes the attributes and operations of a class and
on the system.
2.
also the constraints imposed
The class diagrams are widely used in the modeling of object
oriented systems because they are the only UML diagrams, which
can be mapped directly with object-oriented languages.
3. Class diagram shows a collection of classes, interfaces, associations,
collaborations, and constraints. It is also known as a structural
diagram.
C. Significance of instance diagram:
1. An object diagram represents an instance at a particular moment,
which 18 concrete in nature.
0.1
husband
Sibling
Person
mother father
1L
child child
AKTU2011-12, Marks 05
Answer
Patron
Book
Library
CheckoutEvent
checkoutDate
dueDate
CheckoutType dateReturned
1 MateCharge
finePerDay
(dataReturned dueDate) CheckoutType.finePerDay)
lateCharge =
PART-3
Collaboration Diagram, Terms, Concepts, Depicting
A Message, Polymorphism in Collaboration Diagram,
Iterated Message, use of Self in Message.
Questions-Answers
Answer
Collaboration diagram:
A collaboration diagram, also known as a communication diagram, is an
illustration of the relationships and interactions among software objects
in the Unified Modeling Language (UML).
2. These diagrams can be used to portray the dynamic behavior of a
particular use case and define the role of each object.
Collaboration diagrams are created by first identifying the structural
elements required to carry out the functionality of an interaction.
Object
2
name j
Actors: Actors are instances that invoke the interaction in the diagram.
Each actor has a name and a role, with one actor initiating the entire
use case.
3 Links: Links connect objects with actors and are depicted using a solid
line between two elements. Each link is an instance where messages
can be sent.
Link
4 Messages: Messages between objects are shown as a labeled arrow
placed near a link. These me88ages are communications between objects
that convey information about the activity and can include the sequence
number.
Polymorphism using collaboration diagram :
1. Fig. 2.12.1 uses a collaboration diagram to illustrate polymorphisn in a
business BCenario.
2. The diagram assumes that there are different ways of calculating an
employees pay.
2-16 L(CS/IT-Sem-5) Basic Structural Modeling
3. Full-time employees are paid a salary that depends only on his or her
grade; part-time staff are paid a salary that depends in a similar way on
grade, but must also take into account the number of hours worked;
temporary staff differ in that no deductions are made for the company
pension scheme, but the salary calculation is otherwise the same as for
a full-time employee.
4. An object-oriented system to calculate pay for these employees might
include a separate class for each type of employee, each able to perform
the appropriate pay calculation.
Fixed monthy
t depends oniy
on employee grade
2a:=calculatePay()
FullTimeEmplovee
Variable monthly
amount depends on
1=getTota 2b:=calculatePayt) gTade ana n o u s
Pay
Monthly PayPrint art TimcEmployee
Pay clerk
Fixed monthly amount
but
aepends on grade,
Do pension deductions
2c:=calculatePay)
Temporary Employee
Fig. 2.12.1. Polymorphism allows a message to achieve the
same result even when the mechanism for achieving
it differs between different objects.
6. Suppose one of the outputs from this system is a print-out showing the
total pay tor the current month: to assemble the total, a message is sent
7. Since the message signature is the same in each case, the requesting
(here called MonthlyPayPrint) need not know that the class of
object
each receiving object, still less how each calculation is carried out.
Answer
Polymorphism:
1. Polymorphism means having many forms.
Object Oriented System Design 2-17 L (Cs/IT-Sem-5)
5. This indicates that the message is sent only if the condition is met.
6. The UML leaves the syntax of conditional clauses wide open, so we can
create expressions that make sense in the context of our application.
Use of self in message:
L Self represents the ability of an object to send a message to itself.
PART-4
Sequence Diagram, Terms, Concept, Depicting Asynchronous
Message With/ Without Priority, Callback
Mechanism, Broadeast Message.
Questions-Answers
Long Answer Type and Medium Answer Type Questions
Object
Pig2.14.1
2
Activation or Execution Occurrence: Activation occurrence
represent the time an object needs to complete a task. When an object is
busy executing a process or waiting for a reply message, use a thin gray
rectangle placed vertically on its lifeline.
Activation
occurrence
Fig. 2.142
3 Messages: Mes8ages are arrows that represent communication between
objects. Use half-arTowed lines to represeont asynchronous messages.
Asynchronous messages are sent from an object that will not wait for a
response from the receiver before continuing its tasks.
----------
Asynchronous
message
Synchronous
messag
Pig. 2.14.3
Object Oriented System Design 2-19L (CS/NT-Sem-5)
Lifelines : Lifelines are vertical dashed lines that indicate the
presence over time. object's
Lifeline
Fig. 2.14.4
5 Destroying objects: Objects can be terminated early using an arrow
labeled "<< destroy>>" that
points to an X. This object is removed from
memory. When that object's lifeline ends, we can place an X at the end
of its liteline to denote a
destruction occurrence.
Loops: A repetition or loop within a sequence diagram is depicted as a
rectangle. Place the condition for exiting the loop at the bottom left
corner in square brackets.
A Asynchronous messages without priority
L An asynchronous be
message can
implemented on the sequence
diagram by using a half arrowhead on the asynchronous message
arrow.
asyncMessagel (inputArg)
senderObject: targetObject:
lass1 Class2
operate
signDuration)
recordEntry
person ID, door!D,
actuelTime)
time
high-
medium priority
msg msg ihe
priority msgmsg msgmsg target
msg
priority
msg msg msg msg msE msg msg ODject
Fig. 2.14.7. Three parallel queues, each with its own priority
6 Fig. 2.14.8 shows an asynchronous message with its priority level.
7. The property (priority = 3) indicates that the message has a priority
of 3.
transmitMsg (eMailMsg)
priority= 3 eMailPort:
senderObject:
SomeClass Port
Fig. 2.14.8, An asynchronous message (with priority 3) going
to an object with a multiple-priority message queue.
Object Oriented System Design 2-21 L (Cs/IT-Sem-5)
Broadcast message:
1. A broadcast message treats every object in the system as a potential
target.
2. A copy ot the message goes into the queue of every object in the
system.
3. An object may broadcast a message in response to some external
event that it detects.
4 Por example, an object might detect a security compromise and
broadcast to all objects the need for a priority system shutdown.
5. Fig. 2.14.9 shows the UML for a broadcast message. Here, a start-
up sequencer is getting every object in the system that exists at
start-up time to load itself.
*: load ()
<<broadcast>>
StartUpSequencer :(Object)
OR
AKTU2012-13, Marks 10
What do you understand by callback mechanisms?
registerNewEMailEvent
(urgency'Thresh)
newEMailReceived
(highestUrgency) time
open (timne,
highestUrgency)
Questions-Answers
Long Answer Type and Medium Answer Type
Questions
Que 2.17. Write a short note on use case diagram and time diagram
with suitable diagram and their utility in system design.
Vending machine
Buy
beverag
Customer
Perform
cheduled
maintenance
Technician
Make
repairs
Load items
Clerk
Time diagram:
1. Timing diagram is used to show interactions when a primary purpose of
the diagram is about time.
2. It focuses on conditions changing within and among lifelines along a
linear time axis.
3. Timing diagram is a special form of a sequence diagramn.
Utility of time diagram in system design:
1. It emphasizes at that particular time when the message has been sent
among oDjects.
2. It explains the time processing of an object in detail.
3. It is employed with distributed and embedded systems.
4. It also explains how an object undergoes changes in its form throughout
its lifeline.
5. It depicts a graphical representation of states of a lifeline per unit time.
For example
State Duration constraint
d.3d)
User idle Wait card Wait access 1dle
Fig. 2.17.2.
PackageName
Que 2.19. Write short notes on use case diagram with suitable
diagram and their utility in system design.
AKTU 2014-15, Marks 05
Answer
Use case diagrams:
1 Use cases describe how a system interacts with external user of a system
(i.e., actor).
Each use case represents a piece of functionality that a system provides
to its users.
cases.
7. A use case is a coherent piece offunctionality that a system can provide
by interacting with actors.
detail.
AKTU 2014-16, Marks 05
OR
What do you mean by activity diagram ? What are the two special
states shown in an activity diagram ? Explain with an example.
For example:
data entry
processing
generate
output
Diagramn
object to another.
A signal i1s a message between objects while a signal event is
an occurrence in time.
For example, TrainDeparture has attributes train, trainNumber, city,
and date. The UML notation is the keyword signal in guillements (<< >
above the signal class name in the top section of a box. The bottom section
lists the signal attributes.
<signal>>
TrainDeparture
train
trainNumber
city
date
Fig.2.22.1.
B. Time event:
A time event 1s an event caused by the occurrence of an
absolute time or the elapse of a time interval.
2. For example, Fig. 2.22.2 shows, the UML notation for an
absolute time is the keyword when followed by a
parenthesized expression involving time. The notation for
time interval is the keyword after followed by a parenthesized
expression that evaluates to a time duration.
C. Change event
1. A change event is an event caused by the satisfaction of a
boolean expression.
The boolean expression is continually tested and whenever
the expression changes from false to true, the event occurs.
3. For example, the UML notation for a change event is the
keyword when followed by a parenthesized boolen expression.
Fig. 2.22.3 shows examples of change events.
Fig. 2.22.3.
Que 2.23.| Explain use case with example. How are the diagrams
Answer
Use case diagrams :
1. Use cases describe how a system interacts with external user of a system
i.e., actor)
2. Each use case represents a piece of funetionality that a system provides
to its users.
3. Use cases are helpful for capturing informal requirements.
4. Use case consists of actors.
5. An actor is an object or set of objects that communicates directly with
the system but that is not part of the system.
6 The various interactions of actors with a system are quantized into use
cases.
PART-6
Architectural Modeling, Component, Deployment,
Component Diagrams and Deployment Diagrams.
Questions-Answers
Long Answer Type and Medium Answer Type Questions
i. Components:
a. A component is a physical, replaceable part of a system that
packages implementation and provides the realization of a set
of interfaces.
2-32 L(CS/AT-Sem-5)
Basic Structural Modeling
b A
component is a
physical manifestation of an object that has
a
well-defined interface and set of
interface.
a
implementations for the
C.
complex system can be built using software components. It
enhances re-use in the
system and facilitates system evolution.
Component
Fig 2.24.1.Component.
Component
Component
Component A
Realization
Interface Component A
Component A
<<interface>>
Name
Attributes
Nodel
Communication
patn
Node2
Difference:
Node Component
Node represents the physical part Component represents any part
of the system for instance, server, ot the system it might be physical
CONTENTS
3-21L to 3-11L
Part-1 Object
Object
Oriented Analysis,.
Oriented Design, Object
Models,
Design, Combining Three
Designing Algorithm, Design
Optimization, Implementation of
Control, Adjustment of Inheritance,
Object Representation, Physical
Packaging, Documenting
Design Consideration
3-1L CSTT-Sem-5)
3-2L (CST-Sem-5) Object Oriented Analysis
LPART-1
Objecet Oriented Analysis, Object Oriented Design, Object
Design, Combining Three Models, Designing Algorithm, Design
Optimization, Implementation of Control, Adjustment of
Inheritance, Object Representation, Physical Packaging,
Documenting Design Consideration.
Questions-Answers
Long Answer Type and Medium Answer Type Questions
Answer
Object oriented analysis :
Object-Oriented Analysis (00A) is the procedure ofidentifying software
engineering requirements and developing software specifications in
terms of a software system's object model, which comprises of interacting
objects.
2. The primary tasks in object-oriented analysis (OOA) are:
Identifying objects
b. Organizing the objects by creating object model diagram.
C. Defining the internals of the objects, or object attributes.
d. Defining the behavior of the objects, i.e., object actions
Describing how the objects interact.
3. The common models used in O0A are use cases and object models.
Object-Oriented Design:
Object-0riented Design (OOD) involves implementation of the
conceptual model produced during object-oriented analysis.
2. In OOD, concepts in the analysis model, which are te
independent, are mapped onto implementing classes, constraints are
identifed and interfaces are designed, resulting in a model for the solution
domain, i.e., a detailed description of how the 8ystem is to be built on
concrete technologies.
3. The implementation details include
Object Oriented System Design 3-3L(CS/IT-Sem-5)
a. Restructuring the class data (if necessary),
b. Implementation of methods, i.e., internal data structures and algorithms,
C.Implementation of control, and
d Implementation of associations.
Answer
1. After the hierarchy of subsystems has been developed, the objects in
the system are identified and their details are designed.
Here, the designer details out the strategy chosen during the system
design.
3. The emphasis shifts from application domain concepts toward computer
concepts.
4 The objects identified during analysis are eteched out for implementation
with an aim to minimize execution time, memory consumption, and
overall cost.
a Object identification
b. Object representation, i.e., construetion of design models
c. Classification of operations
d Algorithm design
e. Design of relationships
f.Implementation ofcontrol for external interactions
g Package classes and associations into modules
Answer
1. The operations in the objects are defined using algorithms.
2. An algorithm is a stepwise procedure that solves the problem laid
down in an operation. Algorithms focus on how it is to be done.
3. There may be more than one algorithm corresponding to a given
4.
operation.
Once the alternative algorithms are identified, the optimal algorithm
is selected for the given problem domain.
Answer
Refer Q. 1.13, Page 1-12L, Unit-1.
Que 3.5. What are the three models in OMT ? How is the object
oriented analysis and design attached with OMT? Explain with an
1. Objectmodel:
a. Object model encompasses the principles of abstraction,
encapsulation, modularity, hierarchy, typing, concurrency and
persistence.
b. Object model emphasizes on the object and class.
c. Main concepts related with object model are classes and their
association with attributes.
Predefined relationships in object model are aggregation and
generalization (multiple inheritance).
2 Dynamic model :
a Dynamic model involves states, events and state diagram (transition
diagram) on the model.
b. Main concepts related with dynamic model are states, transition
between states and events to trigger the transitions.
3 Functional model:
a. Functional Model focuses on the how data is flowing, where data is
stored and different processes.
b. Main concepts involved in functional model are data, data flow,
data store, process and actors.
system.
The dynamic model represents the temporal, behavioral, "control" aspects
of a system.
The functional model represents the transformational, "function" aspects
of a system.
5. A typical object oriented software procedure incorporates all three
aspects: It uses data structures (object model), it sequences operations
in time (dynamic model), and it transforms values (functional model).
Each model contains references to entities in other models.
6. For example, operations are attached to objects in the object model but
more fully expanded in the functional model.
3. The dynamic model shows the sequences in which the operations are
object model.
models. Data flows to or from
5. Actors are explicit objects in the object
actors represent operations on or by the objects.
Problem
Domain
Kepresentation Design
Solution Domain
Representation
Optimization of design:
1. Design optimization is an engineering design methodoloEY using a
mathematical formulation of a design problem to support selection of
the optimal design among many alternatives.
2. Design optimization involves the following stages
a. Variables: Describe the design alternatives.
b. Objective: Elected functional combination ofvariables (to be maximized
or minimized).
c. Constraints : Combination of variables expressed as equalities or
inequalities that must be satisfied for any acceptable design alternative.
d Feasibility: Values for setof variables that satisfies all constraints and
minimizes/maximizes objective.
Object Oriented System Design 3-7L(CS/IT-Sem-5)
2.
embellished for appropriate implementation.
The approaches for implementation of the dynamic model are:
a. Represent state as a location within a program:
i. This is the traditional procedure-driven approach whereby
the location of control defines the program state.
i. A finite state machine can be implemented as a program.
ii. A transition forms an input statement, the main control path
forms the sequence of instructions, the branches form the
conditions, and the backward paths form the loops or
iterations.
b. State machine engine:
i This approach directly represents a state machine through a
state machine engine class.
. This class executes the state machine through a set of
transitions and actions provided by the application.
c. Control as concurrent tasks:
i In this approach, an object is implemented as a task in the
programming language or the operating system.
i Here, an event is implemented as an inter-task call.
i. It preserves inherent concurrency of real objects.
Answer
1. Once the classes are identified, they need to be represented using
object modeling techniques.
2. This stage essentially involves constructing UMLdiagrams.
3 There are two types of design models that need to be produced:
3-8L (CS/IT-Sem-5)
Object Oriented Analysis
a. Static Models: To describe the static structure
diagrams and of a system using class
object diagrams.
b.
Dynamic Models: To describe the dynamic strueture of a system
show the interaction between classes and
state-chart diagrams.
using interaction diagrams and
3. A package is an
organized group of elements. A package may contain
structural things like classes, components, and other packages in it.
For example, package is
a
represented by a tabbed folder.
5. A package generally
is drawn with only its name. However, it may have
additional details about the contents of the
package.
Customer
+ Personal_details
Accountdetails
+ Loan_details
Answer
Thedifferent aspects
of are:
packaging
1. Hiding internal information from outside view:
a. It allows a class to be viewed as a "black box" and permits class
implementation to be changed without requiring any clients of the
class to modify
code.
2. Coherence of elements:
a. An element, such as a class, an operation, or a module, is coherent
if it is organized on a consistent plan and all its
related so that they serve a common
parts are intrinsically
goal
3. Construction of physical modules : The following guidelines help
while constructing physical modules
Object Oriented System Design 3-9L (CS/T-Sem-5)
its components.
i.e.,
e. A module should have low coupling with other modules,
should be
interaction or interdependence between modules
minimum.
various considerations in
documentation designing? Explain.
AKTU 2011-12, Marks 05
Answer
Documentation :
that records the
Documentation is a software development process
software.
procedure of making the
be documented for any non-trivial software
The design decisions need
to
2.
others.
the design to
system for transmitting documentation is indispensable,
a good
A B
C
Fig.8.13.1.
Multiple inheritance in Java :
1 Java does not allow multiple inheritance, and we cannot extend more
than one other class.
2. Javadoesn't allow multiple inheritance to avoid the ambiguity caused by
it.
3-11L(CS/IT-Sem-5)
considerations. How do
Describe documenting design
Que 3.14.|
we perform adjustment of
inheritanee ? AKTU 2013-14, Marks 10
Answer
Unit-3.
considerations: Refer Q. 3.12, Page 3-9L,
Documentation design the chance
can be used to increase
Following kinds of adjustments
of inheritance: The missing
fewer arguments than others.
Some operations may have
1. For example, a draw operation on
arguments can be added but ignored. but the
does not need a color parameter,
a monochromatic display with color
be accepted and ignored for
consistency
can
parameter
displays. n a m e s . Give
classes may have different
2. Similar attributes in diflerent
n a m e and m o v e them to
the c o m m o n a n c e s t o r
the a t t r i b u t e s the s a m e
a c c e s s the attributes
will match better.
class. Then operations that
a r e special
fewer arguments because they
3. Some operations may have
cases of more general arguments. Implement
the
specia operations by
values.
with appropriate parameter
calling the general operation
the
are not always recognized during
Opportunities to u s e inheritance r e e x a m i n e the
s o it is w o r t h w h i l e to
analysis phase of development,
between classes.
object model looking for commonality
PART-2
Structured Analysis and Structured Design(SA/SD), Jackson
Oriented
Development(JSD), Mapping Object
Structured
Translating
Concepts Using Non-0bject Oriented Language,
Classes Into Data Structures, Passing Arguments to Method,
Association Encapsulation.
Implementing nheritance,
Questions-Answers
OR with
and structured design (SASD)
Explain structured analysis
example.
AKTU 2015-16, Marks 10
Answer
Structured analysis and structure design:
Structured Analysis Design (SAVSD) is diagrammatic
and Structured
1. u n d e r s t a n d the system.
notation which is design to help people
reduce the risk of
to improve quality and
2. The basic goal of SA/SD is
system failure.
documentation.
specification and
3. It establishes concrete management
of system.
4. It focuses on solidity, pliability and maintainability
the Data Flow Diagram.
The approach of SA/SD is based
on
5.
but it focuses on well defined system
6. It is easy to understand SA/SD have any
is to0 complex and does not
boundary whereas JSD approach
graphical representation.
SAD and it mainly focuses on following
7. SA/SD is combined known as
threepoints:
a System
b. Process
c. Technology
For
i
example
During structured design, data flow diagram processes are grouped
into tasks and allocated to operating system processes and CPUs.
Answer
AKTU2011-12, Marka 06
AKTU 2012-13, Marks 05
OR
Write short note on JSD. AKTU 2013-14, Marks 05
Answer
1. Jackson System Development (JSD) is a method of system development
that covers the software life cycle either directly or by providing a
framework into which more specialized techniques can fit.
JSD can start from the stage in a project when there is only a general
statement of requirements.
3. Following are the phases of JSD
a Modeling phase : In the modeling phase, the designer creates a
collection of entity structure diagrams and identifies the entities in
the system, the actions they perform, the attributes of the actions
and time ordering of the actions in the life of the entities.
3-14L (CS/IT-Sem-5) Object Oriented Analysis
AKTU 2010-11,Marks 06
OR
How object-oriented concept can be implemented using non-object-
oriented language? Explain with an example.
1. Class definitions:
. Thefirst step in implementing an object-oriented design is to declare
object classes. Each attribute and operation in an object diagram
must be declared as part of its corresponding class.
ii. Assign data types to attributes. Declare attributes and operations
as either public or private
2 Creating objects:
i. Object-oriented languages create new objects in following two ways:
a Class operation applied to a class object creates a new object of
the class.
a Static or dynamic
b. Implicit or explicit
C. Per object or per group.
ii Many of the popular languages are static, implicit and per grOup.
5. Implementing associations:
i There are two approaches to implement associations: buried
pointers and distinct association objects.
Ifthe language does not explicitly support association objects then
buried pointers are easy to implement.
i An association can also be implemented as a distinct container
object.
Que 3.20. Describe passing arguments to method with example.
AKTU 2012-18,Marka 05
Answer
1. There are different ways in which parameter data can be passed into
and out of methods and functions,
3-17L (CS/AT-Sem-5)
Object Oriented System Design
b.
Actual that appears in the function
o r method call
in the
formal parameter
calling environment.
: func_name(variable
namets));
Syntax
with example.
Que 3.21. Describe implementation of inheritance
PART-3
Object Oriented Programming, Reusability, Extensibility
Robustness, Programming in the Large, Procedural vls OOP,
Abstraction and Encapsulation.
Object Oriented Language Feature,
Questions-Answers
iv.
manipulates.
This concept is also used to hide the internal representation, or
Object 2
Object 1
Message C
Method 2
Method 1\
Data Data
Method 1>
Method 5/ Method 3
Method 6
Message B
Message A
Fig. 3.22.1. Message pasing between objects with encapsulation,
activating methods that can use or modify the data
within their object.
2 Polymorphism:
i Polymorphism means having many forms.
Polymorphism is the ability message to be
ofa displayed in more
than one form.
i. It plays an important role in allowing objects having different
internal structure to share the same external interface.
Inheritance:
i Inheritance is the ability to create classes that share the attributes
and methods of existing classes, but with more specific features.
ii. Inheritance is mainly used for code reusability.
3-19L(CS/AT-Sem-5)
Object Oriented System Design
Difference
C+ Java
S.No.
C++ 18 a platform dependent| Java is platform-independent
1
anguage.
language
as an
C++is a compiled language. Java is compiled a s well
a
interpreted language.
Java, translates the code into
3 C++code is not portable.
byte code. This byte code is
portable and can be executedon
any platform.
Memory management in C++ 18 n Java the memory
4
m a n a g e m e n t is a u t o m a t i c .
manual.
Answer
CONTENTS
Part-1 C++ Basics, Overview,. . . 4-2L to 4-10L
Program Structure, Namespace,
rdentifiers, Variables,
Constants, Enum, Operators,
Typecasting, Control Structures
4-1L(CS/TT-Sem-5)
C++ Basics & Functions
4-2L(CS/IT-Sem-5)
PART-1
C++ Basics, Overview, Program Structure, Namespace, Identifiers,
Variables, Constants, Enum, Operators, Typecastin8
Control Structures.
Questions-Answers
Answer
performance applications.
2. C++is a versatile language for handling very large programs.
3. It is suitable for variety of programming task including development of
editors, compilers, and different complex real-life application systems.
Applications of C++
Since C++ allows us to create hierarchy-related objects, we can build
special object oriented libraries which can be used later by many
programmers.
2. While C++ is ableto map the real-world problem properly, the C part of
C++ gives the language the ability to get close to the machine-level
details.
C++ programs are easily maintainable and expandable. When a new
3 feature needs to be implemented, it is very easy to add to the existing
structure of an object.
Answer
1. Fig. 4.2.1 shows the structureof C++ program that contain four sections
2. The class declarations are placed in a header file and the definitions of
member funetions go into another file.
Answer
A Namespace:
1. Namespace defines a scope for the identifiers that are used in a program.
2. For using the identifiers defined in the namespace scope we must include
the using directive
4 Examples:
123 l decimal integer
12.34 floating point integer
037 l octal integer
OX2 II hexadecimal integer
"C++" l string constant
A character constant
so on, up to Sat.
.
In an enum you must give a specific name to every possible value.
E Variables:
1 Avariable is a symbolic name that can be given a variety of values.
2. Variables are stored in particular places in the computer's memory.
When a variable is given a value, that value is actually placed in the
cos (x).
Answer
#include<iostream>
#includecmath.h>
float temp = n;
Binx = n
Object Oriented System Design 4-5L (CS/IT-Sem-5)
sinval = sin(n);
int i= 1;
do
denominator = 2 * i * (2*i+ 1);
temp =
-temp *n*n/ denominator;
Sinx= Sinx + temp;
i=i+ 1;
while (acc <= fabs(sinval sinx)
coute<sinx;
cosval = cos(n);
int i= 1;
do
cosx = cO5x +
temp
i=i+1;
) while (acc <= fabs{cosval cosx));
coutc< COSx,
int main(OT
float n = 30;
n-60;
coutevalue of Cos is: ";
cal_cos(n);
return 0;
Answer
1. Memory Management Operators:
C++ defines two unary operators new and delete that perform the task
of allocating and freeing the memory in a easier way.
b. Since these operators manipulate memory on the free store, they are
also known as free store operators.
The new operator can be used to create objects of any type. It takes the
tollowing general form
Manipulators
a Manipulators are operators that are used to format the data display.
b. The most commonly used manipulators are endl and setw.
The endl manipulator, when used in an output statement, causes a
linefeed to be inserted.
d It has the same effect as using the newline character "\n".
3 Type cast operator:
a C++permits explicit type conversion of variables or expressions using
the type cast operator
b. The following two versions are equivalent:
(type-name) expression // C notation
ype-name (expression) / C++ notation
c. A type-name behaves as if it is a function for converting values to a
designated type.
d The function-call notation usually leads to simplest expressions.
e. However, it can be used only if the type is an identifier. For example,
P= int (q
is illegal. In such cases, we must use C type notation.
P= (int ) g
Answer
Typecasting :
b Explicit conversion:
i Many conversions, especially those that imply a different interpretation
of the
value, require an explicit conversion.
i For example:
short a = 2000;
int b;
b= (int) a; /C
like cast notation
b=int (a); I functional notation
Dynamic cast:
dynamic_cast can be used only with pointers and references to objects.
I t s purpose is to ensure that the result of the type conversion is a valid
complete object of the requested class.
d Static cast:
static_cast can perform conversions between pointers to related classes,
not only from the derived class to its base, but also from a base class to
its derived.
e reinterpret_cast:
Btypeid:
typeid allows to check the type of an expression
typeid (expression)
T h i s operator returns a reference to a constant object of type type_info
that is defined in the standard header file <typeinfo>
que 4.7.Describe various control statements used in C++.
4-8L (CS/IT-Sem-5) C++ Basies & Functions
Answer
1. The if statement: The if statement is implemented in two forms
a. Simple if statement
b. if..else statement
2 The switch statement:
a. This is a multiple-branching statement where, based on a condition, the
control is transferred to one of the many possible points.
b. This is implemented as follows
switch (expression)
casel
actionl;
case2
action2;
case3
action3;
default
action4;
actions;
3 The do-while statement:
a. The do-while is an exit-controlled loop. Based on a condition, the control
is transferred back to a particular point in the program.
do
action
Object Oriented System Design 4-9 L (CS/IT-Sem-5)
actionl;
action2;
5 The for statement:
a The for is an entry-controlled loop and is used when an action is to be
actionl;
actionz,
Answer
#include ciostream>
using namespace std;
int main(0
char line[35);
int vowels;
vowels 0;
coute< "Enter a line of string: ":
cingetline( line, 35);
forlint i = 0, lineli]!="\0; ++i)
++vowels;
return 0:
Answer
Z.
It is used to identify the name It is used to specify the type of
of the variable. entity.
3. It can consist of letters, digits,| It contains only letters.
and underscore.
PART-2
C++ Function, Simple Function, Call and Return by Reference,
Inline Function Macro Us Inline Functions, Overloading of
Functions, Default Arguments, Friend Functions, Virtual Function.
Object Oriented System Design 4-11 L (CS/AT-Sem-5)
Questions-Answers
Long Answer Type and Medium Answer Type Questions
Answer
1. The main() returns a value of type int to the operating system.
2 C++ explicitly defines main() as matching one of the following
prototypes:
int main()
'
****
**
return 0;
5. Since the return type of functions is int by default, the keyword int in
the main() header is optional.
Most C++ compilers will generate an error or warning if there is no
return statement.
1. Call by reference:
a Provision of the reference variables in C++ permits us to pass parameters
to the functions by reference.
b. When we pass arguments by reference, the formal' arguments in the
called function become aliases to the 'actual' arguments in the calling
function.
4-12 L (CS/IT-Sem-5) C++ Basics & Functions
C. This means that when the function is working with its own arguments,
it is actually working on the original data.
d For example, consider the following function
void swapint &a, int &b) / a and b are reference variables
= t;
Now, if m and n are two integer variables, then the function call
swap(m, n);
will exchange the values of m and n using their aliases (reference
variables) a and b.
2 Return by reference:
a A function can also return a reference.
if(x> y)
return x;
else
return y;
max(a, b) = - 1;
otherwise-1 to b.
is legal and assigns
-
1 to a ifit is larger,
Answer
Answer
1. Inline function is a function that is expanded in line when it is called.
2. When the inline function is called whole code of the inline function gets
inserted or substituted at the point of inline function cal.
3. This substitution is performed by the C++ compiler at compile time.
Inline function may inerease efficiency if it is small.
4. The syntax for defining the function inline is:
inline return-type funetion-name(parameters)
Wfunction code
Answer
#includeciostream>
using namespace std;
int main(0
i n t val, num, s u m = 0;
4-14 L (CS/AT-Sem-5) C++ Basics & Functions
num = Val;
while (num != 0)
Answer
#includeiostream>
using namespace std;
class operation
cin >>a,
cout < "Enter second value:"
Cin >> b;
:: sum()
inine vo1d operation
Object Oriented System Design 4-15 L (CS/IT-Sem-5)
add = a + b;
sub = a - b;
mul = a* b;
div=a/b;
cout <<"Division of two numbers: "<< a/b<< *\n";
int main)
function \n";
cout <<"Program using inline
operations;
S-geto
S.Sum);
s.difference();
s.product(0;
s.division();
return 0;
of inline
the advantages and disadvantages
Que 416.What are
function ?
Answe
A Advantages:
Function call overhead doesn't occur.
1.
4-16 L (CS/IT-Sem-5) C++ Basics & Functions
Answer
5. In C++, inline may be defined Whereas the macro is all the time
either inside the class or outside defined at the beginning of the
the class.
program.
5. In C++, inside the class,
the While the macro is specifically
short length functions are defined.
automatically made the
functions.
inline
7. Inline is not as widely used While the is
as macro widely used.
macros.
Answer
1. C+ allows you to specify more than one definition for a funetion name
or an operator in the same scope, which is called funetion overloading.
2 An overloaded declaration is a declaration that is declared with the same
name as a previously declared declaration in the same scope, except that
both declarations have different arguments and different definition
(implementation).
3.Whenyou call an overloaded function or operator, the compiler
determines the most appropriate definition to use, by comparing the
argument types you have used to call the function or operator with the
parameter types specified in the definitions.
4. The process of selecting the most appropriate overloaded function or
operator is calied overload resolution.
Answer
#includeciostream>
using namespace std;
class Cal
public:
4-18 L (CS/IT-Sem-5) C++ Basics & Functions
return a + b+c;
intmain(void)|
Cal C; Iclass object declaration.
cout < C.add(10, 20) << endl;
cout << C.add(12, 20, 23);
return 0;
Answer
#include<iostream>
using namespace std;
class Box
private:
int length
public:
Box(): length(0) I |
friend int printlength(Box); //friend function
b.length += 10;
return b.length;
int m a i n )
Box b;
Object Oriented System Design 4-19L (CS/IT-Sem-5)
Answer
#includeiostream>
using namespace std;
Ilfunction to find longest word
int word_length(string str){
int len = str.length();
int temp = 0;
int newlen = 0;
0; i< len; i++){
for (int i =
if(strlil = )
newlen++;
else
temp = max(temp, newlen)
newlen = 0;
intmain)
string str = "Quantum Series is the best for clearing exam";
cout << "maximum length of a word is: "<e word_length(str)
return 0;
return tX +y + Z+ W),
#include <iostream>
using namespace std;
class Box
private
int length;
public:
Box(): length(0) I
friend int printLength( Box); /friend function
Answer
Characteristics of friend funetion are
1. The function is not in the scope of the class to which it has been declared
as a friend.
2 It cannot be called using the object as it ia not in the seope of that clas.
3. It can be invoked like a normal function without using the object.
4. It cannot access the member names directly and has to use an object
name and dot membership operator with the member name.
Object Oriented System Design 4-21 L (CS/IT-Sem-5)
Answer
1. A virtual function is a member function which is declared within a base
class and is redefined (Overridden) by a derived class.
When you refer to a derived class object using a pointer or a reference
to the base class, you can call a virtual function for that object and
execute the derived class's version of the function.
3. Virtual functions ensure that the correct function is called for an object,
regardless of the type of reference (or pointer) used for function call.
4 They are mainly used to achieve Runtime polymorphism
5. Functions are declared with a virtual keyword in base class.
6. The resolving of function call is done at Run-time.
Answer
1 Virtual functions cannot be static and also cannot be a friend funetion of
another class.
CONTENTS
Part-1 : Objects and Classes, 5-2L to 5-6L
Basics ot Object and Class
in C++, Private and
Public Members, Static
Data and Function Members
5-1L(CS/TT-Sem-5)
5-2L(CS/IT-Sem-5) Objects and Classes
LPART1
Objects and Classes, Basics of Object and Class in C+t, Private
and Public Members, Static Data and Function Members.
Questions-Answers
Long Answer Type and Medium Answer Type Questions
Answer
A Object:
1 An Object is an instance of a Class. Whena class is defined, no memory
1s allocated but when it is instantiated (i.e. an object is created) memory
1s allocated.
2 When a class is defined, only the specification for the object is defined;
no memory or storage is allocated. To use the data and access funetions
defined in the class, you need to create objects.
B. Classes:
1 Aclass is a way to bind the data and its associated functions together. It
allows the data (and functions) to be hidden, if necessary, from external
use.
2. When defining a class, we are creating a new abstract data type that can
be treated like any other built-in data type.
3. The class declaration describes the type and scope of its members.
4. The class function definitions describe how the class functions are
implemented.
5. The general form of a class declaration is:
class clas8_name
private
variable declarations
function declarations;
publie
variable declarations
function declarations
Object Oriented System Design 5-3L (CS/TT-Sem-5)
Answer
#include<iostream>
using namespace std;
struct node
int data;
node "next
class list
ate:
public:
list)
head = NULL;
tail = NULL
temp->data = value;
temp->next = NULL;
if(head == NULL)
5-4L(CS/TT-Sem-5) Objects and Classes
head = temp;
tail temp;
temp = NULL,
else
int main)
list obj;
obj.createnode(25);
obj.createnode(50);
obj.createnode(90);
obj.createnode(40);
cout<<"\n- - In";
cout«- Displaying Al nodes---
cout<"\n---
system"pause");
return 0;
Answer
1. A private member function can only be called by another function that
is a member of its class.
Even an object cannot invoke a private function using the dot operator
Consider a class as defined below:
class sample
in m;
void read(void); private memberfunction
Object Oriented System Desigm 5-5 L (CS/IT-Sem-5)
public
void update(void);
void writevoid);
4. If sl is an
object of sample, then
s1.read); won't work; objects cannot access
private members
is illegal.
Answer
The data members and member Only the member functions or the
functionsdeclared public can be friend functions are allowed to
accessed by other classes too. access the private data members
of a class.
The public members of a class They are not allowed to be
can be accessed from anywhere accessed directly by any object or
in the program using the direct| function outside the class.
member access operator (.) with
the object of that class.
Answer
Static data:
Static data is data that does not change after being recorded. It is a fixed
dataBet.
5-6L (CSIT-Sem-5) Objects and Classes
2. Experts contrast static data with dynamic data, where dynamie data
may change after it is recorded, and has to be continually updated.
Member function:
A member function of a class is a function that has its definition or its
prototype within the class definition like any other variable.
It operates on any object of the class of which it is a member, and has
access to all the members of a class for that object.
3. Member functions can be defined within the class definition or separately
using scope resolution operator
PART-2
Constructors and their Types, Destructors, Operators
Overloading, Type Conversion.
Questions-Answers
Answer
Constructor:
initializes objects of
1. A constructor is a member function of a class which
a class.
called when object (instance of
2. In C++, Constructor is automatically
function of the class.
class) create. It is special member
A constructor is
different from normal
fiunctions in following ways:
itself.
1. Constructor has s a m e n a m e as the class
constructor 7
What the types of
Que 6.7. are
Object Oriented System Design 5-7L (CS/1T-Sem-5)
Answer
Different types of constructor are
1. Default constructors:
a. Default constructor is the constructor which doesn't take any
argument. It has no parameters.
b. Even if we do not define any constructor explicitly, the compiler
will automatically provide a default constructor implicitly.
2 Parameterized constructors:
a It is possible to pass arguments to constructors. Typically, these
Answer
Destructor:
1. Destructor is a member function which destructs or deletes an object.
Properties of Destructor:
1. Destructor function is automatically invoked when the objects are
destroyed.
2. It cannot be declared static or const.
Answer
We call a destructor when:
1. Adestructor function is called automatically when the object goes out of
Scope
a The function ends
Answer
1 Operator overloading is a compile-time polymorphism in which the
operator is overloaded to provide the special meaning to the user-defined
data type.
2. Operator overloading is used to overload or redefines most of the
Answer
Rules for Operator Overloading:
cannot
but the operators
1. Existing operators can only overloaded,
be new
be overloaded.
operand of the user-
The overloaded operator contains at least
one
2.
defined data type.
certain operators. However,
We cannot use friend function to overload
3. the member function can be used to overload those operators.
conversion) :
1. Implicit Type Conversion (automatic type
external trigger from
Done by the compiler o n its own, without any
the user.
b. Generally takes place when in an expression more than one data
type present. In such condition
is type conversion (type promotion)
takes place to avoid lose of data.
All the data types of the variables are upgraded to the data type of
the variable with largest data type.
Converting by assignment:
a. This is done by explicitly defining the required type in
PART-3
Inheritance: Concept of Inheritance, Types of Inheritance: Single,
Multiple, Multilevel, Hierarchical, Hybrid, Protected
Members, Overriding, Virtual Base Class.
Questions-Answers
Long Answer Type and Medium Answer Type Questions
Answer
Inheritance:
1. The capability of a class to derive properties and characteristics from
another class is called Inheritance.
2. Inheritance is one of the most important features of Object Oriented
Programming.
3 The class that inherits properties from another class is called Sub class
or Derived class.
Object Oriented System Design 5-11L (CS/IT-Sem-5)
The class whose properties are inherited by sub class is called Base Class
or Super class.
Modes of inheritance:
1. Public mode:
a. If we derive a sub class froma public base class.
b. Then the public member of the base class will become public in the
derived class and protected members of the base class will become
protected in derived class.
2 Protected mode:
a Ifwe derive a sub class from a Protected base class.
b. Then both public member and protected members of the base class
will become protected in derived class.
3 Private mode:
a. If we derive a sub class from a Private base class.
b. Then both public member and protected members of the base class
will become Private in derived class.
? Explain.
Que 5.14.What are the types of inheritance
Answer
Different types of inheritance:
1. Single inheritanece:
inheritance, a class is allowed to inherit from only one
In single
class only.
class. i.e., one sub class is inherited by one base
Ibody of subelass
Multiple inheritance:
class can inherit
inheritance is a feature of C++ where a
a. Multiple is inherited from
than one classes. i.e one sub class
from more
body of subelass
5-12L (CSAT-Sem-5)
Objects and Classes
Answer
1. Protected access modifier is similar to private access modifier in the
sense that it can't be accessed outside of it's class unless with the help of
friend class, the difference is that the class members declared as Protected
can be accessed by any subclass (derived class) of that class as well.
Answer
1. If derived class defines same function as defined in its base class, it is
known as function overriding in C++.
2. It is used to achieve runtime polymorphism.
3. It enables you to provide specific implementation of the function which
is already provided by its base class.
4 For example, we are overriding the eat() function.
#include iostream>
uSing namespace std;
Object Oriented System Design 5-13 L (CS/AT-Sem-5)
class Animal
public:
void eatt
cout << "Eating..";
public:
void eat)
int main(void)
Dog d Dog(;
d.eat0;
return 0;
Answer
#includeciostream>
using namespace std;
int main)
cout <"Output:";
for (int i = 0; i < row; it+ ){
for
(int j 0;j col; j++
= <
return ,
Syntax 2
class C: public virtual A
3. Por example,
#include ciostream>»
Using namespace std;
class A
Object Oriented System Design 5-15 L (Cs/AT-Sem-5)
public:
void show)
class B: public A
class C: public A
int main0
D object
object.show();
PART-4|
Polymorphism, Pointers in C++, Pointers and Objects,
this Pointer, Virtual and Pure Virtual Function, Implementing
Polymorphism.
Questions-Answers
Long Answer Type and Medium Answer Type Questions
Answer
Polymorphism: Refer . 1.3, Page 1-3L, Unit-1.
Different types of polymorphism:
1 Compile time polymorphism: This type of polymorphism is achieved
a. Function overloading:
When there are multiple functions with same name but
different parameters then these functions are said t0 be
overloaded.
Functions can be overloaded
by change in number ofarguments
or/and change in of
type arguments.
b
Operator overloading: C++ also provides option to overload
Operators.o r example, we can make the operator ('+) for string
class to concatenate two strings.
2 Runtime polymorphism: This type of polymorphis1m is achieved by
function overriding:
a Function overriding:
Answer
#includeiostream.h>
#includecconio.hs
void main()
clrser);
int "a,"b,"temp;
cout << "BEnter value of a and b :";
Cin >> "a >> *b;
emp a
a=b
b= temp:
cout <<"nAfter
swaping na ="<« 'a << "nb ="<< "b;
getch();
Ans
Pointer:
1. Pointers symbolie representation of addresses.
are
format:
Its general declaration in C++ has the
datatype "var_name;
int "ptr; /ptr can point to an address
Use a pointer:
Define a pointer variable
Answer
1. Objects are the basic run-time entities in an object-oriented system.
2 In the object-oriented programming paradigm object can be a combination
of variables, functions, and data structures.
3. They may represent a person, a place, a bank account, a table of data or
has to handle.
any item that the program
4. Programming problem is analyzed in terms of objects and the nature of
communication between them.
5. Program objects should be chosen such that they match closely with the
real-world objects.
interact without having to know details of each other's data
6 Objects c a n
or code.
Answer
1. In C++ programming, this is a keyword that refers to the current instance
of the class.
2. There can be three main Usage of this keyword in C++:
3. For example,
#include <iostream>
Using namespace std;
class Employee
5-18 L(CS/IT-Sem-5) Objects and Classes
public:
int id, //data member (also instance variable)
string name;//data member(also instance variable)
float salary:
Bmployeelint id, string name, float salary)
this->id = id;
this->name = name;
this->salary = salary;
void display0
cout << id «<" " <<name <<" " < salary << endl;
int mainívoid) |
Employee el = Employee( 101, "Sonu", 890000); //ereating an object
of Employee
Employee e2 = Employeel102, "Nakul", 59000), I/ereating an object
of Employee
el.displayO;
e2.display(;
return 0;
Answer
3. Syntax Syntax:
virtual<func_type> virtual<func_type><unc_name>)
<func_name>()
ll code
All derived class may or may not All derived class must redefine
7.
redefine virtual function of base pure virtual function of base class
class. otherwise derived class also
becomes abstract just like base
class.