**Note: Other Websites/Blogs Owners Please do not Copy (or) Republish this Materials, Students & Graduates if You Find the Same Materials with EasyEngineering.net Watermarks or Logo, Kindly report us to [email protected]
Visit : www.EasyEngineering.net
CS6461 OBJECT ORIENTED PROGRAMMING LAB
LAB MANUAL
For more Visit : www.EasyEngineering.net
Regulation
: 2013
Branch
: B.E. – EEE
Year & Semester
: II Year / IV Semester
ww
w.E
asy
CS6461 - OBJECT ORIENTED PROGRAMMING LAB
En
gin
eer
ing
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
.ne t
1
CS6461 OBJECT ORIENTED PROGRAMMING LAB
ANNA UNIVERSITY: CHENNAI REGULATION - 2013 CS6461 OBJECT ORIENTED PROGRAMMING LABORATORY
LIST OF EXPERIMENTS: C++ PROGRAMS: 1. Program using functions . Functions with default arguments . Implementation of call by value, address, reference
ww
2. Simple classes for understanding objects, member functions & constructors
w.E
. Classes with primitive data members, . Classes with arrays as data members
asy
. Classes with pointers as data members
En
. Classes with constant data members
. Classes with static member functions 3. Compile time polymorphism . Operator overloading . Function overloading 4. Run time polymorphism
gin
eer
ing
. Inheritance . Virtual functions
.ne t
. Virtual base classes . Templates 5. File handling . Sequential access . Random access
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
2
CS6461 OBJECT ORIENTED PROGRAMMING LAB
JAVA PROGRAMS: 6. Simple java applications . For understanding references to an instant of a class . Handling strings in JAVA 7. Simple package creation . Developing user defined packages in java 8. Interfaces . Developing user defined interfaces . Use predefined interfaces
ww
9. Threading
w.E
. Creation of threading in java applications . Multi threading
asy
10. Exception handling mechanism in java . .
En
Handling predefined exceptions
Handling user defined exceptions
gin
eer
TOTAL PERIODS: 45
ing
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
.ne t
3
CS6461 OBJECT ORIENTED PROGRAMMING LAB
INDEX S.NO
DATE
SIGNATURE OF THE STAFF
TITLE
REMARKS
C++ PROGRAMS 1
Functions with default arguments
2
Call by value, call by reference and call by address
3
Classes and objects
4
Static member function
ww 5
Operator overloading
6
Function overloading
7 8 9
w.E
Inheritance and Virtual base class
asy
Virtual functions Function template
En
10
File handling: Sequential file access
11
File handling: Random file access
gin
JAVA PROGRAMS 12
Class and object in Java
13
Strings in Java
14
Packages in Java
15
Interfaces in Java
16
Threads in java
17
Multithreading
18
Exception handling
19
User Defined Exception
eer
ing
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
.ne t
4
CS6461 OBJECT ORIENTED PROGRAMMING LAB
INTRODUCTION Basic Concepts of C++ : C++ was developed by Bjarne stroustrup at bell labs. C++ is an intermediate level language, as it comprises of both high level and low level language features. C++ is an Object Oriented Programming language but is not purely Object Oriented. Object Oriented programming is a programming style that is associated with the concept of Class, Objects and various other concepts revolving around these two, like Inheritance, Polymorphism, Abstraction, Encapsulation.
ww
w.E
asy
Basic Built in types
En
char
for character storage ( 1 byte )
int
for integral number ( 2 bytes )
float
gin
single precision floating point ( 4 bytes )
eer
ing
double double precision floating point numbers ( 8 bytes )
.ne t
Features of C++: 1. Objects 2. Classes 3. Abstraction 4. Encapsulation 5. Inheritance Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
5
CS6461 OBJECT ORIENTED PROGRAMMING LAB
6. Overloading 7. Exception Handling Classes and Objects: A class is a blueprint for any functional entity which defines its properties and its functions. Like Human Being, having body parts, and performing various actions. Objects are instances of class, which holds the data variables declared in class and the member functions work on these class objects. Static Keyword: Static is a keyword in C++ used to give special characteristics to an element. Static
ww
elements are allocated storage only once in a program lifetime in static storage area. And they have a scope till the program lifetime. Functions:
w.E
asy
Functions are used to provide modularity to a program. Creating an application using function makes it easier to understand, edit, check errors Inheritance:
En
gin
Inheritance is the capability of one class to acquire properties and characteristics from
eer
another class. The class whose properties are inherited by other class is called
ing
the Parent or Base or Super class. And, the class which inherits properties of other class is called Child or Derived or Sub class. Inheritance makes the code reusable. When we inherit
.ne t
an existing class, all its methods and fields become available in the new class, hence code is reused. Function Overloading
If any class has multiple functions with same names but different parameters then they are said to be overloaded. Function overloading allows you to use the same name for different functions, to perform, either same or different functions in the same class. Function overloading is usually used to enhance the readability of the program. Operator Overloading: Operator overloading is an important concept in C++. It is a type of polymorphism in which an operator is overloaded to give user defined meaning to it. Overloaded operator is
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
6
CS6461 OBJECT ORIENTED PROGRAMMING LAB
used to perform operation on user-defined data type. For example '+' operator can be overloaded to perform addition on various data types, like for Integer, String(concatenation) etc. Virtual Functions: Virtual Function is a function in base class, which is overrided in the derived class, and which tells the compiler to perform Late Binding on this function. Virtual keyword is used to make a member function of the base class Virtual.
Basic Concepts of JAVA Java was developed by James Ghosling, Patrick Naughton, Mike Sheridan at Sun
ww
Microsystems Inc. in 1991. It took 18 months to develop the first working version.
w.E
The initial name was Oak but it was renamed to Java in 1995 as OAK. Java Features: 1. Simple
A class is declared using class keyword. A class contain both data and code that operate on that data. The data or variables defined within a class are called instance variables and the code that operates on this data is known as methods. Object is an instance of class
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
7
CS6461 OBJECT ORIENTED PROGRAMMING LAB
String: String is the most commonly used class in java library. String class is encapsulated under java.lang package. String objects are immutable that means once a string object is created it cannot be altered. Package: A package can be defined as a group of similar types of classes, interface, enumeration and sub-package. Using package it becomes easier to locate the related classes. Interface: Interface is a pure abstract class. They are syntactically similar to classes, but we cannot create instance of an Interface and their methods are declared without any body.
ww
Interface is used to achieve complete abstraction in Java
w.E
Multithreading:
asy
A program can be divided into a number of small processes. Each small process can be addressed as a single thread (a lightweight process). Multithreaded programs contain two
En
or more threads that can run concurrently. This means that a single program can perform two
gin
or more tasks simultaneously. For example, one thread is writing content on a file at the same time another thread is performing spelling check. Exception Handling:
eer
ing
Exception Handling is the mechanism to handle runtime malfunctions. We need to
.ne t
handle such exceptions to prevent abrupt termination of program. The term exception means exceptional condition, it is a problem that may arise during the execution of program
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
8
CS6461 OBJECT ORIENTED PROGRAMMING LAB
Ex. No : 1 Date
:
FUNCTIONS WITH DEFAULT ARGUMENTS
AIM: To write a C++ program to implement functions with default arguments ALGORITHM: Step 1: Start the program.
ww
Step 2: Declare the simple interest function with default argument.
w.E
Step 3: From main function call the required data. Step 4: Define simple interest function.
asy
Step 5: Calculating simple interest.
En
Step 6: Display the details given. Step 7: Stop the program.
gin
eer
ing
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
.ne t
9
CS6461 OBJECT ORIENTED PROGRAMMING LAB
PROGRAM: (FUNCTIONS WITH DEFAULT ARGUMENTS) #include #include float si(float p=1000.00,int n=2,float =0.02); void main() { clrscr(); float p,r; int n; cout<<"\n Enter principal amount:"; cin>>p;
cout<<"\n simple interest with 3 default arguments="<
gin
cout<<"\n simple interest with 2 default arguments="<
eer
cout<<"\n simple interest with 1 default arguments ="<
ing
cout<<"\n simple interest without default arguments="<
.ne t
return((pr*no*ra)/pr); }
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
10
CS6461 OBJECT ORIENTED PROGRAMMING LAB
INPUT AND OUTPUT:
ww
w.E
asy
En
gin
eer
ing
.ne t
RESULT: Thus the implementation of c ++ program for default argument is executed and the output has been verified.
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
11
CS6461 OBJECT ORIENTED PROGRAMMING LAB
Ex. No: 2 Date:
CALL BY VALUE, CALL BY REFERENCE AND CALL BY ADDRESS AIM: To write a C++ program using call by value, call by reference and call by address. ALGORITHM: Step 1: Start the program
ww
Step 2: Declare and define a function swapval using call by value
w.E
Step 3: Declare and define a function swapref using call by reference Step 4: Declare and define a function swapadr using call by address
asy
Step 5: Pass necessary arguments to these functions Step 6: Display the output Step 7: Stop the program
En
gin
eer
ing
Visit : www.EasyEngineering.net VVIT DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
.ne t
12
CS6461 OBJECT ORIENTED PROGRAMMING LAB
PROGRAM:(CALL BY VALUE, CALL BY REFERENCE AND CALL BY ADDRESS) #include #include void swapval(int,int); void swapref(int &x,int &y); void swapadr(int *,int*); void main()
Just what do you do to start checking out Stand By, Stand By By Chris Ryan ... we have informed recently, simply go to the web link that we provide here.
Kuala Lumpur Lisbon London Madtld f\~exlco City f\~llan Monueal. San Juan Santiago Singapore Sydney Tokyo Toronto. Visit : Civildatas.blogspot.in. Visit : Civildatas.blogspot.in. Civildatas.blogspot.in. Page 3 of 450. Engineering Hydrology by K Subra
meaningful approach by integrating the inquiry statement in a global context - Develops ... and eTextbooks via Dynamic Learning, our complete digital solution.
www.EasyEngineering.net. Page 3 of 220. Main menu. Displaying Basic Environmental Engineering by R.C.Gaur - civilenggforall- By EasyEngineering.net.pdf.
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Main menu.
Engineering Surveying by W.Schofield - BY Civildatas.blogspot.in.pdf. Engineering Surveying by W.Schofield - BY Civildatas.blogspot.in.pdf. Open. Extract.
Dublin Institute of Technology. Ireland. Blackwell. Science. Downloaded From : www.EasyEngineering.net. Downloaded From : www.EasyEngineering.net. www.EasyEngineering.net. Page 3 of 292. Main menu. Displaying HIGHWAY ENGINEERING by Martin Rogers - By
Page 1 of 281. Downloaded From : www.EasyEngineering.net. Downloaded From : www.EasyEngineering.net. www.EasyEngineering.net. Page 1 of 281. Page 2 of 281. IRRIGATION. ENGINEERING. Downloaded From : www.EasyEngineering.net. Downloaded From : www.Easy
Prelims-H8323.qxd 9/22/06 6:35 PM Page xi. Visit : www.Easyengineering.net. Visit : www.Easyengineering.net. Page 3 of 381. Beginning AutoCAD 2007 by Bob McFarlane - By www.EasyEngineering.net.pdf. Beginning AutoCAD 2007 by Bob McFarlane - By www.Eas