Object-1 (student)
Ø
Classes:
A class is a group of objects having similar characteristics. Once a class is
defined, any
number of objects of that class are created
Ex 1: man and woman
belongs to the same class called Human Being.
Ex 2: planets, sun, moon are members of class solar system.
|
Ø
Data
abstraction: Abstraction is a process of representing essential
features without including background details or explanations.
Ø
Data
encapsulation: data encapsulation combines both data and functions in a
single unit called class. Data encapsulation prevents data from direct access.
The data can be accesses only through functions present inside the class definition.
Data encapsulation enables data hiding or information hiding.
Object
Ø
Inheritance:
The concept of inheritance provides the use of reusability. This means that we
can
add additional features to the existing class without modifying it. Thus
the process of acquiring
properties of one class to another is called
inheritance. The existing class is known as base class
and the new class
obtained is called derived class.
The derived class shares some of the properties of the base
class. Therefore a code from a base
class can be reused by a derived class.
Ø
Overloading:
There are two types of overloading:
a) Operator
overloading: when existing operator operates on new data type is called
operator
overloading
b) Function overloading: Two or more functions
have same name but different number of arguments or data type of arguments.
Function overloading is a process of defining same function name to carry
similar types of activities with various data items.
Ø
Polymorphism:
it is a process where a function can take multiple forms based on the type
of arguments, number of arguments and data type of return value.
The ability of an operator and function to take multiple
forms is known as polymorphism.
Ex: int addition(int
a, int b);
int addition( float a, float b);
Consider the addition
operation. In addition of two numbers the result is the sum of two numbers.
In addition of two
strings the operation is string concatenation. When an operator behaves
differently based on operands, then it is said that operator is overloaded.
Similarly when same function is used for multiple tasks in the same program by
changing argument type and number, it is known as function overloading.
Ø
Dynamic
binding: binding is a process of connecting one program to another.
Dynamic binding is
a process of connecting one program to another during
execution (when function is called).
Ø
Message
passing: a message for an object is request for execution of procedure.
Message passing
involves specifying the name of object, the name of the function
and the information to be sent.
2. What are the advantages of OOP over earlier
programming methods
Ans: Following are the advantages of
OOP over earlier programming methods
- Using class and objects, programs are modularized
- Linking code and object allows related objects to share
common code. This reduces code
duplication and code reusability
- As the data is encapsulated along with functions, the
non-member functions cannot access or
modify data. Thus, providing data
security
- Complexity of the program development is reduced
through the use of inheritance
- Reduces time, as creation and implementation of OOP
code is easy
- Through message passing OOP communicates to the outside
system.
3. What are the application of OOP.
Ans: Applications of OOP are as follows
- Computer graphic applications
- CAD/CAM software
- Object oriented database
- User interface design such as windows
- Real-time systems
- Simulation and modeling
- Artificial intelligence and expert systems
4. Explain class definition and class
declaration with syntax and example
Ans: A class definition is a process of
naming a class, data and functions of the class
A class declaration specifies,
representing objects and functions that operate on objects. The definition and declaration
of a class includes the following
- The data members of the class describes the
characteristics of the class
- The function members are the set of operations that are
performed on the objects of the class.
- The access control specifiers (private, protected and
public) to the class members within a
program are specified
- Class name is used for external operations for
accessing and manipulating the instance of a class
Syntax of a class:
class class_name
{
private: data member;
function member;
protected: data member;
function member;
public: data member;
function member;
};
Example:
class student
{
private:
int rollno;
char name[15];
float percentage;
public:
void getdata();
void
putdata();
};
5. Write a program to demonstrate the use of
class and object
Ans:
#include<iostream.h>
#include<conio.h>
class demo
{
private: int a,b;
public: void getdata();
{
cout<<”Enter
the value of A: ”;
cin>>a;
cout<<”Enter
the value of B: ”;
cin>>b;
}
void
putdata()
{
cout<<”Addition
of two numbers=”<<a+b;
}
};
void main()
{
demo d;
d.getdata();
d.putdata();
getch();
}
6. Explain how to write member functions
written inside and outside the class definition
Ans: To define member function inside a
class the function declaration within the class is replaced by actual function
definition inside the class. Only small functions are defined inside class
definition
Ex:
class room
{
int length;
int breadth;
public: void getdata()
{
cin>>length;
cin>>breadth;
}
void putdata()
{
cout<<length;
cout<<breadth;
}
};
To define member
functions written outside the class definition replaced by actual function
definition outside the class.
Ex:
class room
{
int length;
int breadth;
public: void getdata();
void putdata();
};
void room::getdata()
{
cin>>length;
cin>>breadth;
}
void
room::putdata()
{
cout<<length;
cout<<breadth;
}
The symbol :: is known as scope resolution operator. The scope
resolution operator identifies the function as a member of particular class.
The use of scope resolution operator implies that these member functions are
defined outside the class.
7. Explain how objects of a class can be
defined?
Ans: when a class is defined, it
specifies that the user defined data type is defined. The objects of a class
are declared in the same manner like any other variable declaration
Syntax:
class class_name
{
private members;
public
members;
};
class_name
object1, object2…;
Ex:
class num
{
private:
int x;
int y;
public:
int sum(int a, int b);
int
diff(int a, int b);
};
void main()
{
num n1,n2;
n1.sum(10,5);
n2.diff(10,5);
}
Note that an object is an instance of a class template.
8. Explain how an array of objects can be
defined?
Ans: An array having class type
elements is known as array of objects. An array of objects is declared after
class definition and is defined in the same way as any other array
Ex:
class employee
{
char name[15];
int age;
float salary;
public:
void getdata()
{
cout<<”Enter the name of
employee: ”;
cin>>name;
cout<<”Enter the age of
an employee: ”;
cin>>age;
cout<<”Enter the salary:
”;
cin>>salary;
}
void putdata()
{
cout<<”Name:
”<<name;
cout<<”Age:
”<<age;
cout<<”Salary:
”<<salary;
}
};
void main()
{
employee emp[3];
for(int
i=0;i<3;i++)
{
emp.getdata();
emp.putdata();
getch();
}
9. Describe the need for function overloading
Ans: function overloading means two or
more functions have same name, but differ in the number of arguments or data
type of arguments. Therefore, it is said that function name is overloaded. The
advantages of overloaded functions are:
- When functions are overloaded, then the compiler
automatically decides and executes appropriate function based on type of
arguments and calls the required function. Thus the code is executed faster.
- It is easier to understand the flow of information and
debug.
- Code maintenance is easy.
- Easier interface between programs and real world
objects.
10. Explain overloaded functions with syntax
and example
Ans: function overloading means two or
more functions have same name, but differ in the number of arguments or data
type of arguments. Therefore, it is said that function name is overloaded.
Syntax:
return_type1
function_name(argument list)
{
statement(s);
}
return_type2 function_name(argument
list)
{
statement(s);
}
…
return_typen
function_name(argument list)
{
Statement(s);
}
Ex:
int sum(int a,
int b)
{
return(a+b);
}
float sum(float a, float b)
{
return(a+b);
}
11. Explain inline function with syntax and
example
Ans: In inline function compiler
replaces a function call along with the body of the function. Inline function
run little faster than normal functions as function calling overheads are
saved. Advantages of inline function are as follows:
- They are compact function calls
- The size of the object code is reduced
- Very efficient code can be generated
- The readability of the program increases
Syntax:
inline
retrun_type function_name(argument list)
{
statement(s);
}
Ex:
#include<iostream.h>
#include<conio.h>
inline int square(int a)
{
return(a*a);
}
void main()
{
int x;
x=square (5);
cout<<”Square of 5=”<<x;
getch();
}
12. Explain friend function and their
characteristics. Or explain friend function with syntax
and programming
example.
Ans: A friend function is a non member
function that is a friend of a class. The friend function is declared within a
class with the prefix friend. But it should be defined outside the class like a
normal function without the prefix friend.
Syntax:
class class_name
{
public: friend void
function(void);
};
Characteristics of a friend
function are as follows:
- A friend function has full access right to the private
and protected members of the class.
- A friend function cannot be called using the object of
that class. It can be invoked like any normal function.
- A friend function can be declared anywhere in the class
and it is not affected by access specifiers (private, protected and public).
- They are normal external functions given special access
privileges.
- The function is declared with keyword friend. But while
defining friend function it does not use either friend or :: operator.
#include<iostream.h>
#include<conio.h>
class myclass
{
int a,b;
public: void set_val(int i, int j );
friend
int add(myclass obj);
};
void myclass::set_val(int i, int j)
{
a=i;
b=j;
}
int add(myclass obj)
{
return(obj.a+obj.b);
}
void main()
{
myclass object;
object.set_val(10,20);
cout<<”sum =”<<add(object);
getch();
}
13. What are the rules for writing a
constructor function?
Ans: Rules for writing a constructor
function are as follows
- A constructor name is always same as that of the class
name.
- There is no return type for the constructors not even
void.
- A constructor should be declared in public section.
- A constructor is invoked automatically when objects are
created.
- It is not possible to refer to the address of
constructors.
- The constructors make implicit calls to the operators
new and delete when memory allocation is
required.
14. Explain default constructor with syntax and
example
Ans: A constructor which does not
accept any arguments is called default constructor. Default constructor simply
allocated memory to data members of objects. Features of default constructors
are
- Default constructor automatically invokes when object
is created.
- All objects of the class are to be initialized to same
set of values by the default constructor.
- If different objects are to be initialized with
different values, it cannot be done using default
constructor.
Syntax:
class_name calss_name()
{
}
Ex:
#include<iostream.h>
#include<conio.h>
class c
{
int a,b;
public:
c()
{
a=10;
b=20;
}
void
display()
{
cout<<a<<b;
}
};
void main()
{
c obj;
obj.display();
getch();
}
15. Explain parameterized constructor with
syntax and example
Ans: A constructor that takes one or
more arguments is called parameterized constructor. Using this constructor it
is possible to initialize different objects with different values. The
parameters are used to initialize the object.
Features of
parameterized constructor are as follows:
- The parameterize constructor can be overloaded.
- For object created with one argument, constructor with
only one argument is invoked and
executed.
- The parameterized constructor can have default
arguments and default values.
Syntax:
class_name class_name(
argument list)
{
statement(s);
}
Ex:
#include<iostream.h>
#include<conio.h>
class num
{
int a,b;
public: num(int m,int n)
{
a=m;
b=n;
}
void display()
{
cout<<”A=”<<a<<”B=”<<b
}
};
void main()
{
num n;
n.num(10,20);
n.display();
getch();
}
16. Explain destructors with syntax and example.
Ans: A destructor is a special member
function that will be executed automatically when an object is destroyed. It
will have, like constructor, the same name as that of the class but preceded by
a tilde (~). A destructor will be called
automatically when an object is destroyed. Destroying an object means
de-allocating all the resources such as memory that was allocated for the
object by the constructor.
Syntax:
class class_name
{
private: data_variables;
public: class_name() //constructor
~class_name() //destructor
};
Ex:
#include<iostream.h>
#include<conio.h>
class num
{
int x;
public:
num();
void display();
~num();
};
num::num()
{
cout<<”In
constructor:\n”;
x=100;
}
num::~num()
{
cout<<”In
desctructor:\n”;
}
void num::display()
{
cout<<”Value
of x=”<<x;
}
void main()
{
num n;
n.display();
getch();
}
17. What are the advantages of inheritance?
Ans: inheritance has the following
advantages
- Reusing existing code.
- Faster development time.
- Easy to maintain.
- Easy to extend.
- Memory utilization.
18. Explain types of inheritance.
Ans: following are the types of
inheritance
- Single
inheritance: if a class is derived from a single base class, it is called
as single inheritance.
- Multilevel
inheritance: the classes can also be derived from the classes that are
already derived. This type of inheritance is called multilevel inheritance.
- Multiple
inheritance: if a class is derived from more than one base class, it is
known as multiple inheritance.
- Hierarchical inheritance: if a number of classes are derived from a single
base class, it is called as hierarchical inheritance.
-
Hybrid inheritance: it is a combination of Hierarchical and
Multiple inheritance.
19. What is virtual base class? give example
Ans: consider a situation where the
program design would require one base class call it A and two
derived classes
namely B and C, which are inherited from the base class A. further, derived
class D is
created from B and C.
When two or more
objects are derived from a common base class, we can prevent multiple copies of
the base class being present in an object derived from those objects by
declaring the base class as
virtual when it is being inherited. Such a base
class is known as virtual base class. This can be
achieved by preceding the
base class name with the word virtual
Ex:
class A
{
__________
__________
};
class B: virtual
public A
{
____________
____________
};
class C: virtual
public A
{
____________
____________
};
class D: public B,
public C
{
____________
____________
};
20. Write a program to demonstrate the use of single
inheritance
Ans:
#include<iostream.h>
#include<conio.h>
class abc
{
int rollno;
char name[15];
public: void read()
{
cout<<”Enter
the roll number: ”;
cin>>rollno;
}
void display()
{
cout<<”Roll
no:”<<rollno;
cout<<”Name:”<<name;
}
};
class
xyz:public abc
{
int
m1;
int
m2;
int
t;
public:
void read1()
{
cout<<”Enter the first
marks:”;
cin>>m1;
cout<<”Enter the second
marks:”;
cin>>m2;
t=m1+m2;
}
void display1()
{
cout<<”First marks:
”<<m1;
cout<<”Second
marks:”<<m2;
cout<<”Total marks:”<<t;
}
};
void
main()
{
xyz
ob;
ob.read();
ob.read1();
ob.display();
ob.display1();
getch();
}
21. Explain data processing cycle
Ans: the information processing cycle
consists of five specific steps,
- Input: any
kind of data- letters, numbers, symbols, shapes, images or whatever raw
material put into the computer system that needs processing. Input data is put
into the computer using a keyboard, mouse or other devices such as the scanner,
microphone and the digital camera. In general data must be converted to
computer understandable form.
- Processing: the
processing is a series of actions or operations from the input data to generate
outputs. Some of the operations are classification based on some condition,
calculation, sorting, indexing, accessing data, extracting part of file/attribute,
substring etc. conversion of data into information by the central processing
unit. For example, when the computer adds 4+2=6 that is an act of processing.
- Storage:
data and information not currently being used must be stored so it can be
accessed later. There are two types of storage, primary and secondary storage.
Primary storage is the computer circuitry that temporarily holds data waiting
to be processed (RAM) and it is inside the computer, secondary storage is where
data is held permanently. A floppy disk, hard disk or CD. ROM is example of
this kind of storage.
- Output: the
result or information obtained after processing the data must be presented to
the user in user understandable form. The result may in the form of reports
(hard copy or soft copy). Some of the output can be animated with sound and
video/picture.
- Communication:
With wired and wireless communication connections, data may be input from a far
, processed in a remote area and stored in several different places and then be
transmitted by modem as an e-mail or posted to the website where the online
services are rendered.
22. Explain the features of database system. or
explain the advantages (features) of DBMS.
Ans: in the database approach, the data
is stored at a central location and is shared among multiple
users. Thus, the
main advantage of DBMS is centralized data management. The advantages of
centralized database system are as follows:
- Controlled data
redundancy: elimination of duplication of data item in different files
ensures consistency and saves the storage space. The redundancy in the database
cannot be eliminated completely as there could be some performance and
technical reasons for having some amount of redundancy.
- Enforcing data
integrity: data integrity refers to the validity of data and it can be
compromised in a number of ways.
- Data sharing:
the data stored in the database can be shared among multiple users or
application programs. It is possible to satisfy the data requirements of the
new applications without creating any additional data or with minimal modification
- Ease of
application development: the application programmer needs to develop the
application programs according to user’s needs. The other issues like
concurrent access, security, data integrity etc are handled by the RDBMS itself
- Data security:
since the data is stored centrally data security checks can be carried out
whenever access is attempted to sensitive data. To ensure security, a RDBMS
provides security tools such as used codes and passwords. Different checks can
be established for each type of access like addition, modification, deletion
etc to each piece of information in the database
- Multiple user
interfaces: For various users having different technical knowledge DBMS
provides different types of interfaces such as query languages, application
program interfaces, and graphical user interfaces (GUI)
- Backup and
recovery: RDBMS provides backup and recovery subsystem that is responsible
for recovery from hardware and software failures. For example, if the failure
occurs in between the transaction, the RDBMS recovery subsystem either reverts
back the database to the state to the previous state of the transaction or
resumes the transaction from the point it was interrupted so that its complete
effect can be recorded in the database.
23. Explain DBMS architecture
Ans: it is a three levels of
architecture namely, internal, conceptual and external levels.
Internal level: internal level is the
lowest level of data abstraction that deals with the physical
representation of
the database on the computer and thus, is known as physical level. It describes
how
the data is physically stored and organized on the storage medium. It
includes storage space allocation
techniques for data and indexes, data
compression and encryption techniques, and record placement.
Conceptual level: conceptual level describes
what data is stored in the database, the relationships among the data and
complete view of the user’s requirements without any concern for the physical
implementation. i.e. it hides the complexity of physical storage structures.
External level: this level permits the
user to access data in a way that is customized according to their needs, so
that the same data can be seen by different users in different ways at the same
time. In this way, it provides a powerful and flexible security mechanism by
hiding the parts of the database from certain users, as the user is not aware
of existence of any attributes that are missing from the view.
24. Explain database model.
Ans: A database model defines the
logical design of data. The model describes the
relationships between different
parts of the data. There are three models
- Hierarchical
model: this data model organizes the data in a tree like structure, in
which each child node can have only one parent node. The database based on the
hierarchical data model comprises a set of records connected to one another
through links. The links is an association between two or more records. The top
of tree structure consists of a single node that does not have any parent and
is called the root node. It represents only one-to-one and one-to-many
relationships. In this model each entity has only one parent but can have
several children. At the top of hierarchy there is only one entity which is
called root.
- Network model: Unlike hierarchical data model, all the nodes
are linked to each other without any hierarchy. The main difference is that in
hierarchical data model, the data is organized in the form of trees and in
network data model, the data is organized in the form of graph, in which some
entities can be accessed through several level path
- Relational
model: the relational model was developed by E.F.Codd in 1970. In
relational model there are no physical links. All data is maintained in the
form of tables (generally known as relations) consisting of rows and columns.
Each row or record represents an entity and a column or field represents an
attribute of the entity. Oracle, Sybase, DB2, Ingress, Informix, MS-SQL server
are the examples of DBMSs
In
this model, data is organized in two-dimensional tables called relations. The
tables or relations are related to each other
Relational model of database
25. Explain SQL constraints with example.
Ans: Constraints are the
rules enforced on data columns on table. These are used to limit the
type of
data that can go into a table. Following are the constraints available in SQL:
- Primary key: this
constraints defines a column or combination of columns which uniquely identifies
each row in the table
Ex: create table
student(rollno number(2) PRIMARY KEY, name varchar(15));
- Foreign key: this
constraints identifies any column referring the PRIMARY KEY in another table.
It establishes a relationship between two columns in the same table or between
different tables.
Ex: SQL>
create table grade(rollno number(2), grade char(1), foreign key(rollno)
references student(rollno));
- Not null
constraint: this constraints ensures all rows in the table contain a
definite value for the column which is specified as not null. Which means a
null value is not allowed
Ex: create table
student(rollno number(2) NOT NULL, name varchar(15));
- Unique key: this
constraint ensures that a column or a group of columns in each row have a
distinct value. A column(s) can have a null value but the values cannot be
duplicated
Ex: create table
student(rollno number(2) PRIMARY KEY, name varchar(15) UNIQUE);
- Check
constraint: The CHECK constraint is used to limit the value range that can
be placed in a column.
Ex: create table
student(rollno number(2), marks number(3) check(marks>=0 and marks<=100));
26. Explain with example to create details of
employees and give the minimum and
maximum in the salary domain.
Ans: SQL> create table employee(empid
number(3), ename varchar(20), salary number(8,2));
Table created.
SQL> insert into
employee values(&empid,'&ename',&salary);
Enter value for
empid: 1
Enter value for
ename: ganesh
Enter value for
salary: 12000
old 1: insert into employee
values(&empid,'&ename',&salary)
new 1: insert into employee
values(1,'ganesh',12000)
1 row created.
SQL> /
Enter value for
empid: 2
Enter value for
ename: raju
Enter value for
salary: 10000
old 1: insert into employee
values(&empid,'&ename',&salary)
new 1: insert into employee values(2,'raju',10000)
1 row created.
SQL> select *
from employee;
EMPID ENAME SALARY
----------
-------------------- ----------
1 ganesh 12000
2 raju 10000
SQL> select
max(salary) from employee;
MAX(SALARY)
-----------
12000
SQL> select
min(salary) from employee;
MIN(SALARY)
-----------
10000
27. Explain OSI reference model
- The physical
layer: it is concern with transmitting raw bits over a communication
channel. It also deals with mechanical, electrical and timing interfaces
- The data link
layer: it transform a raw transmission into a line that forms frame
- The network
layer: it determines how packets are routed from source to destination
- The transport
layer: it splits up packets into smaller units if needed, and pass these to
the network layer and ensure that the pieces all arrive
correctly at the other end
- The session
layer: it allows users on different machines to establish sessions between
them. It includes dialog control, token management and synchronization
- The presentation
layer: it is concerned with the syntax and semantics of the information
transmitted
- The application
layer: it contains a variety of protocols that are commonly needed by the
user. For example, HTTP (HyperText Transfer Protocol) which is the bases for
the World Wide Web (WWW) to access web pages
28. What is topology? Explain in detail OR
explain the types of topologies.
Ans: The layout of networking is called
as Topology.
- Bus topology or
linear topology: this consists of a single length of the transmission
medium onto which the various nodes are attached. The transmission from any
station travels the length of the bus, in both directions, and can be received
by all other stations. The bus has terminators at either end which absorb the
signal, removing it from the bus.
Ring topology or circular topology: In this topology each node is connected to two
and only two neighboring nodes and is transmitted to another. Thus data travels
in one direction only, from node to node around the ring. After passing through
each node, it returns to the sending node, which removes it.
- Star topology: this
topology consists of a central node to which all other nodes are connected by a
single path.
In star topology,
every node (computer workstation or any other peripheral) is connected to a
central node called a hub or switch. The switch is the server and the
peripherals are the clients.
No comments: