Home Work 1
CAP 310: Modern Programming Tools and Techniques -I
Course Instructor : Lect. Balraj Kumar____________ Course Tutor (if applicable) : ____________
Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s work
or from any other source except where due acknowledgment is made explicitly in the text, nor has
any part been written for me by another person.
Evaluator’s comments:
_____________________________________________________________________
Part A
Q:1 Define abstraction, encapsulation, modularity and hierarchy in your own
terms.
Ans
Abstraction
Abstraction is the techinique by virtue of which we can represent the essential features of a
program excluding the details of program. It involves only what the system
performs and excluding the internal details of its functioning (what and how it
happens in the background is hidden)
E.g. consider the case of a train .driver only drive the train without considering what
goes under the body or engine of the train to move. Thus abstraction hides the basic
details in performing a particular function.
Encapsulation: The process of wrapping up variables and methods into a single unit
called class is known as encapsulation it is done to protect the variables and
methods from unauthorised access and misuse.
Hierarchy: The concept of arranging the variables and methods in a program in a top-
down order.
Example of the train. From the outside train is a single object, once inside one can
see various parts arranged together to work in a co-ordinated manner to run the train.
Q:2 Sketch the object-oriented design or the Card game Black-Jack. What are
the key objects? What are the properties and behaviours of these objects?
How does the object interact?
The object-oriented design of the Card game Black-Jack is shown below with class
associated with data and methods.
Class hand:
( hand which holds various cards and cards that it gives and gets and shows cards)
Class player:
Class deck:
(vector cards, shuffledcard, next card to be suffed, next item)
Class card :
int getValue()
string getSuit(),
Void addToHand
Void showHand()
The object-oriented design of the Soda dispensing machine is shown below with class
associated with data and methods.
Class type
( type of Soda dispensing machine various types of cold drinks that it can dispatch)
Class company:
Class flavour
(type of flavour, that is poured and how many flavour are there in a machine )
Class alert
( this is real time class which alerts when container of either water and flavour are empty )
void poursoda()
Void alert()
Part B
Q:4 In an object oriented inheritance hierarchy, the objects at each level are
more specialized than the objects at the higher levels. Give three real
world examples of a hierarchy with this property.
Ans example 1: grand parent is a base class and father inherits some of the
grand parent class and son inherits the features of father class
example 2 vechiles ->car->maruti800
example 4: UGC->LPU->LIM
Ans
System.out.print() System.out.println()
Output
Welcome in home
Output
Welcome in
home
Class arun
{
final double s=2.9979E8;
}
}
Q:6 Write a code segment that defines a Scanner variable stdin that is
associated with System.in. The code segment should than define to int
variables a and b, such that they are initialized with the next two input
values from the standard input stream.
class arun
int x,y,z;
x=stdin.nextInt();
y= stdin.nextInt();
z=x+y;
Variables: stdin, n