Download presentation
Presentation is loading. Please wait.
2
1 Lab Session-3 CSIT221 Fall 2002 b Exception Handling b Lab Exercise (Demo Required)
3
2 Exception Handling b Exceptions are handled by try~catch clauses b Fill in the details to develop a code segment that handles (a) Attempt to divide by zero(a) Attempt to divide by zero (b) Attempt to divide by a negative number(b) Attempt to divide by a negative number (c) Attempt to obtain a result of zero(c) Attempt to obtain a result of zero b Use switch~case to display error as per numeric error code thrown
4
3 Sample Source Code b #include b #include b using namespace std; b void main() b{b{b{b{ b int fruits,kids; b cout<<“how many bananas?”; b cin>>fruits; b cout<<“how many kids?”; b cin>>kids;
5
4 Sample Source Code b try b{b{b{b{ b cout<<“Each kid gets “<<fruits/kids<< “bananas”; b}b}b}b} b Catch (int errorcode) b{b{b{b{ b}b}b}b} b}b}b}b}
6
5 Lab Exercise (Demo Due Sep 17 th Sec 01 and Sep 19 th Sec 02) b Develop an object oriented program to implement a cash register. This cash register stores an inventory of ten items (item numbers 0 through 9). When the item number is given, it can retrieve the invoice price of that item, add 18% profit and show the retail price followed by display of 7% tax and the total price. The program should be able to sell as many items as the user wants. When the program exits, it displays the total amount of sales for the day. The program should be robust and be able to handle any exceptions.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.