You are on page 1of 1

Bangladesh Army University of Engineering & Technology (BAUET)

Department of Computer Science and Engineering (CSE)


2nd Year 1st Semester Sessional Class, Fall-2023
Course Code: CSE-2106
Course Title: Object Oriented Programming Sessional
Full Marks: 25 Time: 03 Hours

Lab Test No: 02


SL Assigned Tasks
Q1. Design a C++ program that implements a simple counter class with the ability to increment and decrement its
value using operator overloading. Implement a solution with the following specifications:

a) Define a class named Counter with a private attribute value (int) to store the counter value.
b) Implement a default constructor for the Counter class that initializes the counter value to 0.
c) Overload the unary operators ++ (prefix and postfix) and -- (prefix and postfix) to perform increment
and decrement operations on the counter value.
d) Define member functions display() to display the current counter value.
e) Develop a main() function to demonstrate the functionality of the Counter class:
a. Create a Counter object.
b. Increment and decrement the counter using both prefix and postfix operators.
c. Display the counter value after each operation.

Q2. Problem: Division with Exception Handling


Design a C++ program that performs division of two numbers with exception handling. Implement a solution
with the following specifications:
a) Define a function named divide() that takes two integer parameters dividend and divisor and returns
the result of dividing dividend by divisor.
b) Implement exception handling in the divide() function to handle the following scenarios:
If the divisor is zero, throw an exception of type std::invalid_argument with the message "Division
by zero error".
c) Develop a main() function to demonstrate the functionality of the divide() function:
a. Prompt the user to input two integers dividend and divisor.
b. Call the divide() function with the user-input values and handle any exceptions that occur.
c. Display the result of the division if successful, or display the error message if an exception
occurs.

You might also like