Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
94 views

Object Oriented Programming Full PDF

The document discusses object-oriented design and its key concepts. It covers topics like the meaning of object orientation, elements of an object-oriented system including objects, classes, attributes, methods, and messages. It also describes the features of object-oriented languages such as encapsulation, polymorphism, and inheritance. Additionally, it provides the steps of object-oriented design including system analysis, system design, object design, and final implementation. Finally, it differentiates between the structured approach and object-oriented approach.

Uploaded by

ashsingh536
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

Object Oriented Programming Full PDF

The document discusses object-oriented design and its key concepts. It covers topics like the meaning of object orientation, elements of an object-oriented system including objects, classes, attributes, methods, and messages. It also describes the features of object-oriented languages such as encapsulation, polymorphism, and inheritance. Additionally, it provides the steps of object-oriented design including system analysis, system design, object design, and final implementation. Finally, it differentiates between the structured approach and object-oriented approach.

Uploaded by

ashsingh536
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 116

1

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, . . . . ******

Conceptual Model of UML,


Architecture

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

with its benefits.


Que 1.1Explain object-oriented approach
Answer
the focus is capturing the structure
1 In the object-oriented approach, on

and behavior of information systems into small modules that combines

both data and process.


2. The main aim of Object Oriented Design (0OD) is to improve the quality
and productivity of system analysis and design by making it more usable.

3. In analysis phase, O0 models are used to fill the gap between problem
and solution.

4 It performs well in situation where systems are undergoing continuous


design, adaption, and maintenance.
5. It identifies the objects in problem domain, classifying them in terms of
data and behavior

6 Following are the benefits of object-oriented approach


a. It facilitates changes in the system at low cost.
b. It promotes the reuse of components.
c. It simplifies the problem of integrating components to configure
large system.
d It simplifies the design of distributed systems.
Que 1.2. Describe the elements of object-oriented system.

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)

2 Attributes: They describe information about the object.

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.

b. They are information sent to objects to trigger methods.

Que 1.3. Describe the features of object-oriented languages ?

AKTU 2012-13, Marks 05


OR
Explain the major features of Objeet-Oriented Programming.

AKTU 2013-14, Marks 05


Answer
Features of object-oriented language are:
1. Encapsulation :
i. Encapsulation means that data are encapsulated inside an inviolable
shell along with the methods required to use it.

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.

Que 1.4. Describe stepsof object-oriented design.

AKTU 2010-11, Marks 05


Answer
Steps of object-oriented design:
System analysis :
i. In this stage a statement of the problem is formulated and a model
is build. This phase show the important properties associated with
the situation.
i The analysis model is a concise, precise abstraction and agreement
on how the desired system must be developed.

i The objective is to provide a model that can be understood by any


application experts in the area.
2 System design:
A t this stage, the complete system architecture is designed.
i In this stage the whole system is divided into subsystems, based on
system analysis model and the proposed arehitecture of the system.
3. Object design :
i At this stage, a design model is developed based on the analysis
model.
. The object design decides the data strueturea and algorithms needed
to implement each of the classes in the system.
Object Oriented System Design 1-5 L (CS/IT-Sem-5)

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

S.No. Structured approach Objeetoriented approach


1. It works with Top-down Tt works with Bottom-up
approach. approach.
Program is divided into number Program is organized by having
functions. number of classes and objects.
of sub-modules or
. Function call is used. Message passingis used.
4.
Software reuse is not
possible. | Reusability is possible.
5. Structured design Object oriented design
programming usually left until programming done concurrently
end pnases. with other phases.
Structured Design is more It is suitable for in-house
suitable for off-shoring.
development.
It shows clear transition from Not so clear transition from design

design toimplementation. to implementation.


. It is suitable for real time It is suitable for most business
system, embedded system and applications, game development
projects where objects are not projects, which are expected to
the most useful level of customize or extended.
abstraction.
9. DFD&E-R diagram model the Class diagram, sequence diagram,
data state chart diagram, and use cases
all contribute.
10. In this, projects can be managed In this approach, projects can be
easily due to clearly identifiable difficult to manage due to uncertain
phases. transitions between phases.

Que 18. Write short notes on: Compare procedural


programming with object-oriented programming with examples.

AKUTU 2012-13, Marks 05


OR
1-6L(CSIT-Sem-5) Introduction

What is the difference between Procedure Based programming


language and Object-Oriented programming language?

AKVTU 2013-14, Marks05


OR
Write short notes on: Procedural v/s 0OP.

AKTU 2013-14,Marks 05
Answer

S.No. Procedural Oriented Object-Oriented


Programming Programming
1. In procedural programming.In object-oriented programming,
program is divided into small program is divided into small parts
parts called functions. called objects.
Procedural programming|Object-oriented programming
follows top down approach. ollows
bottom up approach.
There is no access specifier in Object-oriented programming has
access specifiers like private,
procedural programming.
public, protected etc.

4. Adding new data and function Adding new data and function is
1S not easy. easy.

5. Procedural programmingdoes Object-oriented programming


not have any proper way for provides data hiding so it is more
hidingdata so it is less secure. secure.

6. In procedural programming. Overloading is possible in


overloading is not possible. object-oriented programming.
7. In procedural programming. In object-oriented programming,
function is more important data is more important than
than data. function.
Procedural programming is Object-oriented programming is
based on unreal world. based on real world.

9. Examples: C, FORTRAN, Examples: C++, Java, Python,


Pascal, Basic etc. C# etc.

Que1.7. What do you understand by object-oriented technolog?


Discuss the pros and cons of object-oriented technology with

suitable example. AKTU 2011-12, Marks 10


Object Oriented System Design 1-7L (CS/IT-Sem-5)

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

teams, then each can work of one another once the


independently
modular classes have been worked out.
2 Themodular classes are often reusable : Once the modular classes
been created, they can often be used again in other applications or
have
projects.
3. The coding is easier to maintain :
a With 0OP, because our coding base has been centralized, it is easier
to create a maintainable procedure code.
b. That makes it easier to keep our data accessible when it becomes
necessary to perform an upgrade.
C. This process also improves the security of the programming since
high levels of validation are often required.
Cons of object-oriented technology are :
L Itis inefficient:
a. Object-oriented programming tends to use more CPU than
alternative options.
b. That can make it inefficient choice when there are technical
limitations involved due to the size.
2 It is scalable:
a. If 0oP is out of control, then it can create a massive amount of
bloated, unnecessary code.
b. When that occurs, the overhead rises and that makes it difficult to
keep costs down.
3. It causes duplication:
a. 00P projects tend to be easier to design than implement.
b. That is because of the modular classes that are so flexible in their
application.
1-8L(CSTT-Sem-5) Introduction

We may be able to get new projects up and running at a greater


speed, but that comes at the cost of having projects sometimes feel
like they have been cloned.
Que 1.8.What do you understand by object identity ? Explain

with an example. AKTU 2013-14, Marks 05


Answer
1. Object identity is a property of data that is created in the context of an
object data model, where an object is assigned a unique internal object
identifier, or object ID.
2. The object identifier is used to define associations between objects and
to support retrieval and comparison of object-oriented data based on the
internal identifier rather than the attribute values of an object.
3. There are many techniques for identifying objects in programming
languages.
00 languages have built-in mechanisms for identifying objects. There
is no need to create explicit object identifier types.
5. For example: In C++ an objects actual memory address serves asa
unique identifier and can be obtained by applying the '&' operator to an
object or object reference.
6. Object identity can be tested by pointer comparison.

que 1.3. Explain encapsulation with example.


OR
Discuss the concept of encapsulation with suitable example.

AKTU 2012-13, Marke 05


OR
What do you mean by encapsulation ? How does the object-oriented
concept of message passing help to encapsulate the implementationa
of an object, including its data ?

AKTU 2010-11, Marks 05


Answer
1 Encapsulation consists of separating the external aspects of an object,
which are accessible to other objects, from the internal implementation
details of the object, which are hidden from other objects
2. Encapsulation prevents a program from becoming so interdependent
that a small change has massive ripple effects.

3 The implementation of an object can be changed without affecting the


applications that use it.
Object Oriented System Design 1-9 L (CS/IT-Sem-5)

4. One may want to


change the
implementation of an object to improve
performance, fix
bug, consolidate code, or for porting.
a

5. To understand encapsulation, let us consider the


6. The attributes
object 'Employee'.
of employees
say 'salary'is kept hidden inside the
object
and may be made accessible
only through the method meant for the
purpose.

The methodresides within the object.


For example, if
getSalary() is a method of the object "Employee' to
get
the salary of an employee, then the salary of an employee can be obtained
by no other way but by this method.
8. Other objects can also send messages to the object
the salary of an employee by the getSalary() method.Employee' and get
9. Other objects need not be concerned with the attributes and internal
structure of the
object.
10. This is shown in Fig. 1.9.1. The
inside the object by a method.
figure shows that attributes are hidden

Methods

Message (Attribute Message


hidden

Fig. 1.9.1 Encapsulation of an object

Using message passing to encapsulate the implementation of


an
object:0ther parts of a system only see an object's interface
it
perform and operation signatures). Internal details
can (services
are hidden and can
only be accessed by
including data
a
message that contains a valid
51gnature.

Que L.10.Write short note on information hiding.


Answer
1. Information hiding is the process of
hiding the details of an object or
function
The hiding of these details results in an
external complexity and makes the abstraction, which reduces the
object or function easier to use.
3. In addition, information
hiding
from the internal workings of theeffectively decouples the calling code
makes it possible to object or function being called, which
change the hidden portions without having to also
change the calling code.
Introduction

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

an example. AKTU 2012-13, Marks 05


OR
? Is this concept only applicable
What do you m e a n by polymorphism
? Explain.
to object-oriented systems

AKTU 2010-11, Marks 05


OR
Define polymorphism. Is this concept only applicable to object

oriented systems ? Explain. AKTU 2014-15, Marks 05


Answer
means having many forms.
L Polymorphism
of a message to be displayed in more than
2. Polymorphism is the ability
one formn.
internal
3. It plays an important role in allowing objects having different
s t r u c t u r e to share the same external interface.

is function that may be applied to or


by objects in a class.
4. An operation a

and redisplay operations on class Windouw. All


5. Open, close, hide, are

objects in a class share the same operations.


6. Bach operation has a target object as an implicit argument.
7. The behavior of the operation depends on the class of its target.
8. An object "knows" its class, and hence the right implementation of the
operation.
9. The same operation may apply to many different classes. Such an
operation is polymorphic; t.e., the same operation takes on different
forms in different classes.

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.

4 In universal (parametric) polymorphism, the polymorphic functions are

written without mention of any specific type.


5. The ad-hoc polymorphism is applicable in both traditional and object-
oriented programming environments, whereas universal polymorphism
only applies to object-oriented syste ms.

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.

AKTU 2011-12, Marks 05


Answer
1. A model is an abstraction of something for the purpose of understanding
it before building it.
2. Since a model leave out non essential detail, it is easier to manipulate
them.

3. To build hardware and software syste ms, the developer needs to


i. Abstract different views of the system.
i Build models using precise notations.
ii. Make sure that the model satisfy the requirements of the system.
iv. Add details to transform the model into an implementation.
4. Model serves the following purpose:
1-12 L (CST-Sem-5) Introduction
Testing a physical entity before building it :
i. Simulating a model is cheaper. Also, it provides information that
is too inaccessible to be measured from physical model.
i Computer models are usually cheaper than building a complete
system and it enable flaws to be corrected early.
For example: Scale models of airplane and cars are tested in wind
tunnels to improve their aerodynamic.
b. Communication with customers:
Software designers build models to show their customers.
For example: Demonstration products like mock-ups that imitate some
or all of the external behavior
of a system.
Visualization
i Storyboards of movies, television shows, and advertisements allow
the writers to see how their idea flows.
i Using models unnecessary segments can be modified before the
final development begins.
d Reduction of complexity
Modeling helps in understanding the systems that are too complex
to understand directly.
ii Model reduces complexity by leaving out the non essential details.

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.

Que 1.14.Write short notes on :


a. Data store
Actors
C Control flow
AKTU 2016-16, Marks 15
Answer
a. Data store:
1. A data store is a passive object within a data flow diagram that stores
data for later access.
2. Unlike an actor, a data store does not
generate any operations on its
own but merely responds to requests to store and access data.

3. A data store allows values to be accessed in different order than


are generated.
a
they
Adata store is drawn as a pair of parallel lines containing the name of
the store
5. Input arrows indicate information or operations that modify the stored
data; this includes adding elements, modifying values, or deleting
elements.
6. Output arrows indicate information retrieved from the store. This
includes retrieving the entire value or some component of it.
b. Actors:
An actor is an active object that drives the data flow graph by producing
or consuming values.

Actors are attached to the


inputs and outputs of a data flow graph.
3. Examples of actors include the user of a program, a thermostat, and a
motor under computer control.
An actor is drawn as a rectangle to show that it is an object. Arrows
between the actor and the diagram are inputs and outputs of the
diagram.
Control low:
A data flow diagram shows all possible computation paths for values; it
does not show which paths are executed and in what
order
1-14 L (CS/IT-Sem-5) Introduction

2. This is done by including control flows in the data flow diagram.


A control flow is a Boolean value that affects whether a process s
evaluated.

The control flow is not an input value to the process itself.

5. A control flow is shown by a dotted line from a process producing a


Boolean value to the process being controlled.

modeling ? What is the


Que1.15. What are the principles of

importance of modeling ? AKTU 2013-14, Marks 05


OR
What are the basie principles of modeling? Explain in detail.

ARTU 2014-15, Marks 05


Answer
Principles of modeling a r e :
1. The choice of what models to create has a profound influencee
on how a problem is attacked and how a solution is shaped:
This means choose correct model as per the requirement of problem

statement.
Every model may be expressed at different levels of precision:
This means all the user and developers both may visualize a system at

different levels of details at different time.


that the
3. The best models a r e connected to reality: This means
model must have things that are practically possible. They must satisfy
the real word scenarios.
No single model is sufficient, Every non-trivial system is best
small set of nearly independent models
:
approached through a

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 :

i In this stage a statement of the problem is formulated and a model


is build. This phase show the important properties associated with
the situation.
i The analysis model is a concise, precise abstraction and agreement
on how the desired system must be developed.

ii. The objective is to provide a model that can be understood by any


application experts in the area.

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.

T h e object design decides the data structures and algorithms needed


to implement each of the classes in the system.

4 Final implementation :
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.
Que 1.17. Define link and association. Discuss the role of link and
association in object modeling with suitable example.

AKTU 2012-13, Marks 05


1-16 L (CSAT-Sem-5) Introduction

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.

a Association: It is a group of links that relates objects from the same


classes.

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.

i. Also it can be related in reverse that a company may have several


persons owing its stock.

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

Links in Object Diagram

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)

Person OwnsStock Company


Name Name

Association in class diagram


Fig. 1.17.2.

Que 1.18.What do you mean by object modeling technique ?


Explain. Diseuss the various stages of the object modeling
techniques with some example. AKTU 2015-16, Marks 10
Answer
Object modeling technique:
1. The Object Modeling Technique (OMT) is the methodology that combines
the three views of modeling system, i.e., the object model, the dynamic
model and the functioned model.

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.

d A good model can be understood by application experts who are


not programmers.

For example, a Window class ina workstation


windowing system
would be described in terms of the attributes and operations visible
a user

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

The system designer must decide what performance characteristics


to optimize, developing strategy for solving the problem, and
making tentative resource allocations.
d Por example, the system designer might decide that changes to
the workstation screen must be fast and smooth and choose an
appropriate communications protocol and memory buffering
strategy
3 Object design:
a. The object designer builds a design model based on the analysis
model but containing implementation details.
b. The designer adds details to the design model in accordance with
the strategy established during system design.
The focus of object design is the data structures and algorithms
needed to implement each class.
d The object classes are augmented with computer-domain data
structures and algorithms chosen to optimize important
pertormance measures.

For example, the Window class operations are now specified in


terms of the underly1ng hardware and operating system.

4 Implementation :

a. The object classes and relationships developed during object design


are finally implemented.

b. During implementation, it is important to follow good software


engineering practice so that traceability to the design is straight.
forward and so that the implemented system remains flexible and
extensible.

c. For example, the Window class would be coded in a programming


language, using calls to the underlying graphics system on the
workstation.

Que 1.19. Wire is used in the following applications. For each of


the following applications, prepare a list of wire characteristics
that are relevant and also explain why each characteristic is
important for the application: (1) Designing the filament for a light
bulb; (2) Designing the electrical system for an airplane.

AKTU 2011-12, Murks 05


1-19 L (CS/IT-Sem-5)
Object Oriented System Design

Answer
filament for light bulb:
Designing the a

1. Because the filament of a light bulb operates at a high temperature,


resistance to high temperatures is important.

is used because of its high melting point,


even though
2. Tungsten generally
tungsten filaments are brittle.

Designing the electrical system for an airplane:


of
used in the electrical system
1. Weight is important for wire that is to be
the total weight of the plane.
an airplane, because it affects
to vibration.
2. Toughness of the insulation is important to resist chafing due
to avoid starting or
3. Resistance of the insulation to fire is also important
feeding electrical fires in flight.

L PART-3
UML, Architecture.
Introduction of UML, Conceptual Model of

Questions-Answers

Medium Answer Type Questions


Long Answer Type and

by UML ? Discuss the conceptual


What do you mean
Que1.20.
of an appropriate example.
model of UML with the help
AKTU 2011-12, Marks 05
OR
example to illustrate
model of UML. Use some
Give the conceptual

the model in detail using


diagram. AKTU 2012-13, Marks 05
Answer
UML:
UMLstands for Unified Modeling Language.
1.
make software blueprints.
pictorial language used
to
2. UML is a

UML can be deseribed as a general purpose visual modeling language to


3. software system.
visualize, specify, construct, and document
1-20 L (CS/AT-Sem-5) Introduction
4. lt is also used to model non-software systems as well.

5. UML is not a programming language but tools can be used to generate


code in various languages using UML diagrams.
6. UML has a direct relation with object-oriented analysis and design.
Conceptual model of UML:
1. A conceptual model is defined as a model which is made of concepts and
their relationships.
2. A conceptual model is the first step before drawing a UMIL diagram.
3. It helps to understand the entities in the real world and how they interact
with each other.
4. The conceptual model of UML has three major elements:
a UML building blocks.
b. Rules to connect the building blocks.
Common mechanisms of UML.
5. A domain model, often referred to as a conceptual model, might be
represented by a particular kind of UML class diagram.
6. This model explains the structure of the application domain rather than
the application structure itself.
7. It focuses on the domain concepts, rather than on the software entities.
8 Fig. 1.20.1 shows the conceptual model for a library system.

Library

has
contains

User reserves Item


name Kind
.1 title

consults
has_copies
Co
Copy
borrowsB
location
status

Fig. 1.20,1, Conceptual model for a library system.


Object Oriented System Design 1-21 L (Cs/AT-Sem-5)

Que 1.21.Describe the pros and cons of unified modeling language

(UML). AKTU 2012-13, Marks 05


Answer
Pros of UML:
1. It has wide industry acceptance in comparison to previous modeling

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.

5. It is a unified and standardize modeling language.

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.

4. UML software costs money.


5. Complex to learn and takes time to master properly.

the basic arehitecture of


Que 1.22.Why UML required? What are

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

Basic architecture of UML:


1. The UML is defined in a circular manner, in whieh a subset of the
language notation and semantics is used to specify the language itself.
1-22 L (CS/AT-Sem-5)
Introduction
2. The UML is defined within
consists of four distinet
a
conceptual framework for modeling that
layers or levels of abstraction.
3. This framework is based on the most
fundamental UML notation that
concepts are depicted as symbols, and
relationships among concepts
are depictted as paths (lines) connecting symbols.
elements may be named.
Both of these of types
4. The concepts introduced by the
UMLare organized around architectural
views to define the various
diagrams.
5. The UML diagrams are used to
solve the problem, and
understand for conceptualize a problem,
implement
or realize the solution.
2
UNIT
Basic Structural
Modeling

CONTENTS
2-21L to 2-8LL
Part-1 : Basic Structural Modeling.. ****

Class, Relationships, Common


Mechanism and Diagram

Part-2 Class and Object Diagram,... 2 - 9 L to 2-14L

Terms, Concepts, Modeling


Techniques for Class and Object Diagram

Part-3 Collaboration Diagram, Terms,.. 2-14L to 2-17L


Concepts, Depicting A Message,
Polymorphism in Collaboratioon

Diagran1, Iterated Message,


use of Self in Message

Part-4 S e q u e n c e Diagram, Terms,.. 2-17L to 2-22L

Concept, Depicting Asynchronous


Message With/ Without Priority,
Callback Mechanism, Broadcast Message

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

Que 2.1.Explain different types of modeling in object oriented


system design.
OR
What is UML ? Mention the different kinds of modeling diagrams
used.
AKTU 2013-14, Marks 05
Answer
There three important types
are
of modeling:
L Structural Modeling
Structural modeling captures the static features of a system.
b. Structural model represents the framework for the system and
this framework is the place where all other components exist.
Hence, the class diagram, component diagram and deployment
diagrams are part of structural modeling.
They all represent the elements and the mechanism to assemble
them.

e. The structural model never deseribes the dynamic behavior of the


8ystem.

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.

ii. Interfaces: An interface is a collection of operations that are used


to specify a service of a class or a component. It is represented by a
circle. An interface possesses the following properties
a Every interface is identified by a unique name, with an
operational pathname.
b. Interfaces do not specify any structure or implementation details
of the operations. When an interface is represented as a
rectangle, it has the same parts as a class. When it is represented
as a circle, the display of these parts is suppressed.

Component A

Realization

Component A
Interface
-

Component A

Fig 2.2.3. Realization of an interface.

<<interface>>
Name

Attributes

Operations Interface name

Fig 2.24. Representation of interfaces.


Object Oriented System Design 2-5 L (CS/IT-Sem-5)

B. Deployment diagrams: They display the configuration of run-


time processing elements and the software
components, processes
and objects. The deployment diagram contains nodes and connections.
A node is a piece of hardware in the system. A connection depicts the
communication path used by the hardware (Fig. 2.2.5).

Node1

Communication
path

Node2

Fig. 2.2.5. Deployment diagram


Que 23.What do you understand by classes in object oriented
system design ?

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.

8. An object's class is an implicit property of the object.

Que 24.Explain relationship with its different types.

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

Dependency is represented by a dotted arrow as shown in the


following figure.
The arrow head represents the independent element and the other
end represents the dependent element.
Dependency is used to represent the dependency between two
elements of a system
2 Association Notation:
a. Association describes how the elements in a UML diagram are
associated.

b . I n simple words, it describes how many elements are taking part in


an interaction.
C. Association is represented by a dotted line with (without) arrows
on both sides.
d The two ends represent two associated elements as shown in the
following figure.
e. The multiplicity is also mentioned at the ends (1, ', etc.) to show
how many objects are associated.
3 Generalization Notation
a Generalization describes the inheritance relationship of the object-
oriented world.
b. It is
parent and child relationship.
a

cGeneralizationis represented by an arrow with a hollow arrow


head as shown in the following figure.
d One end represents the parent element and the other end
represents the child element.
4 Extensibility Notation:
a A l the languages (programming or modeling) have some
mechanism to extend its capabilities such as syntax, semantics, etc.
b. UML also has the following mechanisms to provide extensibility
features:

i Stereotypes (Represents new elements)


i. Tagged values (Represents new attributes)
ii. Constraints (Represents the boundaries)
c. Extensibility notations are used to enhance the power of the
language.
Que 2.5, Describe generalization and specinlization.

AKTU 2010-11, Marks 05


OR
Object Oriented System Design 2-7L(CS/IT-Sem-5)
What do you mean by generalization ? Explain. How is it related
with inheritance? AKTU201-12, Marks 05
OR
Define agsgregation and generalization. Explain.

AKTU 2012-13, Marks05


Answer

Generalization and specialization: Generalization and specialization


represent a hierarchy of relationships between classes, where subclasses
inherit from super-classes.
1. Generalization
i In the generalization process, the common characteristics of classes
are combined to
form a class in a
higher level of hierarchy, i.e.,
subelasses are combined to form a generalized super-class.
i It represents an "is - a- kind-of relationship. For example, "car is
a kind of land vehicle", or "ship is a kind of water vehicle".
2 Specialization
i Specialization is the reverse process of generalization. Here. the
distinguishing features of groups of objects are used form specialized
classes from existing classes.
It can be said that the subelasses are the specialized versions of the
super-claSS.
The following fgure shows an example of generalization and specialization.

Vehicle

Water
Land

Car Bus Ship Boat AeroplaneHelicopter


Fig. 2.6.1.

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.

2. Generalization refers to the concept of generalizing from specifics (the


subclasses) to the generic (the superclass).
Basic Structural Modeling
2-8L(CS/IT-Sem-5)
3. Inheritance refers to the effect of generalization on the subclasses.
Aggregation :
1. Aggregation is a stronger form of association. It represents the has-a or

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,

foundation, walls, rooms, windows, and so o n . A room may, in turn be,


in
composed of walls, ceiling, floor, windows,
and doors, as represented
Fig. 2.5.2.

House

Roofs
Roofs

Doors Windows|| Walls

A house and some of its component.


Fig. 2.5.2.
describe models of the real world that
Hence object aggregation helps us
of still
wellas those that are composed
composed of other models,
as
are

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

Que2.7.Explain class and object diagrams with examples.

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

Tools: Organization Apps : Organization


Location = "Chennai" Location = "Mumbai'"

Parent

Abha: Person Kanika :Person


Location = "Champaign
Locaticn="Champaign
Fig. 2.72.Object diagram showing example instances of party

Que 2.8.Differentiate between a class and object with some

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.

Class is a group of similar objects. Object is a real world entity


such as pen, laptop, mobile, bed,
keyboard, mouse, chair etc.

3. Class is a logical entity. Object is physical entity.


Class is declared using class Object is created through new
4 keyword, for example,
keyword mainly, for example,
Student 8l = new student 0;
Class student|)

Object is created many times as


Class is declared once.
per requirement.

allocated memory| Object allocates memory when


6. Class does cnot it is created.
reated.
when it 18
Object Oriented System Design 2-11 L(CS/AT-Sem-5)

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 ?

(Point) Next (Point)

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

1. Fig. 2.9.2 shows the class diagram.

2 Fig. 2.9.2 permits a degenerate polygon which consists of exactly one


point. (The same point is first and last. The point is next to itsel).

3 The class diagram also pernmits a line to be stored as a polygon.


4. Fig. 2.9.2 does not enforce the constraint that the first and last points
must be adjacent.

5. In Fig. 2.9.2 the sense of ordering is problematic. A polygon that is


traversed in left-to-right order is stored differently than one that is
traversed in right-to-left order even though both visually appear the
same.

There is no constraint that a polygon be closed and that a polygon not


b
cross itself.

7. In general it is difficult to fully capture constraints with class models and


we must choose between model complexity and model completeness.

class diagram and


Que 2.10.What is the difference between a an

instance diagram ? Discuss the significance of each. Also prepare a


class diagram for the following instance diagram as given in
Fig. 2.10.1.

Mate
(Person) (Person)

a grandmother grandfather
Child Child
(Person) Mate erson)

(Person siblingyour
an aunt
father
o u r latheer o u r mother

Child Child Child


(Person) cousin(Person)
a cousin you
Fig. 2.10.1.

AKTU 2012-13, Marks 10


Object Oriented System Design 2-13 L (CS/AT-Sem-5)

Answer
A Difference:

S. No. Class diagram Instance diagram


. A class
diagram is a An instance diagram
schema,| describes
pattern, or template for describing
how does a particular set
many possible instances of data. object relates to each other. of
A class diagram describes the| An instance diagram
general case in modeling a object instances. describes
sy'stem.
A class diagram describes object| An instance diagram is useful
classes. for documenting test
cases,
especially scenarios, and is used
to show examples to help to
clarify a complex class diagram.

The OMT symbol for a class is


a Figure below shows the OMT
rectangular box with class name representation of instance
in boldface. A line is
drawn| diagram. The class name in
between the class name
and parenthesis is at the
top ot the
attributes. object box in boldface and object
names are listed in normal
Persona font|
with their attributes.

(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.

It means the object diagram is closer to the actual system behaviour.


3. The purpose is to capture the static view of a system at a particular
moment.
Basic Structural Modeling
2-14L (CS/AT-Sem-5)
D. Class Diagram :

Mate wife 0..1 Cousin

0.1
husband
Sibling
Person

mother father
1L
child child

Fig. 2.10.2. Class diagram for family trees.


Prepare portion of an object diagram for a library
Que 2.11. a

book checkout system that shows the date


abook is due and the late
charges for an overdue book as derived objects.

AKTU2011-12, Marks 05
Answer

Patron
Book
Library
CheckoutEvent
checkoutDate
dueDate
CheckoutType dateReturned
1 MateCharge
finePerDay
(dataReturned dueDate) CheckoutType.finePerDay)
lateCharge =

Fig. 211.1. Class diagram for library book checkout aystem.

PART-3
Collaboration Diagram, Terms, Concepts, Depicting
A Message, Polymorphism in Collaboration Diagram,
Iterated Message, use of Self in Message.

Questions-Answers

Medium Answer Type Questions


Long Answer Type and

collaboration diagram ? Explain


Que 2.12.What do you mean by
a

used in a collaboration diagram. How


various terms and symbols
Object Oriented System Design 2-15 L (CS/NT-Sem-5)

polymorphism is described using a collaboration diagram ? Explain

using an example. AKTU2010-11, Marks05


OR
What is a collaboration diagram ? How polymorphism is represented
in a collaboration diagram? Explain with an exanmple.
AKTU 2011-12, Marks 05

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.

Various terms used in collaboration diagram:


L Objects: Objects are shown as rectangles with naming labels inside.
The naming label follows the convention of object name; class name.

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.

5. However, following the principle of polymorphism, the message signature


for all calculate pay operations is the same

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

to each employee object, asking it to calculate its pay.

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.

Que 213. Explain Polymorphism, Iterated Messages and use of

selfin message in collaboration diagram. AKTU 2013-14, Marks 05

Answer
Polymorphism:
1. Polymorphism means having many forms.
Object Oriented System Design 2-17 L (Cs/IT-Sem-5)

2. Polymorphism is the ability of a message to be displayed in more than


one torm.
3. It plays an important role in allowing objects having different internal
structure to share the same external interface.
Iterated messages :
1. Collaboration diagrams use syntax similar to sequence diagrams to
indicate that either a message iterates (is run multiple times) or is run
conditionally.
We can indicate that a particular message iterates by prefixing a message
sequence number with an iteration expression.
We can simply use an asterisk (") to indicate that a message runs more
than once, or we can get more specific and show the number of times a
message is repeated.

4 To indicate that a message is run conditionally, we can prefix the message


sequence number with a conditional clause such as lx = truel.

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.

2 Messages in collaboration diagrams are shown as arrows pointing from


the client object to the supplier object.
3. Messages represent a client invoking an operation on a supplier object.
4. Message icons have one or more messages associated with them.

5. Messages are composed of message text prefixed by a sequence number.


6. This sequence number indicates the time-ordering of the message.

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

que 2.14. What do you mean by sequence diagram? Explain


various terms and symbols used in a sequence diagram. Describe
2-18 L (CS/T-Sem-5) Basic Structural Modeling

the following using sequence diagram : (i) asynchronous messages


with/without priority. (i) broadeast messages.

AKCTU 2011-12, Marks10


OR
Explain sequence diagrams with example.

AKTU 2013-14, Marlks 05


Answer
Sequence diagram
1. Sequence diagrams deseribe interactions among classes in terms of an
exchange of messages over time.
2 They're also called event diagrams.
A sequence diagram is a good way to visualize and validate various
runtime scenarios.

In UMIL it is shown as a table that shows objects arranged along the X


axis and messages along the Y axis.
5. It has a global life line and the focus of control.
Various terms and symbols used in sequence diagram :
L Class roles or Participants : Class roles describe the way an object
will behave in context.

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

ig. 2.14.5. A collaboration diagram showing a hasie


asynchron0us message
2. When an asynchronous message is send, at least to loci of execution
are active in the system, because the target begins to execute
while the sender remains in
execution
3. shows a
Fig.2.14.5 specific example froma real-time system that
authorizes personnel to pass through electronically controlled
doors.

entryManager eronnelloE doo doorSis doorPlayer


EntryManager Los
SecureDoor aminatedSignMusicPayer

holdOpen (doaruratio) operate (playerDuration)

operate
signDuration)
recordEntry
person ID, door!D,
actuelTime)
time

Pis. 2.146. A5quence dingram for concurreaty executingobjecta


2-20 L (CS/AT-Sem-5)
Basic Structural Modeling
The employee inserts an ID card into a reader, and if the
is authorized toenter, the system plays jingly music, employee
gTeeting and slides the displays a
door open.
The operation that manages this
piece of the
application is
permitEntry.
After
determining that the employee is allowed through the door
permitEntry sends the synchronous message holdOpen to the
object door.
7. The operation holdOpen then handles the sound, lights, and action
associated with opening the door.
8. For the action of
opening the door, holdOpen sends to messages
hardware driver.
9. For the
sound-and-light show, holdOpen sends two asynchronous
messages, both named operate: one to doorPlayer and one to
doorSign.
10. The two
operations named operate execute concurrently: door.
B. Asynchronous message with priority:
1 In concurrency the target object receives message from lots of
concurrently executing sender objects.
2. Since these messages may arrive faster than the
target can process
them, they are ushered into the message queue.
3 The object then removes a message from the front of the queue;
process the message, and takes the next message from the queue
These messages in a queue are ordered by
5.
priority.
Fig. 2.14.7 shows a set of parallel queues at the target, each queue
with its own priority level.

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)

Fig. 2.14.9. A broadcast message.

Que 2.15. Discuss the significance of sequence diagrams. How the

following is implemented using sequence diagrams:


iii. Callback
Broadcastmechanism
messages
ii. Asynchronous messages with/without priority.

OR
AKTU2012-13, Marks 10
What do you understand by callback mechanisms?

AKTU 2013-14, Marks 05


Answer
Significance of sequence diagram:
i. Sequence diagrams are one of the important dynamic modeling
techniques in the UML.

These diagrams are used by software developers and business


professionals to understand requirements for a new 8ystem or to
document an existing process.
i Broadcast messages : Refer Q. 2.14, Page 2-17L, Unit-2.
ii. Callback mechanism:
1. Here the subscriber object registers an interest in some event via
an asynchronous me5sage to the target objeet.
2-22 L (CS/AT-Sem-5) Basic Structural Modeling

2. The target objeet continuous with other activities while it monitors


for the occurrence of an event of the registered type.

userSession: eMaillistener: eMailRevdWin:


Session PMailListenerWinApplEMailRevd

registerNewEMailEvent
(urgency'Thresh)

newEMailReceived
(highestUrgency) time

open (timne,
highestUrgency)

Fig. 2.15.1.Callback mechaniam used to detect e-mail.


3. When an event of that type occurs, the target object sends a

message back to the subseriber object to notify of the occurrence.


This is known as callback mechanism.
The sequence diagram in Fig. 2.15.2 shows an example of the
callback mechanism, where the event of interest is the arrival of
e-mail with an urgency above a certain threshold.

5. The userSession object registers its interest in new e-mail with


the emailListener object by sending the message
registerNewEMailEvent (urgencyThresh).
When e-mail thae's urgent enough arrives, eMailListener calls back
userSession with newEMaillReceived (highest Urgency), whose
argument indicates the highest urgency among the messages that actually
arrived

ii. Asynchronous messages withwithout priority : Refer Q 2.14,


Page 2-17L, Unit-2.
Object Oriented System Design 2-23 L (CS/IT-Sem-5)

Basic Behavioural Modeling, Use


PART5
Cases, use Case Diagrams,
Activity Diagram, State Machine, Process and
Thread, Event and
Signals,
Time Diagram, Interaction Diagram, Package Diagram.

Questions-Answers
Long Answer Type and Medium Answer Type
Questions

Que 2.16.| Discuss in brief basie behavioural


modeling.
AKTU 2011-12, Marks 05
OR
What do you understand by basie behavioural modeling ?
AKTU 2013-14, Marks 05
Answer
i Behavioral models describe the internal dynamic aspects of an information
system that supports the business processes in an organization.
ii. During analysis, behavioral models describe what the internal
logic of
the processes is without
specifying how the processes are to be
implemented.
ii. In the design and
implementation phases, the detailed design of the
operations contained in the object is fully specified.
iv. There are two types of behavioral models. First, there are behavioral
models that are used to represent the underlying details of a business
process portrayed by a use case model. In UML, interaction diagrams
(sequence and communication) are used tor this type of behavioral
model
v. Second, there is a behavioral model that is
used to represent the changes
that occur in the underlying data. UML uses behavioral state machines
for this.
vi. During the analysis phase, analysts use behavioral model to capture a
basic understanding of the dynamic as pects ot the underlying business
process.
vii. Traditionally, behavioral models have been used primarily during the
design phase where analysts refine the behavioral models to include
implementation details.
2-24 L (CS/IT-Sem-5) Basic Structural Modeling

Que 2.17. Write a short note on use case diagram and time diagram
with suitable diagram and their utility in system design.

AKTU 2010-11, Marks 05


Answer

Use case diagrams:


1. Use case diagrams consist of actors, use cases and their relationships.
2. The diagram is used to model the system/subsystem of an application.
A single use case diagram captures a particular functionality ofa system.
Hence to model the entire system, a number of use case diagrams are
used.
Utility of use case diagram in system design
1. It is used to gather the requirements ofa system.

2 It is used to get an outside view of a system.


3. It identifies the external and internal factors influencing the system.

4 It shows the interaction among the requirements of actors.


5. It is used for requirement analysis and high level design.
6. It models the context of a system.
7. It is used in reverse engineering and forward engineering.
For example:

Vending machine

Buy
beverag
Customer

Perform
cheduled
maintenance

Technician
Make
repairs

Load items
Clerk

Fig. 2,.17,1. Uso case diagram for a vending machine.


Object Oriented System Design 2-25 L (CS/IT-Sem-5)

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.

Que 2.18. Define package. Explain the package diagram with


suitable diagram. AKVTU 2014-16,Marka 05
OR
What are package diagrams and why are they used ?

AKTU 2013-14, Marks05


Answer
1. Package diagrams are structural diagrams used to show the organization
and arrangement of various model elements in the form of packages.
2. A package is a group of elements (classes, associations, generalizations,
and lesser packages) with a
common theme.
3. A package partitions a model, making it easier to understand and
manage. Large applications may require several tiers of packages.
Packages form a tree with increasing abstraction toward the root, which
is the application, the top-level package.
As Fig. 2.18.1 shows, the notation for a package is a box with a tab. The
purpose of the tab is to suggest the enclosed contents, like a tabbed
folder.

PackageName

Pig 2.18,1.Notation for a package


2-26 L (CS/IT-Sem-5) Basic Structural Modeling

6. For example, many business systems have a Customer package or a


Part package; Customer and Part are dominant classes that are important
to the business of a corporation and appear in many applications.
Following are the uses of package diagram:
1. Package diagrams are used to structure high level system elements.
2 Packages are used for organizing large system which contains diagrams
and documents.
3. Package diagram can be used to simplify complex class diagrams; it can
group classes into packages.

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.

Use cases are helpful for capturing informal requirements.


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.
The various interactions of actors with a system are quantized into use

cases.
7. A use case is a coherent piece offunctionality that a system can provide
by interacting with actors.

8. For example, a customer actor can buy a beverage from a vending


machine. The customer inserts money into the machine, makes a
selection, and ultimately receives a beverage. Similarly, a repair
technician can perform scheduled maintenance on a vending machine.
9 Fig. 2.19.1 summarizesseveral use cases for a vending machine.
Buy a beverage: The vending machine delivers a beverage after a
customer selects and pays for it.
Perform scheduled maintenance: A repair technician performs
the periodic service on the vending machine necessary to keep it in
good working condition.

Make repairs : A repair technician performs the unexpected service


on the vending machine necessary to repair a problem in its operation.
L o a d items:A stock clerk adds items into the vending machine to
replenish its stock of beverages.

Fig. 2.19,1. Use case summaries for a vending machine.


Object Oriented System Design 2-27 L (Cs/IT-Sem-5)

Utility of use cases


diagram in system design:
1. Use cases identify the functionality
of a system and organize it according
the of users.
toUse cases
perspective
describe complete transactions and are therefore less likely to0
omit necessary steps.
3. The main purpose of a system is almost always found in the use cases,
with requirements lists supplying additional implementation constraints.

Que 2.20.| What do you mean by activity diagram ? Explain in

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.

AKTU 2010-11, Marks 05


Answer
1. An activity diagram is a flowchart that shows activities performed by a
system.
2. The two special states shown in an activity diagram are the Initial State
(Start Point) and Final State (End Point).
Initial State or Start Point: A small filled circle followed by an arrow
represents the initial action state or the start point for any activity diagram.
Start Point/Initial State
4 Final State or End Point: An arrow pointing to a filled circle nested
inside another circle represents the final action state.

Ent Point Symbol

For example:
data entry

processing
generate
output

Fig. 2.20.1. Notation for activity states and activity-state transitions

gue 2.21. Define state machine ? Draw a state machine diagram

for answering a telephone call. AKTU 2014-16, Marlks 05


Answer
State machine:A state machine diagram models the behaviour of a single
object, specifying the sequence of events that an object goes through during
its lifetime in response to events.
2-28 L(CS/IT-Sem-5) Basic Structural Modeling

Diagramn

Fig.2.21.1.8tate machine diagram for answering a telephone call.


2-29 L(CS/IT-Sem-5)
Object Oriented System Design

What are the types of


Que 2.22. | What do you mean by event

event explain with example ? AKTU2014-15, Marks 05


Answer
1. An event is something that happens at a point in time, such as user
transmission of
presses right mouse button. An event is a one-way
information from one object to another. An event conveys information

from one object to another.


2. An event has no duration. By definition, an event happens
instantaneously with regard to time seale of an application.

3. Following are three most common events


A Signal event:
1. A signal event is the event of sending or receving a signa..

2. A signal is a one-way transmission of information from one

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.

when (date January 1, 2020)


after (30 seconds)
Fig. 2.22.2.
2-30 L (CS/AT-Sem-5) Basic Structural Modeling

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.

when (cabin temperature <heating set point)|


when (cabin temperature > cooling set point)

Fig. 2.22.3.

Que 2.23.| Explain use case with example. How are the diagrams

divided? AKTU 2013-14, Marks 05

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.

7. A use case is a coherent piece offunctionality that a system can provide


by interacting with actors.

8. For example, a customer actor can buy a beverage from a vending


machine. The customer inserts money into the machine, makes a
selection, and ultimately receives a beverage. Similarly, a repair
technician can perform scheduled maintenance on a vending machine
9. Fig. 2.23.1 summarizes various use cases fora vending machine.
Buy a beverage: The vending machine delivers a beverage
after a customer selects and pays for it.

Perform scheduled maintenance : A repair technician


performs the periodie service on the vending machine necessary
to keep it in good working condition.
Object Oriented System Design 2-31 L (CS/IT-Sem-5)

Make repairs: A repair technician performs the unexpected


service on the vending machine necessary to repair a problem
in its operation.
Load items: A stock clerk adds items into the vending machine
to
replenishits stockof beverages.
Fig. 2.23.1. Use case summaries for a vending machine
Use case diagrams are divided as:
1. Use case diagram are divided into three use cases diagrams i.e., Order,
SpecialOrder, NormalOrder and one actor which is the customer.
2. The SpecialOrder and NormalOrder use cases are extended from Order
Use case.

3. Hence, they have extended relationship.


4. The actor Customer lies outside the system as it is an external user ot
the system.

PART-6
Architectural Modeling, Component, Deployment,
Component Diagrams and Deployment Diagrams.

Questions-Answers
Long Answer Type and Medium Answer Type Questions

Que 2.24. Describe in brief component diagram.

AKTU 2010-11, Marks 05


Answer
1. 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.
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

Fig. 2.24.2. Component diagram.

ii. Interfaces: An interface is a collection of operations that are used


to specify a service of a class or a component. It is represented by a
circle. An interface possesses the
following properties
a Every interface is identified by a unique name, with an
operational pathname.
b. Interfaces do not specify any structure or implementation details
of the operations. When an interface is represented as a
rectangle, it has the same parts asa class. When it is represented
as a circle, the display of these parts is suppressed.

Component A

Realization

Interface Component A

Component A

Fig. 2.24.3, Renlization of an interface.


Object Oriented System Design 2-33 L (CSIT-Sem-5)

<<interface>>
Name

Attributes

Operations Interface name

Fig. 2.34.4. Representation of interfaces


the deployment diagram. What is the difference
Que 2.25. Explain
between components and nodes ? AKTU201415, Marks05
Answer
Deployment diagram: elements and the
1. They display the configuration of run-time processing
software components, processes and objects.
contains nodes and connection. A node is
a
2. The deployment diagram
piece of hardware in the system.
used by the hardware
3. A connection depicts the communication path
Fig. 2.25.1.

Nodel

Communication

patn

Node2

Fig 225.1., Deployment diagram.


of the physical
4 Deployment diagrams are used to visualize the topology
components of a system, where the software components are deployed.
deployment view
5. Deployment diagrams are used to describe the static
of a system.

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

network and printer etc. aspect such as libraries, file,


executables, document, packages
etc., which reside on the node.
3
UNIT
Object Oriented
Analysis

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

Part-2 : Structured Analysis and Structured.. 3-11L to 3-17L

Design (SA/SD), Jackson Structured


Development (JSD), Mapping Object
Oriented Concepts Using Non-Object
Oriented Language, Translating
Classes In to Data
Structures,
Passing Arguments to Method,
Implementing Inheritance,
Association Encapsulation

Part-3 : Object Oriented Programming,.3-17L to 3-21L


Reusability, Extensibility,
Robustness, Programming in the
Large, Procedural v/s OOP,
Object Oriented Language Feature,
Abstraction and Encapsulation

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

9ue3.1.| Write short note on object oriented analysis and object


oriented design.

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.

gue 3.2.Write short note on object design.

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.

Object design includes the following phases :

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

Que 33. How can we design an algorithm ? Explain

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.

5. The metrics for choosing the optimal algorithm are:


a. Computational Complexity : Complexity determines the efficiency
of an algorithm in terms of computation time and memory requirements.
34L(CSTT-Sem-5) Object Oriented Analysis

b. Flexibility : Flexibility determines whether the chosen algorithm can


be implemented suitably, without loss of appropriateness in various
environments.
c Understandability: This determines whether the chosen algorithm
is easy to understand and implement.

Que 3.4. What are object oriented model ? Explain.

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

example. AKTU 2013-14, Marks 10


Answer
Following are the three models in OMT:

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.

Predefined relationships in object model are aggregation


(concurrency) and generalization.

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.

c. Functional model describes the whole processes and actions with


the help of data flow diagram (DFD).
Object Oriented System Design 3-5 L (CS/IT-Sem-5)

00AD attachment with OMT:


1. Object Modeling Technique (OMT) combines the three views of modeling
systems
The object model represents the static, structural, "data" aspects of a

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.

Que 3.6.Describe the relation of functional model, object model


and dynamie models. What is relationshipand difference between
00A (Object oriented analysis) and 0OD (Object oriented design) ?

AKTU 2014-15, Marks 10


Answer
1. The functional model shows what "has to be done" by a system. The
leaf process are the operation on objects.

objects. Each process is


2 The object model
implemented by a
shows "doers" the
the
method on some object.

3. The dynamic model shows the sequences in which the operations are

pertormed. Bach sequence 1s


implemented as a
sequence, loop or

alteration of statements within some method.

4. The processes in the functional model correspond to operations in the

object model.
models. Data flows to or from
5. Actors are explicit objects in the object
actors represent operations on or by the objects.

Because actors are self-motivated objects, the functional model is not


6 sufficient to indicate when they act. The dynamic model for an actor

object specifies when it acts.

Relationship between 00A and 00D:

1. When orientation is used in analysis as well as design, the


object
blurred. This is particularly true
boundary between OOA and OOD is
in methods that combine analysis and design.
3-6L(CST-Sem-5) Object Oriented Analysis

2. One reason for this


blurring is the similarity of basic constructs (i.e.,
objects and classes) that are used in OOA and OOD.

Real-World Problem Analysis

Problem
Domain
Kepresentation Design
Solution Domain
Representation

Fig. 8.6.1. Relationship between 00A and 0OD.

Difference between 00A and OOD:


1 The fundamental difference between 00A and 00D is that 00OA
models the problem domain, leading to an understanding and
specification of the problem, while the OOD models the solution to the
problem.
2. That is, analys is deals with the problem domain, while design deals
with the solution domain.

Que 3.7. What do you mean by the optimizationof design ? Discuss


the design optimization with suitable example using diagrams.

AKTU 2012-13,Marks 053


Answer

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)

For example : Consider the design of a company's employee skills


database. Fig. 3.7.1 shows a portion of the analysis class model. The
operation companyfindskillO returns a set of persons in the company
with a gven skill. For example, an application might need all the
employees who speak Japanese.

Company Employs Person Hasskill_


Skill
Fir. 3.7.1

Que 3.8. Describe implementation of control in object oriented


design.
Answer
1. The object designer may incorporate refinements in the strategy of
the state-chart model. In system design, a basic strategy for realizing
the dynamie model is made. During object design, this strategy is aptly

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.

Que 3.9. What do you mean by object representation ?

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

Que 3.10 Describe physical packaging with example.

AKTU 2010-11, Marks 2.5


Answer
1.
Physical
A
packaging
component is a
physical and replaceable part of the
system that
conforms and provides the realization of a set of interfaces.
lt
represents
interfaces.
the physical packaging of elements like classes 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

Que 3.11. | What are the different aspects of packaging ?

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)

a. Classes in a module should represent similar things or components

in the same composite object.


b. Closely connected classes should be in the same module.
should be placed in
C. Unconnected or weakly connected classes
separate modules.
d Modules should have good cohesion, i.e., high cooperation among

its components.
i.e.,
e. A module should have low coupling with other modules,
should be
interaction or interdependence between modules
minimum.

documentation? What are the


do you by
Que 3.12.| What
mean

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

3. Though a secondary product,


particularly in the following areas number of
being developed by
a
software that is
a. In designing
developers.
strategies.
b. In iterative software development
versions of a software project.
c. In developing subsequent
a software.
d For evaluating
and a r e a s of testing.
e. For finding conditions
of the software.
f. For maintenance
d o c u m e n t a t i o n designing:
Consideration of
Various
1. It is a roadmap: the stages that can

allows standardization, and it helps to identify


a. It
be improved. facilitates the training of new
documentation also
b. Process
employees.
task:
2 It iseveryone's a r e a or project are responsible for documenting
a.
members
The of an
their processes. their strength, and
b. Every employee knows
their
own functioning,
better indicates to document
a r e the ones
their weakness, so they
their processes.
3-10 L (CS/AT-Sem-5) Object Oriented Analysis

3 Make them publie


a. The documentation of the processes must be available to all team
and company members.

b Restricting access to documentation creates the false illusion that


it's only relevant to a particular group.
4. Flexible documentation
a. Companies change, update, improve, so their processes are also
subject to constant changes. To improve the effectiveness of the
process, incorporate the necessary adjustments to the
documentation of the process.
Document the date of the last
update.
c. Save a backup copy of the files that document the process.
d Review the documents at least once a year.

Que 3.13. by multiple inheritances ? Explain it


What do you mean

with an example. Can you implement multiple inheritances in


Java?
AKTU 2010-11, Marks 05
Answer
Multiple inheritance:
1. Multiple inheritance is a feature of object-oriented computer
programming languages in which an object or class can inherit
characteristics and features from more than one parent object or parent
class.
When one class extends more than one classes then this is called nmultiple
inheritance.
Forexample :Class Cextends class A and B then this type of inheritance
is known as multiple inheritance.

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)

Object Oriented System Design

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

Long Answer Type and Medium Answer Type Questions

Que 3.15,| Describe the structured analysis and struetured design

approach with an example. AKTU 2012-13, Marks 05


OR

Write short notes o n : SA/SD.


AKTU 2013-14,Marks 06
Object Oriented Analysis
3-12L (CS/TT-Sem-5)

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

8 SA/SD involves two phases


a. Analysis Phase: It uses Data Flow Diagram, Data Dictionary.
State Transition diagram and ER diagram.

b. Design Phase: It uses Structure Chart and Pseudo Code.

For
i
example
During structured design, data flow diagram processes are grouped
into tasks and allocated to operating system processes and CPUs.

i Data flow diagram processes are converted into programming


and structure chart is created showing the
language functions,
procedure call tree.
a

Que 316. Compare the OMT methodology with SA/SD


methodology. Explain with suitable example.

AKTU 2014-16, Marks 10


Object Oriented System Design 3-13L (Cs/AT-Sem-6)

Answer

S.No. OMT methodology SA/SD methodology


1 It manages a system around I t manages system around real
procedures. world objects.
. Focus more on functional Focus more on object model and
and less object
model
model. .
on
less on functional model.
Dominance order is Dominance order is object,
functional, dynamic and dynamic and functional.
obect.
4 It is a historical approach. It is
advanced approacn.
5.
Reusability of components Reusability
across projects is less.
of components across
projects is more.

6. Not easily modifiable and | Easily modifiable and extensible.


extensible.

7. Used when functions are Used when data is more important


more important than data. than functions.

Que 3.17. Write short note on Jackson Structured Development

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

b. Specification phase : This phase focuses on actually what is to be


done.Major is
goal to map progress in the real world on progress in
the system that models it.
c. Implementation phase:
the
iIn implementation phase JSID determines how to obtain
the required functionality.
Implementation way of the system is based on transformation
of specification into efficient set of processes.

Que 3.18. How do you map the object-oriented concepts using


non-object oriented languages ? Explain with an example.

AKTU 2010-11,Marks 06
OR
How object-oriented concept can be implemented using non-object-
oriented language? Explain with an example.

AKTU 2011-12, Marks 05


Answer
Implementing an object-oriented concept in a non-object oriented language
requires the following steps :
1. Translate classes into data structures:
Each class is implemented as a single contiguous block of attributes
Each attribute contains variable. Now an object has state and identity
and is subject to side eftects.
i A variable that identifies an object must therefore be implemented
as a sharable reference.
2 Pass arguments to method8
Every method has at least one argument. In a non-object-oriented
language, the argument must be made explicit.

i Methods can contain additional objects as arguments. In passing an


must
argument to a method, reterence to the object
as a

be passedanif the value of the object can be updated within the


object
method.
3 Allocate storage for objects:
stack.
Objects can be allocated statically, dynamically or on a

Most temporary and intermediate objects are implemented as stack-


based variables.
i. Dynamically allocated objects are used when there number is not

known at compile time.


iv. A general object can be implemented as a data structure allocated
on request at run time trom a heap.
Object Oriented System Design
3-15L(CS/AT-Sem-5)
4. Implement inheritance in data
to
structures : Following ways are
use
implement data structures for
inheritance in
language :
a
non-object-oriented
Avoid it.
ii. Flatten the class
hierarchy.
ii. Break out separate
5.
objects
Implement method resolution: Method resolution is
main features of an object-oriented language that is lacking in aof non-
the one

object-oriented language. Method resolution can be implemented in


following ways
Avoid i
i. Resolve methods at compile time.
ii. Resolve methods at run timne.
6 Implement associations: Implementing
oriented language can be done by : associations in a non-object-

Mapping them into pointers.


Implementing them directly as association container objects.
7. Deal with concurreney :
Most languages do not
explicitly support concurrency
i Concurrency is usually needed only when more than one external
event occurs, and the behaviour of the program depends on their
timing.
8 Encapsulate internal details of classes :
i Object-oriented languages provide constructs to encapsulate
implementation.
i Some of this encapsulation is lost when object-oriented concept is
translated into a non-object-oriented language, but we can still
take advantage of the encapsulation facilities provided by the
language.
Que 3.19. Write short note on translating objeet oriented design

into an implementation. AKTU 2010-11, Marka O5


AKTU 2014-15,Marks 05
Answer
i It is easy to implement an object-oriented design with an object-oriente
language since language constructs are similar to design constructs.
i The following steps are required to implement an object oriented design
in an object-oriented language
3-16L(CS/AT-Sem-5) Object Oriented Analysis

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.

h. Using special operations that create new objects.


ii. When a new object is created, the language allocates storage for its
attribute values and assigns it a unique object 1D.
3 Calling operations:
In most object-oriented languages, each operation has at least one
implicit argument, the target object, indicated with a special syntax.
i. Operations may or may not have additional arguments.
4 Using Inheritance:
To implement inheritance object-oriented languages use different
mechanisms.
There are three independent dimensions for classifying inheritance
mechanisms :

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

funetion BO is called from another


function A0. In
2 Let us a s s u m e that a the "called
"caller function" and B is called
this c a s e A is called the
function or callee function.
and the
B called actual arguments
The arguments which A sends to
are
3.
formal arguments.
parameters of B a r e called
Following are the types of parameters:
in the
Formal parameter:A variable and
its type as they appear
a.
o r method.
prototype of the function
Syntax: function_name(datatype variable_name):

parameter: The variable or expression corresponding to a

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

AKTU 2012-13, Marks 05


Answer
classes
Inheritance is the sharing of attributes and operations among
1.
based on a hierarchical relationship.
for implementation
Object-oriented languages provide strong support
of inheritance.
Inheritance has become synonymous with
code reuse within the object-
3.
oriented programming community.
looks at the resulting classes
After modeling a system, the developer
r e u s e common code.
and tries to group similar
classes together and
(such as a class library) which the
5. Often code is available from past work
to get the precise desired behavior.
developer can reuse and modify

PART-3
Object Oriented Programming, Reusability, Extensibility
Robustness, Programming in the Large, Procedural vls OOP,
Abstraction and Encapsulation.
Object Oriented Language Feature,

Questions-Answers

Long Answer Type and Medium Answer Type Questions


Object Oriented Analysis
3-18L(CS/IT-Sem-5)
Que 3.22. Describe the various features of object-oriented
languages. Also compare any two object-oriented languages.

AKTU 2010-11, Marks 05


Answer
Features of object-oriented language are:
1. Encapsulation:
i Encapsulation means that data are encapsulated inside an inviolable
shellalong with the methods required t0 use it.
i. The only way to reach the data is through these particular methods
(see Fig. 3.22.1).
i. It is the mechanism that binds together code and the data it

iv.
manipulates.
This concept is also used to hide the internal representation, or

state, of an object from the outside.

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.

Que 3.23.Explain each of the following with in reference to objeet


oriented programming style with an example:
i. Reusability
ii. Robustness
ii. Extensibility
iv. Abstraction AKTU 2011-12, Marks 10
OR
Write short notes on the following reusability and robustness.

AKTU 2010-11, Marlks 05


Answer
i Reusability:
1. Reusability is a segment of source code that can be used again to add
new functionalities with slight or no modification.
2 Reusable software reduces design, coding and testing cost. Also, reducing
the amount of code simplifier understanding. In object-oriented
the possibility of code reuse is greatly enhanced.
languages
kind
3. There are two
of reuse:
i Sharing of newly-written code within a project.
ii. Reuse of previously-written code on new project.
4. Rules for reusability: Following rules must be kept in mind:
Keep methods coherent.
ii. Keep methods small.
i Keep method consistent.
3-20 L (CS/IT-Sem-5)
Object Oriented Analysis

iv. There should be separate policy and implementation.


v. Provide uniform average.
vi. Broaden the method as much as
possible.
vii. Avoid global information.
vii. Avoid modes.
ii. Robustness :
1. A method is robust if it does not fail even if it receives
improper
parameters.
2. Robustness against
internal bugs may be traded off against eflicieney.
3. Robustness against user errors should never be sacrificed.
4. Rules for robustness :
a.
Protect against errors: Software should protect itself against
incorrect user input. Incorrect user input should never cause a
crash.
b. Optimize after the program Dont
runs: optimize a program
until you
get it working.
Validate arguments: External operations, those available to users
of the class, must rigorously check their arguments to prevent
failure. Don't include arguments that cannot be validated.
d Avoid predefined limits: When possible use dynamic memory
allocation to create data structures that do not have predefined
limits.
e
Instrument the program for debugging and performance
monitoring: You should instrument your ecode for debugging,
and
statistics, performance. The level of debugging that you must
build into your code depends on the programming environment
presented by the language.
i . Extensibility:
1 Extensibility is a soft ware engineering and systems design principle
that provides for future growth.
2. Extensibility is a measure of the ability to extend a system and the level
of effort required to implement the extension.
3. Extensions can be through the addition of new functionality or through
modification of existing functionality.
The principle provides for enhancements without impairing existing
system functions.
For example : Object-oriented application frameworks which achieve
extensibility typically by using inheritance and dynamic binding.
iv. Abstraction:
Abstraction is the selective examination of certain aspects of a problem.
2. The goal of abstraction is to isolate those aspects that are important for
some purpose and suppress those aspects that are unimportant.
Object Oriented System Design 3-21 L(CS/NT-Sem-5)

3. Abstraction must always be for some purpose, because the purpose


determines what is and is not important.
4. Many different abstractions of the same thing are possible, depending
on the purpose for which they are made.

Que 3.24. Compare Abstraction and Encapsulation.


AKTU 2015-16, Marks 05

Answer

S. No. Abstraction Encapsulation


Abstraction is the process or Encapsulation is t h e process or
method of gaining the| method to contain the information.
information.

2. In abstraction, problems are| In encapsulation, problems are


level.
solved at the design or| solved at the implementation
interfacelevel.
Abstraction is the method of| Encapsulation is a method to hide
hiding the unwanted the data in a single entity or unit|

information. along with a method to protect


ntormati0n from outside.

We can implement| Encapsulation is implemented using


abstraction using abstract| by access modifier i.e. private,
class and interfaces. protected and public.
5. The objects that help to Objects that result in encapsulation
need not be abstracted.
perform abstraction are
encapsulated.
4
UNIT
C++ Basics & Functions

CONTENTS
Part-1 C++ Basics, Overview,. . . 4-2L to 4-10L
Program Structure, Namespace,
rdentifiers, Variables,
Constants, Enum, Operators,
Typecasting, Control Structures

Part-2 C++ Function, Simple Function,. 4-10L to 4-21L


Call and Return by Reference,
Inline Function Macro vs Inline
Functions, Overloading of
Functions, Default Arguments,
Friend Functions, Virtual Function

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

Long Answer Type and Medium Answer Type Questions

Que 4.1. Write short note on C++ and its applications.

Answer

1. C++ is an object-oriented programming language developed by Bjarne


Stroustrup.
2 C++ is a cross-platform language that can be used to create high-

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.

Que 4.2. Explain the structure of C++ program.

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.

This approach enables the programmer to separate the abstract


specification of the interface (class definition) from the implementation
details (member functions definition).
Object Oriented System Design 4-3 L (CS/IT-Sem-5)
4. The main
program that uses the class is placed in a third file which
"includes" the previous two files as well as
any other files required.
Include files
Ciass declaration

Member functions definitions


Main function program

Fig. 4.2.1.Structure of a C++ program.

Que 4.3.| Describe briefly the term namespace, identifiers,


variables constants, enum.

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

using namespace stad


3. Here, std is the namespace where standard class ibraries are defined.
4. This directive will bring all the identifiers defined in std to the current
global scope.
B. Identifiers
1. Identifiers refer to the names of variables, funetions, arrays, classes,
etc., which are created by the programmer.
2. They are the fundamental requirement of any language.
3. Each language has its own rules for naming these identifiers. Following
are the rules for C++
a. Only alphabetic characters, digits and underscores are permitted.
b. The name cannot start with a digit.
c. Uppercase and lowercase letters are distinct.
d A declared keyword cannot be used as a variable name.
C. Constants:
1. Constants refer to fixed values that do not change during the execution
of a program.
2. They include integers, characters, floating point numbers and strings.
3. Literal constant do not have memory locations.
44L (CS/TT-Sem-5) C++ Basics & Functions

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

L'ab / wide-character constant


D. Enumeratedd
1. enum specifier defines the set of all names that will be permissible
An
values of the type. These permissible values are called members.
2. The enum type days_of week has seven members: Sun, Mon, Tue, and

so on, up to Sat.

3. Enumerated means that all the values are listed.


4. This is unlike the specification of an int, for example, which is given in
terms of a range of possible values.

.
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

memory space occupied by the variable.


Most popular languages use the same general variable types, such as
characters.
integers, floating-point numbers, and

C++ program to calculate the value of sin (x) and


que 44.Write a

cos (x).

Answer
#include<iostream>

#includecmath.h>

using namespace std;


llcalculate value of sin
void cal_sin(float n)
float acc = 0.0001, denominator, sinx, sinval;
llconvert in radian
(3. 142/ 180.0;
*
n =n

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;

Ilcaleulate value of cos


void cal _cos(float n)
float acc 0.0001, temp, denominator, cosx, cosval;
n=n*(3.142/ 180.0); /lconvert in radiam
temp= 1;
coSx = temp;

cosval = cos(n);

int i= 1;
do

denominator =2*i *(2*i- 1;


temp -temp " n * n/ d e n o m i n a t o r ;

cosx = cO5x +
temp
i=i+1;
) while (acc <= fabs{cosval cosx));
coutc< COSx,

int main(OT
float n = 30;

cout<<value of Sin is: "; cal_ sin(n);


coute\n";

n-60;
coutevalue of Cos is: ";

cal_cos(n);
return 0;

Que 45.What a r e the different types of operators used in C++?


4-6L (CS/IT-Sem-5) C++ Basics & Functions

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

pointer-variable = new data-type:

d. When a data object is no longer needed, it is destroyed using the delete


operator.

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

Que 4.6. Explain typecasting in Ct+

Answer
Typecasting :

Converting an expression of a given type into another type is known as


typecasting.
2. Following are the types of typecasting:
Object Oriented System Design
4-7L (CS/IT-Sem-5)
a. Implicit conversion:

Implicit conversions do not require any operator.


i. They are automatically performed when a value is
copied to a
compatible
type.
i. For example:
short a = 2000;
nt
b
a,

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:

reinterpret_cast converts any pointer type to any other pointer type,


even of unrelated classes.
i The operation result is a simple binary copy of the value from one
pointer to the other.
const cast: This type of casting manipulates the constness of an object,
either to be set or o be removed.

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.

b. The syntax is as follows:

do

action
Object Oriented System Design 4-9 L (CS/IT-Sem-5)

while (condition is true);


action2,
The while statement
a. This is an entry-controlled loop structure.
b. The syntax is as follows :
while (condition is true)

actionl;

action2;
5 The for statement:
a The for is an entry-controlled loop and is used when an action is to be

repeated for a predetermined number of times.


b. The syntax is as follows :
for (initial value; test; increment)

actionl;

actionz,

Write program in C++ to count display the frequency


Que 48 a

of vowels in a given sentence of at least 35 characters long.

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)

iflinelil=='a' || linelil==e' || linefil==**||


linelil=='o'|| linelil==u' || linelil=='A' ||
linelil==E || linelil==T || lineli)==0° ||
linelil--UJ)
4-10 L (CS/IT-Sem-5) C++ Basics & FPunctions

++vowels;

coute< "Vowels: " <<vowels<cendl;

return 0:

Que 4.9. Differentiate between identifiers and keywords.

Answer

S. No. Identifiers Keywords


Identifiers are the names Keywords are the reserved words
to is known by the
defined by the programmer whose meaning
the basic elements of a compiler
program.

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.

4 It can use both lowercase and| It uses only lowercase letters.


uppercase letters.

5. No special character can be It cannot contain any specia


used except the underscore. character.
The starting letter of It can be started only with the
6.
identifiers can be lowercase, lowercase letter.
uppercase or underscore.

It can be classified as internal I t cannot be further classified.


and external
identifiers
Examples are test, result, | Examples are 'for, 'if, 'else',
8
sum, power, etc. "break', etc.

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

Que 4.10. Explain the prototype of main() function.

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()
'

int main(int argc, char argvl|)


The functions that have a return value should use the return statement
for termination.
4 Hence the main) function in C++ is defined as follows :
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.

Que 4.11. Describe call by reference and returm by reference with


example.
Answer

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

intt=a, IDynamic initialization


a = b;

= 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.

b. For example, consider the following function:

int & max(int &x, int &y)

if(x> y)
return x;

else

return y;

the funetion returns reference to


c. Since the return type of max() is int &,
xor y (and not the values).
yield a reference to either a or
d Then a function call such a s max(a, b) will
bdepending on their values.
can appear on the left-hand
side of an
e. This m e a n s that this function call
assignment statement.

This the statement


f. means

max(a, b) = - 1;
otherwise-1 to b.
is legal and assigns
-

1 to a ifit is larger,

Differentiate between call by value and call by reference.


Que 4.12.|
Object Oriented System Design 4-13 L (CS/T-Sem-5)

Answer

S. No. Call by value Call by reference


A copy of the value is passed into An address of value is passed into
the function. thefunction.
2. Changes made inside the Changes made inside the
function are limited to thel function validate outside of the
function only. The values of the| function also. The values of the
actual parameters do not change| actual parameters do change by
by changing the formal changing the formal parameters
parameters.

3. Actual and formal arguments|Actual and formal arguments are


are created at the different| created at the same memory
memory location. location.

Que 4.13. Explain inline function.

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

Que 4.14. Write a program in C++ to caleulate the sum of the


digits of a given positive integer number. For example, if the given
number is 12345 then the program should display: 15.

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

cout <<"Enter the number: "


Cin >>val;

num = Val;

while (num != 0)

sum= sum + num % 10;

num = num / 10;

cout <<"The sum of the digits of"


<< val << " is " << sum;

Write perform addition, subtraction,


Que 4.15. a
program to

multiplication and division using inline function.

Answer
#includeiostream>
using namespace std;

class operation

int a, b, add, sub, mul;


float div
public:
void get;
void sum();
void difference();
void productO;
void division();

inlinevoid operation:: get)


cout << "BEnter first value:";

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;

cout << "Addition of two numbers: "<< a + b<< "\n";

inline void operation:: difference()

sub = a - b;

cout << "Difference of two numbers" << a- b«<"\n";

nline void operation :: product()

mul = a* b;

cout «< "Product


of two numbers: "«a*b«<"\n";
inline void operation ::division(0

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

2 It also saves the overhead of push/pop variables on the stack when


function is called.
Tt also saves overhead of a return call from a function.
4. When you inline a function, you may enable compiler to perform context
specific optimization on the body of function. Such optimizations are not
possible for normal funetion calls. Other optimizations can be obtained
by considering the flows of calling context and the called context.
5. Inline function may be useful (ifit is small) for embedded systems because
inline can yield less code than the function call preamble and return.
B. Disadvantages:
1. The added variables from the inlined function consume additional
registers.
you use too many inline functions then the size of the binary executable
file will be large, because of the duplication of same code.
3. Too much inlining can also reduce your instruction cache hit rate, thus
reducing the speed of instruction fetch from that of cache memory to
that of primary memory.

Inline function may increase compile time overhead if someone changes


the code inside the inline function then all the calling location has to be
recompiled because compiler would require to replace all the code once
again to reflect the changes, otherwise it will continue with old
functionality.
5. Inline functions may not be useful for many embedded systems. Because
in embedded systems code size is more important than speed.

Que 4.17. Differentiate between inline and macro function.

Answer

S No. Inline Macro


L. An inline function is defined by| Whereas the macros are defined
the inline keyword. by the are define keyword.

Through inline function, the Whereas macro can't access the


class's data members can be class's data members8.
accessed.

3. In the case of inline function,|Whereas in the case of macros,


the program can be easily| the program can't be easily
debugged. debugged.
4. In the case of inline, the| Whereas in the case of macro,
arguments are evaluated only| the arguments are evaluated
once. every time whenever macro is
used in the program.
Object Oriented System Design 4-17 L (CS/AT-Sem-5)

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.

8. Inline is not used in competitive While the macro is very much


programming. used n competitive
programming.
9. Inline function is terminated by While the macro is not
the curly brace at the end. terminated by any symbol, it is
terminated by a new line.

ae 4.18. What do you mean by overloading of a function ?

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.

Que 4.19. Write a program of function overloading when the


number of arguments are different.

Answer
#includeciostream>
using namespace std;
class Cal
public:
4-18 L (CS/IT-Sem-5) C++ Basics & Functions

static int add(int a,int b


return a +b;

static int add(int a, int b, inttc)

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;

Que 4.20. Write a program to print the length of a rectangle using


friends funetion.

Answer

#include<iostream>
using namespace std;
class Box

private:
int length

public:
Box(): length(0) I |
friend int printlength(Box); //friend function

int printlength( Box b)

b.length += 10;

return b.length;

int m a i n )

Box b;
Object Oriented System Design 4-19L (CS/IT-Sem-5)

coutelength of box:"<« printLengthblecendl;


return 0;

Que 4.21. Write a program in C++ to display the longest word in a


given sentence.

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;

return max( temp, newlen);

intmain)
string str = "Quantum Series is the best for clearing exam";
cout << "maximum length of a word is: "<e word_length(str)
return 0;

Explain default argument.


Que 4.22.
Answer
default argument is a value provided in a function declaration that is
automatically assigned by the compiler ifthe caller of the funetion doesn't
provide a value for the argument with a default value.
#includeciostream>
4-20 L (CS/AT-Sem-5) C++ Basics & Functions

using namespace std;


WA function with default arguments, it can be called with
I2 arguments or 3 arguments or 4 arguments.
int sumlint x, int y, int z=0, int w=0)

return tX +y + Z+ W),

Que 4.23.Explain friend funetion with example.


Answer
1. Ifa function is defined as a friend function in C++, then the protected
and private data of a class can be accessed using the function.
2. By using the keyword friend compiler knows the given function isa
friend funetion.
3. For accessing the data, the declaration of a friend function should be
done inside the body of a class starting with the keyword friend.
4. For example,

#include <iostream>
using namespace std;
class Box

private
int length;

public:
Box(): length(0) I
friend int printLength( Box); /friend function

Que 4.24.What are the eharacteristics of 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)

5. It can be declared either in the private or the public part.

Que 4.25. Deseribe virtual funetion.

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.

Que 4.26.What are the rules used for a virtual function ?

Answer
1 Virtual functions cannot be static and also cannot be a friend funetion of
another class.

2. Virtual functions should be accessed using pointer or reference of base


class type to achieve run time polymorphism.
The prototype of virtual functions should be same in base as well as
derived class.
They are always defined in base class and overridden in derived class. It
is not mandatory for derived class to override (or re-define the virtual
function), in that case base class version of function is used.

5. A class may have virtual destructor but it cannot have a virtual


constructor.
5UNITT
Object and Classes

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

Part-2 Constructors and t h e i r . . . ******* ... 5-6L to 5-10L


********

Types, Destructors, Operators


Overloading, Type Conversion

Part-3 Inheritance : Concept of.. -l0L to b--161


Inheritance, Types ot
Inheritance: Single,
Multiple, Multilevel,
Hierarchical, Hybrid,
rotected Members,
Overriding, Virtual Base Class

Part-4 : Polymorphism, Pointers in... 6 - 1 5 1 to 5-19L


C++, Pointers and Objects,
this Pointer, Virtual and Pure
Virtual Function, Implementing
Polymorphism

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

Que5.1.Write short note on object and classes.

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)

6. The class declaration is similar to a struct declaration. The


keyword
class specifies that what follows is an abstract data of type class_name.
7 The body of a class is enclosed within braces and terminated by a
semicolon.
8. The class body contains the declaration of variables and functions. These
functions and variables are collectively called class members.
9. The class members that have been declared as private can be accessed
only from within the class.
10. While the public members can be accessed from outside the class also.
11. The variables declared inside the class are known as data members and
the functions are known as member functions.

Que 5.2.Design a class using C++ to create a singly linked list.

Answer
#include<iostream>
using namespace std;
struct node

int data;
node "next

class list

ate:

node "head, *tail;

public:
list)

head = NULL;

tail = NULL

void createnodelint value)

node "temp = new node;

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

tail -> next =


temnp
tail = temp;

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;

Que 53 Explain private member function.

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.

However, the function read0 can be called by the function update) to


update the value of m.
void sample:: update(void)

read); IIsimple call; no object used

Que 54. Differentiate between publie and private member


function.

Answer

.No. Public Private


1 All the class members declared The class members declared as
under publie will be available to private can be accessed only by
everyone. the functions inside the class.

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.

Que 5.5.Explain static data and static function member.

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

Defining a member function within the class definition declares the


function inline, even if you do not use the inline specifier.

PART-2
Constructors and their Types, Destructors, Operators
Overloading, Type Conversion.

Questions-Answers

Answer Type Questions


Long Answer Type and Medium

constructor is different from


constructor. How
Que 5.6.Define
normal member function.
-

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

Constructors don't have return type.


2.
called when an object is created.
3. A constructor is automatically
default
constructor, C++compiler generates a
4. If we do not specify a

(expects no parameters and has an empty body).


constructor for us

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

arguments help initialize an object when it is created.


b. To create a parameterized constructor, simply add parameters to it
the way you would to any other function.
When you define the constructor's body, use the parameters to
initialize the object.
Copy constructor:
a A copy constructor is a member function which initializes an object

using another object of the s a m e class.


Whenever we define one or more non-default constructors (with
parameters) for a class, a default constructor (without parameters)
should also be explicitly defined as the compiler will not provide a

default constructor in this case.


c. However, it is not necessary but it's considered to be the best practice
to always define a default constructor.

Que 5.8. Define destructor with its properties.

Answer
Destructor:
1. Destructor is a member function which destructs or deletes an object.

2. Following is the Syntax of destructor


-constructor-name();

Properties of Destructor:
1. Destructor function is automatically invoked when the objects are

destroyed.
2. It cannot be declared static or const.

3. The destructor does not have arguments.


4. It has no return type not even void.
5. An objeet of a class with a Destructor cannot become a member of the
union.
5-8L(CSSIT-Sem-5) Objects and Classes
6. A destructor should be declared in
the public section of the class.
7. The
programmer cannot access the address of destructor.

Que 5.9. When we call a destructor ? How it is different from


normal member function. Can there be
more than one destructor in
a class ?

Answer
We call a destructor when:
1. Adestructor function is called automatically when the object goes out of
Scope
a The function ends

b. The program ends


C. A block containing local variables ends
d Adelete operator is called
2. Destructors are different from a normal member function:
a. Destructors have same name as the class
preceded by a tilde (-).
b. Destructors don't take any argument and don't return
anything.
No, there can only one destructor in a class with classname preceded by -, no
parameters and no return type.

Que 5.10.Describe operator overloading

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

operators available in C++.


3. It is used to perform the operation on the user-defined data type.
For example, C++ provides the ability to add the variables of the user-
defined datatype that is applied to the built-in data types.
The advantage of Operators overloading is to perform different
operations on the same operand.
6. Syntax of Operator Overloading
return_type class_name ::operator oplargument_list)
1 body of the function.
5-9L(CS/IT-Sem-5)
Object Oriented System Design

Que 5.11. What are the rules of operator overloading?

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.

member function take


4. When unary operators are overloaded througha
friend function,
explicit arguments, but, if they are overloaded by
a
no

takes one argument.


member function
When binary operators are overloaded through a

overloaded through a friend


takes one explicit argument, and if they are

function takes two explicit arguments.

Explain type conversion with its type.


Que 5.12
Answer
conversion from one type to another. There are two
A type cast is basically a

types of type conversion:

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.

d It is possible for implicit conversions to lose information, signs can

be lost (when signed is implicitly


unsigned), and
converted to
overflow can occur (when long is implicitly converted to float).

2 Explicit Type Conversion


a. This process is also calledtype casting and it is user-defined. Here
the user can typecast the result to make it of a particular data type.

b. In C++, it can be done by two ways :

Converting by assignment:
a. This is done by explicitly defining the required type in

front of the expresS1on in parenthesis. This can be also


considered as forceful casting
5-10L (CS/IT-Sem-5) Objects and Classes

b. Following is the syntax:


(type) expression
where type indicates the data type to which the final result
is converted.
i. Conversion using Cast operator
Inheritance: concept of inheritance, types of inheritance: single,
multiple, multilevel, hierarchical, hybrid, protected
members, overriding, virtual base class
a Acast operator is a unary operator which forces one data
type to be converted into another data type.
b. C++ supports four types ofcasting
i Static Cast
. Dynamic Cast
ii. Const Cast
iv. Reinterpret Cast

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

Que 5.13.Define inheritance. What are the modes of inheritance?

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

b. Following is the syntax:


access_mode base_class
class subclass_name:

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

more than one base classes,

b. Following is the syntax


access_mode
access_mode base_clas81,
class subclass_ name:
base_clas52, .

body of subelass
5-12L (CSAT-Sem-5)
Objects and Classes

3 Multilevel inheritance: In this type


created from another derived class.
of inheritance, a derived class is

4 Hierarchical inheritance : In this type of inheritance, more than one


sub class is inherited from a single base class, i.e., more than one derived
class is created from a single base class.
5 Hybrid (Virtual) inheritance:
a. Hybrid inheritance is implemented by combining more than one
type of inheritance.
b. For example : Combining Hierarchical inheritance and Multiple
Inheritance.
Que 5.15.What are protected member ? What is difference between
publie and protected access modifier.

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.

S. No. Publie Protected


1. All the class members Protected access modifier is
declared under public will be similar to that of private access
available to everyone. modifiers.

2 The data members and The class member declared as


member functions declared Protected are inaccessible
public can be accessed by outside the class but they can be
other classes too.
accessed by any subelass (derived
class) of that class.

Que 5.16.Explain function overriding.

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..";

class Dog: public Animal

public:
void eat)

cout << "Eating bread...";

int main(void)
Dog d Dog(;

d.eat0;
return 0;

read in two matrices from the


Que 5.17.Write a program in C++ to
keyboard and compute their sum.

Answer

#includeciostream>
using namespace std;
int main)

int row, col, ml[10][10), m2[10][10], sum[10][10;


cout << "Enter the number of rows(should be »1 and <10): ";

cin >> row;


cout << "Enter the number of column{should be >1 and <10): ";

cin >> col;


cout &< "Enter the elements of first lst matrix: "
row; i++ )
for(int i =0; i <

for (int j = 0;j < col; j++)|


cin >> mllilG};
5-14L (CS/IT-Sem-5) Objects and Classes

cout << "Enter the elements of first 1st matrix:";


for (int i = 0;i <row; i++)
for 0;j
(int j = <
col; j++)
cin >> m2i]G):

cout <"Output:";
for (int i = 0; i < row; it+ ){

for
(int j 0;j col; j++
= <

sumlil|) = mlil|l + m21]Gl:


cout << sum[ilG) << "";

return ,

Que 5.18. What is virtual base class ?


Answer
1. Virtual base classes are used in virtual inheritance in a way of preventing
multiple "instances" of a given class appearing in an inheritance hierarchy
when using multiple inheritances.
2. Following is the Syntax for Virtual Base Classes:
Syntax 1:
class B: virtual public A

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)

cout «< "Hello from A In";

class B: public A

class C: public A

class D: public B, public C

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

Que519, Erplain the term polymorphism with its types.

Answer
Polymorphism: Refer . 1.3, Page 1-3L, Unit-1.
Different types of polymorphism:
1 Compile time polymorphism: This type of polymorphism is achieved

by function overloading o r operator overloading.


5-16 L(CS/AT-Sem-5) Objects and Classes

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:

i It occurs when a derived class has a definition for one of the


member functions of the base class.
i That base function is said to be overridden.

Que 5.20. Write a program to swap to numbers using pointers.

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();

Que 521What is pointer ? How to use pointer.


a
a

Ans
Pointer:
1. Pointers symbolie representation of addresses.
are

2. They enable programs to simulate call-by-reference as well as to create


and manipulate dynamic data struetures.
Object Oriented System Design 6-17L(CS/IT-Sem-5)

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

Assigning the address ofavariable to a pointer using unary operator (&)


which returns the address of that variable.
3. Accessing the value stored in the address using unary operator (")
which returns the value of the variable located at the address specified
by its operand.

Que 5.22. Describe briefly about the term object.

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.

Que 5.23. Explain this pointer' with the help of example.

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++:

It can be used to pass current object as a parameter to another


method.
b. It can be used to refer current class instance variable.

C. It can be used to declare indexers.

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;

Que 5.24. Differentiate between virtual and pure virtual function.

Answer

S.No Virtual function Pure virtual function


A virtual function is a member|A pure virtual function is a
1.
function of base class which can member function of base class
be redefined by derived class. whose only declaration is
provided in base class and should
be defined in derived class
otherwise derived class also
becomes abstract.

Classes having virtual functions Baseclass containing pure virtua


are not abstract. function becomes abstract.
5-19L (CS/IT-Sem-5)
Object Oriented System Design

3. Syntax Syntax:
virtual<func_type> virtual<func_type><unc_name>)
<func_name>()

ll code

Definition is given in base class. No definition is given in base


class.

Base class having virtual Base class having pure virtual


function can be instantiated i.e., | function becomes abstract i.e. it

its object can be made. cannot be instantiated.

does not redefine


6. Ifderived class does not redefine | If derived class
virtual function of base class, virtual function of base class,
then it does not affect| then no compilation error but
derived class also becomes
compilation.
abstract just like the base class.

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.

You might also like