Lab2
Lab2
Program:
#include <iostream>
class Matrix {
private:
int mat[3][3];
public:
Matrix() {
mat[i][j] = 0;
void inputMatrix() {
};
Matrix result;
return result;
int main() {
mat1.inputMatrix();
mat2.inputMatrix();
result.displayMatrix();
return 0;
1. Develop a class Counter that represents a simple integer counter. The class should satisfy the
following requirements:
(a) A he prefix increment and postfix increment operators should be overloaded in order t constructor
should be provided that takes a single int argument that is used to initialize the counter value. The
argument should default to zero.
(c) A member function getValue should be provided that returns the current counter value.
In addition, the class must track how many Counter objects are currently in existence. A means for
querying this count should be provided. The code must not use any global variables. (Hint: Use static
members.)
#include <iostream>
class Counter {
private:
int value;
public:
objectCount++;
objectCount++;
}
~Counter() {
objectCount--;
Counter& operator++() {
++value;
return *this;
Counter operator++(int) {
++value;
return temp;
return value;
return objectCount;
};
int Counter::objectCount = 0;
int main() {
int initialValue;
char choice;
do {
cout << "Enter an initial value for the Counter (default is 0): ";
Counter c(initialValue);
cout << "Initial value of the Counter: " << c.getValue() << endl;
cout << "Value after prefix increment: " << (++c).getValue() << endl;
cout << "Value after postfix increment: " << (c++).getValue() << endl;
cout << "Total Counter objects: " << Counter::getObjectCount() << endl;
cout << "Do you want to create another Counter? (y/n): ";
cout << "Total Counter objects remaining: " << Counter::getObjectCount() << endl;
return 0;