Tue Nov 19 2019

Object Array

C++ Programming1078 views

File Name: object-array.cpp

#include<iostream>
using namespace std;

class array {
	int x, y;
	
	public:
		array(int a, int b) {
			x = a;	y = b;
		}

		inline int getX() {
			return x;
		}

		inline int getY() {
			return y;
		}
};


int main() {

	/* Declearation and initialization of two dimentional array objects */
	array a[2][2] = {array(1,2), array(3,4), array(5,6), array(7,8)};
	array b[2][2] = {array(4,4), array(4,4), array(4,4), array(4,4)};
	cout << "After Sum:" << endl;
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 2; j++)
			cout << a[i][j].getX() + b[i][j].getX() << "\t" << a[i][j].getY() + b[i][j].getY() << endl;

	return 0;
}


/* Output */
After Sum:
5 6
7 8
9 10
11 12
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.