0% found this document useful (0 votes)
39 views

Name: Hamza Javed Roll No. 1524

The document contains C++ code that defines a class called hamza. The hamza class contains a method called Error() that gets user input for two values a and b, calculates a-b and stores it in variable x. It then checks if x is 0, and if not divides a by x and prints the result. If x is 0, it throws an exception that is caught and prints "Division by zero". The main function creates an object of hamza and calls its Error() method.

Uploaded by

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

Name: Hamza Javed Roll No. 1524

The document contains C++ code that defines a class called hamza. The hamza class contains a method called Error() that gets user input for two values a and b, calculates a-b and stores it in variable x. It then checks if x is 0, and if not divides a by x and prints the result. If x is 0, it throws an exception that is caught and prints "Division by zero". The main function creates an object of hamza and calls its Error() method.

Uploaded by

Genghis Khan 69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Hamza Javed

Roll No. 1524


#include<iostream>
using namespace std;
int main()
{
cout<<"welcome";
try
{
throw 10;
cout<<"\n In try";
}
catch( int e)
{
cout<<"\n Expression No:"<<e;
}
cout<<"\n Last line";
return 0;
}
#include<iostream>
using namespace std;
class hamza
{
public:
Error(){
int a, b;
cout<<"\n\t Enter two values a and b";
cin>>a>>b;
int x=a/(a-b);
cout<<"\n\t x="<<x;

}
};
continued

int main()
{
hamza obj;
obj.Error();

return 0;
}
#include<iostream>
using namespace std;
class hamza
{
public:
int a;
int b;
int x;
Error()
{
cout<<"\n\t Enter two values a and b";
cin>>a>>b;
x=a-b;
try
{
if(x!=0)
{
cout<<"\n\t Result:"<<a/(a-b);
}
 else
 {
 throw(x);
 }
 }
 catch(int e)
 {
 cout<<"\n\t Division by zero";
 }

 }

 };

 int main()
 {
 hamza obj;
 obj.Error();

 return 0;
 }

You might also like