C++(OOPs)1
C++(OOPs)1
#include <iostream>
#include <iomanip>
using namespace std;
class matrix
{
int **a,l1,l2;
public:
void initialize_matrix(int m,int n)
{
l1=m;
l2=n;
a = new int*[m];
for(int p=0;p<m;p++)
{
a[p] = new int[n];
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
a[i][j]=0;
}
}
}
void display_matrix()
{
for(int i=0;i<l1;i++)
{
cout<<" ";
for(int j=0;j<l2;j++)
{
cout<<a[i][j]<<setw(5);
}
cout<<"\n";
}
}
void enter_matrix()
{
for(int i=0;i<l1;i++)
{
for(int j=0;j<l2;j++)
{
cin>>a[i][j];
}
}
}
int main()
{
cout<<"\n\n Program for multiplication of two matrices using oop";
cout<<"\n ^^^^^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^ ^^^^^ ^^^";
matrix m1,m2,m3;
int row1,col1,row2,col2;
if(m3.multiply_matrix(m1,m2))
{
cout<<"\n\n Resultant matrix - \n\n";
m3.display_matrix();
}
return 0;
}
Program-2
Aim:- Using the concept of function overloading, write function for
calculating area of triangle, circle and rectangle.
#include<iostream>
using namespace std;
int area(int);
int area(int,int);
float area(float);
float area(float,float);
int main()
{
int s,l,b;
float r,bs,ht;
int area(int s)
{
return(s*s);
}
float area(float r)
{
return(3.14*r*r);
}
#include<iostream>
using namespace std;
class fibonacci
{
long int a,b; //data members
public:
fibonacci() //special member function constructor
{
a=-1;
b=1;
}
};
int main()
{
fibonacci f;
int n;
#include <iostream>
using namespace std;
// Number class
class Number
{
int N;
public:
// Default constructor
Number()
{
N = 0;
}
// Parameterised constructor
Number(int X)
{
N = X;
}
int max(Number A)
{
if (N > A.N)
return N;
else
return A.N;
}
// Destructor
~Number()
{
cout << "Destructor working.\n";
}
};
int main()
{
int a, b;
cout << "Enter two numbers: ";
cin >> a >> b;
return 0;
}