Task 1: Define a class Bubble with data member’s static int objCount and 2D inte
ID: 3813019 • Letter: T
Question
Task 1:
Define a class Bubble with data member’s static int objCount and 2D integer array
mat [10] [10] and 2 integer members rows and cols. Define a default constructor
which will increment objCount when an object is created & display it also define a
user defined constructor which is used to set the values of rows and cols for mat
and increment objCount when an object is created & display it & also define a
destructor which will decrement objCount & display it. Define a member function
populate to fill 2D array with the random numbers up to 100 with rows and cols set
by constructor & also display function to show mat in matrix form. Now define a
friend function sort which will sort the 2D array mat in ascending order(Use any
sorting technique like bubble sort).
In the main function create 2 Bubble objects. Populate both of them, then display
them one by one. Then sort these matrices and display again.
NOTE :Implement the following program in C++ Language , thank you !
Explanation / Answer
The c++ implememtation is given below:
#include<iostream>
using namespace std;
class Bubble
{
public:
//variable decleration
static int objCount;
int rows;
int cols;
int mat[10][10];
//default constructor
Bubble()
{
objCount++;
cout<<"The total objects are: "<<objCount<<endl;
}
//parameterised constructor
Bubble(int r, int c)
{
rows = r;
cols = c;
objCount++;
cout<<"The total objects are: "<<objCount<<endl;
}
//destructor
~Bubble()
{
objCount--;
cout<<"The total objects are: "<<objCount<<endl;
}
};
int Bubble::objCount = 0;
int main()
{
Bubble b1;
Bubble b2(10, 10);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.