0% found this document useful (0 votes)
5 views1 page

Object Passing Program

The document outlines specifications for five classes in a programming assignment: Rectangle, Time, ArraySum, matrix, and Money. Each class includes instance variables, member functions, and a main method for object creation and demonstration of functionality. The assignment emphasizes object-oriented programming principles such as encapsulation and method implementation for various operations like area comparison, time addition, array summation, matrix transposition, and money addition.

Uploaded by

amarjitkaurv1t
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Object Passing Program

The document outlines specifications for five classes in a programming assignment: Rectangle, Time, ArraySum, matrix, and Money. Each class includes instance variables, member functions, and a main method for object creation and demonstration of functionality. The assignment emphasizes object-oriented programming principles such as encapsulation and method implementation for various operations like area comparison, time addition, array summation, matrix transposition, and money addition.

Uploaded by

amarjitkaurv1t
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Home work :

1) Define a class Rectangle with the following specifications:


 Instance Variables:
o double length – to store the length of the rectangle
o double breadth – to store the breadth of the rectangle
 Member Functions:
o A parameterized constructor Rectangle(double l, double b) to initialize the data members
o double calculateArea() – to calculate and return the area of the rectangle
o void compareArea(Rectangle r) – to compare the area of the current object with another Rectangle object
passed as an argument and display which rectangle has the greater area
Write a main() method to create two objects and demonstrate comparison using object passing.

2) Define a class Time with the following specifications:


 Instance Variables:
o int hours – to store hours
o int minutes – to store minutes
 Member Functions:
o A parameterized constructor Time(int h, int m) to initialize time
o void addTime(Time t) – to add the time of the current object with another Time object passed as
argument and display the resultant time in proper format (convert excess minutes into hours)
Write a main() method to create two objects and demonstrate addition using object passing.

3) Define a class ArraySum with the following specifications:


 Instance Variable:
o int arr[] – to store elements of the array
 Member Functions:
o A parameterized constructor ArraySum(int a[]) to initialize the array
o int calculateSum() – to calculate and return the sum of array elements
o void compareSum(ArraySum obj) – to compare the sum of the current object with another ArraySum
object passed as argument and display the result
Write a main() method to create two objects and demonstrate object passing.

4) The transpose of a matrix is found by interchanging the elements of rows and columns.
Design a class matrix that contains a 2D array of order [n * n ]. The maximum value possible for n is 20. The details of
some of the members of the class are given below
Class name : matrix
Data members:
int t[][] : to store the matrix
int n : integer to store the number of rows and columns
Member functions:
matrix(…..) : parameterized constructor to initialize n and to allocate memory to member array
void fnGet() : to fill the member array
void fnDisplay() : to show the member matrix
matrix fnTrans(matrix A) : to store the transpose of the argument matrix in the current object and return that.
Specify the class matrix giving the details of the above member data and methods only.

5) Money is an unit that has 2 parts, Rupees and Paise, where 100 Paise=1 Rupee.
Design a class named Money whose details are as follows:
Class Name : Money
Data member:
int rs, ps : integer to store the value of Rupees and paise.
Member methods:
Money(…..) : parameterized constructor to initialize member data
void fnShow() : to show the member data as Money [Rs 819.75]
Money fnAdd(Money m1, Money m2) :
Add m1 and m2. Store the result in corresponding member data and return it.
Specify the class Money, giving the details of the above member data and methods. Also write the main() to create
objects and call the other methods accordingly to enable the task of the adding 2 units on Money.

You might also like