Professional Documents
Culture Documents
LAB MANUAL
3.
To read a value of distance from one object and add with a value in another
object using friend function.
4.
5.
7.
To compute the area of triangle and rectangle using inheritance and virtual
function.
8.
9.
10.
Ex. No : 1
STRING CONCATENATION
AIM:
To implement the string concatenation function by using dynamic memory
allocation concept.
REQUIREMENTS:
Hardware
Pentium IV PC
Software
Turbo C++
ALGORITHM :
1. Create class STRING with two constructors. The first is an empty constructor,
which allows declaring an array of strings. The second constructor initializes the
length of the strings, and allocates necessary space for the string to be stored and
creates the string itself.
2. Create a member function to concatenate two strings.
3. Estimate the combined length of the strings to be joined and allocates memory for
the combined string using new operator and then creates the same using the string
functions strcpy() and strcat().
4. Display the concatenated string.
MODEL OUTPUT:
Object
Oriented
Programming Lab
Object Oriented
Object Oriented Programming Lab
Ex. No: 2
Pentium IV PC
Software
Turbo C++
ALGORITHM :
1.
2.
The second takes one argument which is used to create objects and initialize
them and the third takes two arguments which is also used to create objects
and initialize them to specific values.
3.
4.
5.
MODEL OUTPUT:
Complex No:1 = 1+j2
Complex No:2 = 3+j1
Sum
= 4+j3
Difference = -2+j1
Product
= 1+j5
Quotient
= 0.5-j0.133333
Ex. No : 3
ADDITION OF DISTANCES
AIM:
To read a value of distance from one object and add with a value in another
object using friend function
REQUIREMENTS:
Hardware
Pentium IV PC
Software
Turbo C++
ALGORITHM :
1.
2.
3.
4.
5.
MODEL OUTPUT:
Enter the first distance(in feet):12
Enter the second distance(in inches):30
Total Distance:14.5feet
Ex. No : 4a
OPERATOR OVERLOADING
AIM:
To implement + and operator overloading. and to implement addition
operation of octal object with integer using operator overloading.
REQUIREMENTS:
Hardware
Pentium IV PC
Software
Turbo C++
ALGORITHM :
1.
Create a class called DATE and define two member functions get-data and
display-result.
2.
3.
Overload operators + and to display the number of days between two valid
dates using display-result.
4.
Repeat step 3 to display the date after a number of days from a valid date
using display-result.
MODEL OUTPUT:
dd mm yyyy
7 9 2007
DATE7:9:2007
Enter the no of days after which it should be displayed5
On Increment it becomes12:9:2007
Enter date 1:5 10 2007
Enter date 2:5 11 2007
DIFFERENCE=30
Ex. No : 4b
ADDITION OF OCTAL WITH INTEGER
AIM:
To implement addition operation of octal object with integer using operator
overloading.
REQUIREMENTS:
Hardware
Pentium IV PC
Software
Turbo C++
ALGORITHM :
1.
2.
3.
MODEL OUTPUT:
Enter the Octal No
= 66
= 54
Integer Value = 3
Sum
= 57
Ex. No. : 5
ADDITION AND SUBTRACTION OF TWO POLYNOMIALS
AIM:
To implement addition and subtraction operations of two polynomials and
display using << operator overloading.
REQUIREMENTS:
Hardware
Pentium IV PC
Software
Turbo C++
ALGORITHM :
1.
2.
3.
4.
MODEL OUTPUT:
FIRST POLYNOMINAL: 1x^3+1x^2+1x+1
Enter the co-efficient of cubic polynomial:
x^3
x^2
constant
sum
9x^3+10x^2+9x+7
Difference
17x^3+19x^2+17x+13
Ex. No. : 6
BANK ACCOUNT MAINTENANCE
AIM:
To manage the account information of the customer using inheritance
concept.
REQUIREMENTS:
Hardware
Pentium IV PC
Software
Turbo C++
ALGORITHM :
1.
2.
3.
4.
Write a member function to get the Deposit amount and to update the
balance information for saving account.
5.
MODEL OUTPUT:
Enter customer name: XXX
Enter your A/c no.:666
Enter the A/c type: 1.Savings 2.Current 3.Exit
1
Enter the amount to be deposited=Rs.5000
Enter the amount to be withdrawn=Rs.500
Your A/c Balance is=Rs.4500
Enter the A/c type: 1.Savings 2.Current 3.Exit
2
Last amount withdrawn=Rs.500
Last amount deposited=Rs.5000
Your A/c Balance is=Rs.4500
Enter the A/c type: 1.Savings 2.Current 3.Exit
3
Ex. No. : 7
AREA OF TRIANGLE AND RECTANGLE
AIM:
To calculate the area of triangle and rectangle using derived classes and
display the result using virtual function
REQUIREMENTS:
Hardware
Pentium IV PC
Software
Turbo C++
ALGORITHM :
1.
2.
3.
4.
Find out the area of triangle and rectangle and display the result
using display_area().
5.
MODEL OUTPUT:
For Triangle
Enter the height and base of triangle
=46
Ex. No. : 8
RANDOM NUMBERS
AIM:
To generate random numbers using simple Java program
REQUIREMENTS:
Hardware
Pentium IV PC
Software
JDK1.3
ALGORITHM :
1.
2.
3.
MODEL OUTPUT:
Random Numbers are:
0.7178800297173848
0.10272303466350396
0.09880382903038853
0.20521914937736818
0.4946446248062951
0.7236876729590774
0.06362232446845784
0.3103631103262836
0.986773064331572
0.888041209983093
Ex. No. : 9
AREA OF RECTANGLE AND CIRCLE
AIM:
To calculate area of rectangle and circle using interfaces.
REQUIREMENTS:
Hardware
Pentium IV PC
Software
JDK1.3
ALGORITHM :
1.
2.
Derive two sub classes RECTANGLE and CIRCLE from the base
class SHAPE.
3.
4.
Find out the area of rectangle and circle display the result
using display_area().