OOP Lab Assgn 9
OOP Lab Assgn 9
OOP Lab Assgn 9
#include <iostream>
using namespace std;
#define N 5
int main()
{
int int_array[N];
float float_array[N];
cout << "Enter integer array elements:" << endl;
for (int i = 0; i < N; i++)
{
cin >> int_array[i];
}
cout << "Enter floating array elements:" << endl;
for (int i = 0; i < N; i++)
{
cin >> float_array[i];
}
sort(int_array, N);
sort(float_array, N);
cout<<"Sorted integer array:"<<endl;
for (int i = 0; i < N; i++)
{
cout << int_array[i] << ", ";
}
cout << endl;
Q2)
#include<iostream>
using namespace std;
int main()
{
int a=20;
char b='B';
display(a,b);
return 0;
}
Q3)
#include <iostream>
using namespace std;
const int N = 5;
int main(){
Array <int> i_obj;
Array <float> f_obj;
i_obj.sortArr();
f_obj.sortArr();
return 0;
}
Q4)
#include<iostream>
using namespace std;
int main()
{
Test <float, int> test1 (1.23, 123);
Test <int, char> test2 (100, 'W');
test1.show();
test2.show();
return 0;
}
Q5)
#include <iostream>
#include <stdexcept>
int main()
{
float numerator, denominator, result;
numerator = 12.5;
denominator = 0;
try {
result = Division(numerator, denominator);
catch (runtime_error& e) {
cout << "Exception occurred" << endl << e.what();
}
return 0;
}
Q6)
#include <iostream>
using namespace std;
class Arr
{
int *a, size;
public:
Arr(int n)
{
size = n;
a = new int[size];
cout << "Array size = " << size << endl;
}
void input()
{
cout << "Input for Array " << endl;
int i = 1, j = 0;
while (1)
{
try
{
cout << "Enter value, -1 to end :";
cin >> i;
if (i == -1)
break;
else if (j >= size)
throw -1;
else
a[j++] = i;
}
catch (int x)
{
cout << "Exception Caught (ARRAY SIZE FULL) " << x << endl;
break;
}
}
}
};
int main()
{
Arr obj(6);
obj.input();
return 0;
}
Q7)
#include<iostream>
#include<conio.h>
void test(int x) {
try {
if (x > 0)
throw x;
else
throw 'x';
} catch (int x) {
cout << "Catch a integer and that integer is:" << x<<endl;
}
catch (char x) {
cout << "Catch a character and that character is; " << x<<endl;
}
}
int main()
{
cout << "Testing multiple catches\n:";
test(10);
test(0);
return 0;
}