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

Lab Exercises-3 Modified

1. Create a class Int that overloads the +, -, *, and / operators to perform integer arithmetic. The operators will check for overflow and terminate the program if the result exceeds the normal integer range. This class could prevent errors from arithmetic overflow. 2. Modify the time class to overload the + operator for adding times. Also add overloaded ++ and -- operators and return values. Test the new operators. 3. Create a class MAT to represent a 2D matrix. Define all arithmetic operators for MAT objects. 4. Create a class distance with kilometers and meters members. Overload the + and - operators to add and subtract distances without allowing negative results. 5. Create a class to

Uploaded by

Ali Azgar
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)
201 views1 page

Lab Exercises-3 Modified

1. Create a class Int that overloads the +, -, *, and / operators to perform integer arithmetic. The operators will check for overflow and terminate the program if the result exceeds the normal integer range. This class could prevent errors from arithmetic overflow. 2. Modify the time class to overload the + operator for adding times. Also add overloaded ++ and -- operators and return values. Test the new operators. 3. Create a class MAT to represent a 2D matrix. Define all arithmetic operators for MAT objects. 4. Create a class distance with kilometers and meters members. Overload the + and - operators to add and subtract distances without allowing negative results. 5. Create a class to

Uploaded by

Ali Azgar
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
You are on page 1/ 1

Lab-3 Exercises

1. Create a class Int based on Exercise 1 in previous lab exercises. Overload four integer
arithmetic operators (+, -, *, and /) so that they operate on objects of type Int. If the
result of any such arithmetic operation exceeds the normal range of ints (in a 32-bit
environment)from 2,147,483,648 to 2,147,483,647have the operator, print a
warning and terminate the program. Such a data type might be useful where mistakes
caused by arithmetic overflow are unacceptable. Hint: To facilitate checking for
overflow, perform the calculations using type long double. Write a program to test
this class.
2. Modify the time class from Exercise 3 in previous lab exercises so that instead of a
function, it uses the overloaded + operator to add two times. Augment this class to
include overloaded increment (++) and decrement (--) operators and return values.
Add statements to main() to test these operators.
3. Create a class MAT of size m x n. Define all arithmetic operations for MAT type objects.
4. Write a class distance with two member variables representing kilometres and
meters. Add overloaded + and - operators that add and subtract two distances.
Assume that the operator will never be used to subtract a larger number from a
smaller one (that is, negative distances are not allowed).
5. Create a class which keeps track of number of its instances. Use static data member,
constructors and destructors to main updated information about active objects.

You might also like