0% found this document useful (0 votes)
37 views5 pages

Practical 3.1 C++

The document summarizes a student's experiment on exception handling in C++. It includes two programs, one that handles a divide by zero exception and another that tests exception restrictions. The student learned about object-oriented programming concepts like decomposition, module design, and program analysis and evaluation. The student's work was evaluated on a worksheet, quiz, and engagement during the lab for a total of 20 marks.

Uploaded by

Vinay Gupta
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)
37 views5 pages

Practical 3.1 C++

The document summarizes a student's experiment on exception handling in C++. It includes two programs, one that handles a divide by zero exception and another that tests exception restrictions. The student learned about object-oriented programming concepts like decomposition, module design, and program analysis and evaluation. The student's work was evaluated on a worksheet, quiz, and engagement during the lab for a total of 20 marks.

Uploaded by

Vinay Gupta
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/ 5

University Institute of Engineering Department

of Mechatronics

Experiment: 3.1

Student Name: Vinay Kumar Gupta UID:21BEM1014

Branch: Mechatronics Engineering Section/Group: B


Semester: 2 Date of Performance:26/04/2022
Subject Name: OBJECT ORIENTED PROGRAMMING USING C++
Subject Code: 21CSH-103

Aim of the practical: LEARN HOW TO USE EXCEPTION HANDLING C ++

List of Sub Programs:

PREREQUISITES- KNOWLEDGE OF EXCEPTION HANDLING KEYWORDS

LIST OF SUB-PROGRAMS-

Practical 8.1: WAP to perform exception handling for Divide by zero Exception.

Solution:

#include <iostream>

using namespace std;

double division(int a, int b) {

if( b == 0 ) {

throw "Division by zero condition!";


University Institute of Engineering Department
of Mechatronics

return (a/b);

int main () {

int x = 50;

int y = 0;

double z = 0;

try {

z = division(x, y);

cout<< z <<endl;

} catch (const char* msg) {

cerr<< msg <<endl; }

return 0;

Output:
University Institute of Engineering Department
of Mechatronics

Practical 8.2:WAP to implement the exception handling with the functionality of testing the throw
restrictions.

Solution:

#include <iostream>

#include <conio.h>

using namespace std;

void handle(int test)

try {

if (test==0)

throw test; // throw int

if (test==1)

throw 'a'; // throw char

if (test==2)

throw 123.23; // throw double

catch(int i) { // catch an int exception

cout<< "Caught " << i << "\n"; }

catch(...) { // catch all other exceptions

cout<< "Caught one!\n"; }


University Institute of Engineering Department
of Mechatronics

int main( ) {

cout<< "start\n";

handle(0);

handle(1);

handle(2);

cout<< "end";

return 0;

Output:
University Institute of Engineering Department
of Mechatronics

Learning outcomes (What I have learnt):

• Understand the concepts of object-oriented programming including programming process and


compilation process.

• Apply different techniques to decompose a problem and programmed a solution with its sub modules.

• Analyze and explain the behavior of simple programs involving the programming addressed in the
course.

• Implement and evaluate the programs using the syntax and semantics of objectoriented programming.

• Design the solution of real-world problems in order to determine that the program performs as
expected.

Evaluation Grid (To be filled by Faculty):


Sr. No. Parameters Marks Obtained Maximum Marks
1. Worksheet completion including 10
writinglearning
objectives/Outcomes.(To besubmitted
at the end of the day)
2. Post Lab Quiz Result. 5
3. Student Engagement in 5
Simulation/Demonstration/Performance
and Controls/Pre-Lab Questions.
Signature of Faculty (with Date): Total Marks Obtained: 20

You might also like